From 3ca80b149ff09a6b25527cadc3b3fb996beb400b Mon Sep 17 00:00:00 2001 From: Yang Xiufeng Date: Thu, 5 Dec 2024 11:16:26 +0800 Subject: [PATCH] fix: need_sticky field was incorrectly set to true. (#16997) * fix: need_sticky field was incorrectly set to true. * update cargo.lock --- Cargo.lock | 10 ++++----- .../src/servers/http/v1/query/http_query.rs | 8 +++---- .../storages/common/session/src/temp_table.rs | 22 ++----------------- .../09_http_handler/09_0008_forward.py | 15 +++++++++---- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f190d2e7627..a0a638c02a87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3096,7 +3096,7 @@ dependencies = [ name = "databend-common-cache" version = "0.1.0" dependencies = [ - "hashbrown 0.15.0", + "hashbrown 0.15.2", "hashlink 0.8.4", ] @@ -7859,9 +7859,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ "foldhash", ] @@ -8550,7 +8550,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.0", + "hashbrown 0.15.2", "serde", ] @@ -10272,7 +10272,7 @@ checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "crc32fast", "flate2", - "hashbrown 0.15.0", + "hashbrown 0.15.2", "indexmap 2.6.0", "memchr", "ruzstd", diff --git a/src/query/service/src/servers/http/v1/query/http_query.rs b/src/query/service/src/servers/http/v1/query/http_query.rs index 4286c80c28ab..7b935706b220 100644 --- a/src/query/service/src/servers/http/v1/query/http_query.rs +++ b/src/query/service/src/servers/http/v1/query/http_query.rs @@ -532,12 +532,10 @@ impl HttpQuery { let tenant = session.get_current_tenant(); let user_name = session.get_current_user()?.name; - let has_temp_table_before_run = if let Some(cid) = session.get_client_session_id() { + if let Some(cid) = session.get_client_session_id() { ClientSessionManager::instance().on_query_start(&cid, &user_name, &session); - true - } else { - false }; + let has_temp_table_before_run = !session.temp_tbl_mgr().lock().is_empty(); http_query_runtime_instance.runtime().try_spawn( async move { let state = state_clone.clone(); @@ -672,7 +670,7 @@ impl HttpQuery { let mut guard = self.has_temp_table_after_run.lock(); match *guard { None => { - let not_empty = !session_state.temp_tbl_mgr.lock().is_empty().0; + let not_empty = !session_state.temp_tbl_mgr.lock().is_empty(); *guard = Some(not_empty); ClientSessionManager::instance().on_query_finish( cid, diff --git a/src/query/storages/common/session/src/temp_table.rs b/src/query/storages/common/session/src/temp_table.rs index fd7d9f6d4468..7c20705d53ec 100644 --- a/src/query/storages/common/session/src/temp_table.rs +++ b/src/query/storages/common/session/src/temp_table.rs @@ -53,8 +53,6 @@ pub struct TempTblMgr { name_to_id: HashMap, id_to_table: HashMap, next_id: u64, - - empty_state_changed: bool, } #[derive(Debug, Clone)] @@ -71,7 +69,6 @@ impl TempTblMgr { name_to_id: HashMap::new(), id_to_table: HashMap::new(), next_id: TEMP_TBL_ID_BEGIN, - empty_state_changed: false, })) } @@ -82,14 +79,8 @@ impl TempTblMgr { } } - pub fn is_empty(&mut self) -> (bool, bool) { - let is_empty = self.id_to_table.is_empty(); - if self.empty_state_changed { - self.empty_state_changed = false; - (is_empty, true) - } else { - (is_empty, false) - } + pub fn is_empty(&mut self) -> bool { + self.id_to_table.is_empty() } pub fn create_table(&mut self, req: CreateTableReq) -> Result { @@ -137,9 +128,6 @@ impl TempTblMgr { true } }; - if self.id_to_table.len() == 1 { - self.empty_state_changed = true; - } Ok(CreateTableReply { table_id, table_id_seq: Some(0), @@ -345,9 +333,6 @@ pub async fn drop_table_by_id( guard, req )) })?; - if guard.name_to_id.is_empty() { - guard.empty_state_changed = true; - } dir } Entry::Vacant(_) => { @@ -371,9 +356,6 @@ pub async fn drop_table_by_id( guard, req )) })?; - if guard.name_to_id.is_empty() { - guard.empty_state_changed = true; - } } Entry::Vacant(_) => { return Ok(None); diff --git a/tests/suites/1_stateful/09_http_handler/09_0008_forward.py b/tests/suites/1_stateful/09_http_handler/09_0008_forward.py index 38a3f1a170b3..d6501e6a794f 100755 --- a/tests/suites/1_stateful/09_http_handler/09_0008_forward.py +++ b/tests/suites/1_stateful/09_http_handler/09_0008_forward.py @@ -10,11 +10,11 @@ logging.basicConfig(level=logging.ERROR, format="%(asctime)s %(levelname)s %(message)s") -def do_query(query, port=8000, session=None, node_id=None): +def do_query(query, port=8000, session=None, node_id=None, wait=100): url = f"http://localhost:{port}/v1/query" query_payload = { "sql": query, - "pagination": {"wait_time_secs": 100, "max_rows_per_page": 2}, + "pagination": {"wait_time_secs": wait, "max_rows_per_page": 2}, } if session: query_payload["session"] = session @@ -88,15 +88,22 @@ def test_query(): assert resp.status_code == 400, resp.text +def test_initial_response(): + sql = "select * from numbers(1000000000000) ignore_result" + resp = do_query(sql, wait=1).json() + assert not (resp.get("session").get("need_sticky")), resp + + def main(): + test_initial_response() + # only test under cluster mode query_resp = do_query("select count(*) from system.clusters").json() num_nodes = int(query_resp.get("data")[0][0]) if num_nodes == 1: return - # test_query() - + test_query() test_txn()