feat(xugu): expose tablespaces and datafiles in tree

This commit is contained in:
Elias authored and GitHub committed 2026-09-01 00:34:12 +08:00
1 parent afe3b3f3c2
commit 351a8b699b
32 files changed
+811 -4

No files matched your search

+15
View File
@@ -1196,6 +1196,7 @@ pub enum AgentMethod {
ListTables,
ListObjects,
ListDataTypes,
ListXuguTablespaces,
CompletionAssistantSearchV1,
GetObjectSource,
GetColumns,
@@ -1283,6 +1284,7 @@ impl AgentMethod {
Self::ListTables => "list_tables",
Self::ListObjects => "list_objects",
Self::ListDataTypes => "list_data_types",
Self::ListXuguTablespaces => "list_xugu_tablespaces",
Self::CompletionAssistantSearchV1 => "completion_assistant_search_v1",
Self::GetObjectSource => "get_object_source",
Self::GetTableDdl => "get_table_ddl",
@@ -2109,6 +2111,18 @@ impl AgentDriverClient {
.await
}
pub async fn list_xugu_tablespaces<T: DeserializeOwned + Send + 'static>(
&mut self,
database: Option<&str>,
timeout_duration: Option<Duration>,
) -> Result<T, String> {
let params = database
.filter(|database| !database.trim().is_empty())
.map(|database| serde_json::json!({ "database": database }))
.unwrap_or_else(|| serde_json::json!({}));
self.call_method_with_timeout(AgentMethod::ListXuguTablespaces, params, timeout_duration).await
}
pub async fn completion_assistant_search<T: DeserializeOwned + Send + 'static>(
&mut self,
request: &crate::types::CompletionAssistantRequest,
@@ -4873,6 +4887,7 @@ for line in sys.stdin:
assert_eq!(AgentMethod::ListTables.as_str(), "list_tables");
assert_eq!(AgentMethod::ListObjects.as_str(), "list_objects");
assert_eq!(AgentMethod::ListDataTypes.as_str(), "list_data_types");
assert_eq!(AgentMethod::ListXuguTablespaces.as_str(), "list_xugu_tablespaces");
assert_eq!(AgentMethod::CompletionAssistantSearchV1.as_str(), "completion_assistant_search_v1");
assert_eq!(AgentMethod::GetObjectSource.as_str(), "get_object_source");
assert_eq!(AgentMethod::GetColumns.as_str(), "get_columns");
+34
View File
@@ -197,6 +197,40 @@ pub async fn list_databases_core(state: &AppState, connection_id: &str) -> Resul
retry_metadata_connection(state, connection_id, None, || list_databases_once(state, connection_id)).await
}
/// Lists XuguDB tablespaces and their physical data files for the selected
/// database. This is deliberately a no-op for every other database type so
/// the common schema surface and non-Xugu drivers remain untouched.
pub async fn list_xugu_tablespaces_core(
state: &AppState,
connection_id: &str,
database: Option<&str>,
) -> Result<Vec<db::XuguTablespaceInfo>, String> {
let config = connection_config(state, connection_id).await;
if !config.as_ref().is_some_and(|config| config.db_type == DatabaseType::Xugu) {
return Ok(Vec::new());
}
retry_metadata_connection(state, connection_id, database.filter(|database| !database.is_empty()), || async {
let pool_key = state
.get_or_create_metadata_pool_for_session(
connection_id,
database.filter(|database| !database.is_empty()),
None,
)
.await?;
let config = connection_config(state, connection_id).await;
let connections = state.connections.read().await;
if let Some(client) = extract_pool!(&connections, &pool_key, Agent) {
drop(connections);
let mut client = client.lock().await;
return client
.list_xugu_tablespaces::<Vec<db::XuguTablespaceInfo>>(database, agent_metadata_timeout(config.as_ref()))
.await;
}
Ok(Vec::new())
})
.await
}
/// Loads the more expensive database-level properties needed only by the
/// connection resource browser. General metadata paths keep using
/// `list_databases_core`, which only enumerates names.
+31
View File
@@ -25,6 +25,37 @@ pub struct DatabaseStorageInfo {
pub size_bytes: Option<i64>,
}
/// XuguDB storage metadata exposed by the read-only schema browser.
///
/// Xugu stores tablespaces and their data files inside the selected database,
/// so these types intentionally remain driver-specific instead of widening
/// the common database model used by other engines.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct XuguDatafileInfo {
pub node_id: String,
pub space_id: i64,
pub path: String,
pub file_no: i64,
pub max_size: Option<i64>,
pub step_size: Option<i64>,
pub curr_size: Option<i64>,
pub reserved1: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct XuguTablespaceInfo {
pub node_id: String,
pub space_id: i64,
pub space_name: String,
pub datafile_num: i64,
pub space_type: String,
pub media_error: Option<String>,
pub total_chunk_num: Option<i64>,
pub free_chunk_num: Option<i64>,
#[serde(default)]
pub datafiles: Vec<XuguDatafileInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SchemaInfo {
pub name: String,