diff --git a/src/config.rs b/src/config.rs index 734a3b3..c69144e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,7 +18,7 @@ pub struct Config { pub fn read_config_file(path: &str) -> Result { let mut file = - File::open(path).expect(format!("Failed to open config file at path {}", path).as_str()); + File::open(path).unwrap_or_else(|_| panic!("Failed to open config file at path {}", path)); let mut contents = String::new(); file.read_to_string(&mut contents)?; Ok(contents) diff --git a/src/main.rs b/src/main.rs index 0a16ffc..40ebc2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,12 +27,17 @@ fn main() { let args = Args::parse(); let config_file = read_config_file(&args.config).expect("Failed to read config file"); let config = config::parse_config_file(&config_file).expect("Failed to parse config file"); - let file = match OpenOptions::new().read(true).write(true).create(true).open( - config - .clone() - .lock_file - .unwrap_or("/tmp/readyset_scheduler.lock".to_string()), - ) { + let file = match OpenOptions::new() + .read(true) + .write(true) + .create(true) + .truncate(true) + .open( + config + .clone() + .lock_file + .unwrap_or("/tmp/readyset_scheduler.lock".to_string()), + ) { Ok(file) => file, Err(err) => { messages::print_error( @@ -133,7 +138,9 @@ fn main() { match supported { Ok(true) => { messages::print_info( - format!("Query is supported, adding it to proxysql and readyset").as_str(), + "Query is supported, adding it to proxysql and readyset" + .to_string() + .as_str(), ); queries_added_or_change = true; queries::cache_query(&mut readyset_conn, &digest_text) diff --git a/src/queries.rs b/src/queries.rs index 75551f5..8646bc9 100644 --- a/src/queries.rs +++ b/src/queries.rs @@ -27,10 +27,10 @@ pub fn find_queries_to_cache( rows } -pub fn replace_placeholders(query: &String) -> String { +pub fn replace_placeholders(query: &str) -> String { // date placeholder - let query = query.replace("?-?-?", "?"); - query + + query.replace("?-?-?", "?") } pub fn check_readyset_query_support( diff --git a/src/server.rs b/src/server.rs index 52c67d1..3ea9e13 100644 --- a/src/server.rs +++ b/src/server.rs @@ -55,14 +55,13 @@ pub fn change_server_status( config.readyset_host, config.readyset_port, status.unwrap(), - server_status.to_string() + server_status ) .as_str(), ); ps_conn.query_drop(format!( "UPDATE mysql_servers SET status = '{}' {}", - server_status.to_string(), - where_clause + server_status, where_clause ))?; ps_conn.query_drop("LOAD MYSQL SERVERS TO RUNTIME")?; ps_conn.query_drop("SAVE MYSQL SERVERS TO DISK")?;