From 42d9048f9efd17c7058b9cbb05bcb69ce0ea99f4 Mon Sep 17 00:00:00 2001 From: dantengsky Date: Mon, 13 Mar 2023 17:15:51 +0800 Subject: [PATCH 1/2] fix: show process status info --- src/query/catalog/src/table_context.rs | 1 + .../service/src/sessions/query_ctx_shared.rs | 6 +++++ .../service/src/sessions/session_info.rs | 24 +++++++++++-------- .../storages/system/src/processes_table.rs | 8 ++++++- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/query/catalog/src/table_context.rs b/src/query/catalog/src/table_context.rs index c3da8bdde68c6..3fb7b1f4be4cd 100644 --- a/src/query/catalog/src/table_context.rs +++ b/src/query/catalog/src/table_context.rs @@ -57,6 +57,7 @@ pub struct ProcessInfo { pub scan_progress_value: Option, pub mysql_connection_id: Option, pub created_time: SystemTime, + pub status_info: Option, } #[derive(Debug, Clone)] diff --git a/src/query/service/src/sessions/query_ctx_shared.rs b/src/query/service/src/sessions/query_ctx_shared.rs index 1c34d8c6f171e..c73c87d52905e 100644 --- a/src/query/service/src/sessions/query_ctx_shared.rs +++ b/src/query/service/src/sessions/query_ctx_shared.rs @@ -233,6 +233,7 @@ impl QueryContextShared { } } + // TODO to_cache? async fn get_table_to_cache( &self, catalog: &str, @@ -339,6 +340,11 @@ impl QueryContextShared { pub fn get_created_time(&self) -> SystemTime { self.created_time } + + pub fn get_status_info(&self) -> String { + let status = self.status.read(); + status.clone() + } } impl Drop for QueryContextShared { diff --git a/src/query/service/src/sessions/session_info.rs b/src/query/service/src/sessions/session_info.rs index 0907052933672..9907b75c2fdaa 100644 --- a/src/query/service/src/sessions/session_info.rs +++ b/src/query/service/src/sessions/session_info.rs @@ -29,10 +29,11 @@ impl Session { self.to_process_info(&session_ctx) } - fn to_process_info(self: &Arc, status: &SessionContext) -> ProcessInfo { + fn to_process_info(self: &Arc, session_ctx: &SessionContext) -> ProcessInfo { let mut memory_usage = 0; - if let Some(shared) = status.get_query_context_shared() { + let shared_query_context = &session_ctx.get_query_context_shared(); + if let Some(shared) = shared_query_context { if let Ok(runtime) = shared.try_get_runtime() { let mem_stat = runtime.get_tracker(); memory_usage = mem_stat.get_memory_usage(); @@ -42,17 +43,20 @@ impl Session { ProcessInfo { id: self.id.clone(), typ: self.get_type().to_string(), - state: self.process_state(status), - database: status.get_current_database(), - user: status.get_current_user(), + state: self.process_state(session_ctx), + database: session_ctx.get_current_database(), + user: session_ctx.get_current_user(), settings: self.get_settings(), - client_address: status.get_client_host(), - session_extra_info: self.process_extra_info(status), + client_address: session_ctx.get_client_host(), + session_extra_info: self.process_extra_info(session_ctx), memory_usage, - data_metrics: Self::query_data_metrics(status), - scan_progress_value: Self::query_scan_progress_value(status), + data_metrics: Self::query_data_metrics(session_ctx), + scan_progress_value: Self::query_scan_progress_value(session_ctx), mysql_connection_id: self.mysql_connection_id, - created_time: Self::query_created_time(status), + created_time: Self::query_created_time(session_ctx), + status_info: shared_query_context + .as_ref() + .map(|qry_ctx| qry_ctx.get_status_info()), } } diff --git a/src/query/storages/system/src/processes_table.rs b/src/query/storages/system/src/processes_table.rs index 0ea98d809399e..597d1b7911e80 100644 --- a/src/query/storages/system/src/processes_table.rs +++ b/src/query/storages/system/src/processes_table.rs @@ -106,7 +106,13 @@ impl SyncSystemTable for ProcessesTable { } // Status info. - processes_status.push(ctx.get_status_info().clone().into_bytes()); + processes_status.push( + process_info + .status_info + .clone() + .unwrap_or("".to_owned()) + .into_bytes(), + ); } Ok(DataBlock::new_from_columns(vec![ From d75b0912028039308a01e2c5905a9d102e2ade35 Mon Sep 17 00:00:00 2001 From: dantengsky Date: Mon, 13 Mar 2023 17:19:08 +0800 Subject: [PATCH 2/2] clean up --- src/query/service/src/sessions/query_ctx_shared.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/query/service/src/sessions/query_ctx_shared.rs b/src/query/service/src/sessions/query_ctx_shared.rs index c73c87d52905e..543bb323b7888 100644 --- a/src/query/service/src/sessions/query_ctx_shared.rs +++ b/src/query/service/src/sessions/query_ctx_shared.rs @@ -233,7 +233,6 @@ impl QueryContextShared { } } - // TODO to_cache? async fn get_table_to_cache( &self, catalog: &str,