Skip to content

Commit

Permalink
Force cache creation to set default schema
Browse files Browse the repository at this point in the history
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
  • Loading branch information
altmannmarcelo committed Dec 2, 2024
1 parent fd19b11 commit 471e049
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
9 changes: 7 additions & 2 deletions src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 471e049

Please sign in to comment.