From 471e0494476afcdc427ba1e6746e8e0b94b08953 Mon Sep 17 00:00:00 2001 From: Marcelo Altmann Date: Thu, 28 Nov 2024 22:22:53 -0300 Subject: [PATCH] Force cache creation to set default schema Force connection to set the default schema before attempting to create a cache. We use one single connection per host. During cache creation dry-run we enforce the default schema to be set, but During actual cache creation we do not. In case a client has more than one Readyset server, we will not execute the dry-run on the second server onwards. This will cause the cache creation to fail as the default schema is not set. This commit forces the default schema to be set before attempting to create a cache. Fixes: #31 --- src/hosts.rs | 1 + src/queries.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hosts.rs b/src/hosts.rs index 12ed77a..5874f5f 100644 --- a/src/hosts.rs +++ b/src/hosts.rs @@ -222,6 +222,7 @@ impl Host { ))) } Some(conn) => { + conn.query_drop(format!("USE {}", query.get_schema()))?; conn.query_drop(format!( "CREATE CACHE d_{} FROM {}", query.get_digest(), diff --git a/src/queries.rs b/src/queries.rs index 359f565..d7c3312 100644 --- a/src/queries.rs +++ b/src/queries.rs @@ -195,8 +195,13 @@ impl QueryDiscovery { queries_added_or_change = true; if !proxysql.dry_run() { proxysql.get_online_hosts().iter_mut().for_each(|host| { - host.cache_query(query) - .expect("Failed to create readyset cache"); + host.cache_query(query).unwrap_or_else(|_| { + panic!( + "Failed to create readyset cache on host {}:{}", + host.get_hostname(), + host.get_port() + ) + }); }); proxysql .add_as_query_rule(query)