mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-19 06:20:38 +00:00
chore: add connection info to QueryContext (#6319)
chore/add-conn-info-to-query-ctx: ### Add Connection Information to Query Context - **`src/frontend/src/instance.rs`**: Updated to use `query_ctx.conn_info().to_string()` for connection information instead of a placeholder string. - **`src/session/src/context.rs`**: Introduced `conn_info` field in `QueryContext` and added a method `conn_info()` to retrieve it. Updated `QueryContextBuilder` to handle `conn_info`. - **`src/session/src/lib.rs`**: Modified `Session` to include `conn_info` in the query context building process. These changes enhance the query context by incorporating connection information, allowing for more detailed session management. Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
This commit is contained in:
@@ -184,7 +184,7 @@ impl Instance {
|
||||
query_ctx.current_catalog().to_string(),
|
||||
vec![query_ctx.current_schema()],
|
||||
stmt.to_string(),
|
||||
"unknown".to_string(),
|
||||
query_ctx.conn_info().to_string(),
|
||||
None,
|
||||
);
|
||||
|
||||
|
||||
@@ -67,6 +67,9 @@ pub struct QueryContext {
|
||||
/// Process id for managing on-going queries
|
||||
#[builder(default)]
|
||||
process_id: u64,
|
||||
/// Connection information
|
||||
#[builder(default)]
|
||||
conn_info: ConnInfo,
|
||||
}
|
||||
|
||||
/// This fields hold data that is only valid to current query context
|
||||
@@ -439,6 +442,11 @@ impl QueryContext {
|
||||
pub fn process_id(&self) -> u64 {
|
||||
self.process_id
|
||||
}
|
||||
|
||||
/// Get client information
|
||||
pub fn conn_info(&self) -> &ConnInfo {
|
||||
&self.conn_info
|
||||
}
|
||||
}
|
||||
|
||||
impl QueryContextBuilder {
|
||||
@@ -461,6 +469,7 @@ impl QueryContextBuilder {
|
||||
.unwrap_or_else(|| Arc::new(ConfigurationVariables::default())),
|
||||
channel,
|
||||
process_id: self.process_id.unwrap_or_default(),
|
||||
conn_info: self.conn_info.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,7 +481,7 @@ impl QueryContextBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ConnInfo {
|
||||
pub client_addr: Option<SocketAddr>,
|
||||
pub channel: Channel,
|
||||
|
||||
@@ -98,6 +98,7 @@ impl Session {
|
||||
.configuration_parameter(self.configuration_variables.clone())
|
||||
.channel(self.conn_info.channel)
|
||||
.process_id(self.process_id)
|
||||
.conn_info(self.conn_info.clone())
|
||||
.build()
|
||||
.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user