Fix panic & query router bug (#85)

* Fix query router bug

* Fix panic
This commit is contained in:
Lev Kokotov
2022-06-24 15:14:31 -07:00
committed by GitHub
parent b93303eb83
commit f06f64119c
2 changed files with 8 additions and 6 deletions

View File

@@ -302,7 +302,11 @@ impl Client {
// Handle all custom protocol commands, if any. // Handle all custom protocol commands, if any.
match query_router.try_execute_command(message.clone()) { match query_router.try_execute_command(message.clone()) {
// Normal query, not a custom command. // Normal query, not a custom command.
None => (), None => {
if query_router.query_parser_enabled() {
query_router.infer_role(message.clone());
}
}
// SET SHARD TO // SET SHARD TO
Some((Command::SetShard, _)) => { Some((Command::SetShard, _)) => {

View File

@@ -126,11 +126,7 @@ impl QueryRouter {
// This is not a custom query, try to infer which // This is not a custom query, try to infer which
// server it'll go to if the query parser is enabled. // server it'll go to if the query parser is enabled.
if matches.len() != 1 { if matches.len() != 1 {
debug!("Regular query"); debug!("Regular query, not a command");
if self.query_parser_enabled && self.role() == None {
debug!("Inferring role");
self.infer_role(buf.clone());
}
return None; return None;
} }
@@ -266,6 +262,8 @@ impl QueryRouter {
/// Try to infer which server to connect to based on the contents of the query. /// Try to infer which server to connect to based on the contents of the query.
pub fn infer_role(&mut self, mut buf: BytesMut) -> bool { pub fn infer_role(&mut self, mut buf: BytesMut) -> bool {
debug!("Inferring role");
let code = buf.get_u8() as char; let code = buf.get_u8() as char;
let len = buf.get_i32() as usize; let len = buf.get_i32() as usize;