From 9c67d44acee3b76585d61632fe7b437a03cab4dd Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" Date: Sat, 2 Nov 2024 21:57:43 -0700 Subject: [PATCH] fix/database-base-ttl: Refactor SchemaMetadataManager and adjust Cargo.toml dependencies - Remove unused imports in schema_metadata_manager.rs - Add conditional compilation for SchemaMetadataManager::new - Update Cargo.toml to remove "testing" feature from common-meta dependency in main section and add it to dev-dependencies --- .../meta/src/key/schema_metadata_manager.rs | 31 ++++++++++++++----- src/mito2/Cargo.toml | 3 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/common/meta/src/key/schema_metadata_manager.rs b/src/common/meta/src/key/schema_metadata_manager.rs index fc6172041d05..6ee3a3112d5d 100644 --- a/src/common/meta/src/key/schema_metadata_manager.rs +++ b/src/common/meta/src/key/schema_metadata_manager.rs @@ -16,14 +16,12 @@ use std::sync::Arc; -use common_telemetry::info; use snafu::OptionExt; use store_api::storage::TableId; -use table::metadata::{RawTableInfo, TableType}; use crate::error::TableInfoNotFoundSnafu; -use crate::key::schema_name::{SchemaManager, SchemaNameKey, SchemaNameValue}; -use crate::key::table_info::{TableInfoManager, TableInfoManagerRef, TableInfoValue}; +use crate::key::schema_name::{SchemaManager, SchemaNameKey}; +use crate::key::table_info::{TableInfoManager, TableInfoManagerRef}; use crate::kv_backend::KvBackendRef; use crate::{error, SchemaOptions}; @@ -32,11 +30,24 @@ pub type SchemaMetadataManagerRef = Arc; pub struct SchemaMetadataManager { table_info_manager: TableInfoManagerRef, schema_manager: SchemaManager, + #[cfg(any(test, feature = "testing"))] kv_backend: KvBackendRef, } impl SchemaMetadataManager { /// Creates a new database meta + #[cfg(not(any(test, feature = "testing")))] + pub fn new(kv_backend: KvBackendRef) -> Self { + let table_info_manager = Arc::new(TableInfoManager::new(kv_backend.clone())); + let schema_manager = SchemaManager::new(kv_backend); + Self { + table_info_manager, + schema_manager, + } + } + + /// Creates a new database meta + #[cfg(any(test, feature = "testing"))] pub fn new(kv_backend: KvBackendRef) -> Self { let table_info_manager = Arc::new(TableInfoManager::new(kv_backend.clone())); let schema_manager = SchemaManager::new(kv_backend.clone()); @@ -74,9 +85,10 @@ impl SchemaMetadataManager { table_name: &str, schema_name: &str, catalog_name: &str, - schema_value: Option, + schema_value: Option, ) { - let value = TableInfoValue::new(RawTableInfo { + use table::metadata::{RawTableInfo, TableType}; + let value = crate::key::table_info::TableInfoValue::new(RawTableInfo { ident: Default::default(), name: table_name.to_string(), desc: None, @@ -99,9 +111,12 @@ impl SchemaMetadataManager { .create(key, schema_value, false) .await .expect("Failed to create schema metadata"); - info!( + common_telemetry::info!( "Register table: {}, id: {}, schema: {}, catalog: {}", - table_name, table_id, schema_name, catalog_name + table_name, + table_id, + schema_name, + catalog_name ); } } diff --git a/src/mito2/Cargo.toml b/src/mito2/Cargo.toml index da02da63820f..eedf6ae636d8 100644 --- a/src/mito2/Cargo.toml +++ b/src/mito2/Cargo.toml @@ -24,7 +24,7 @@ common-datasource.workspace = true common-decimal.workspace = true common-error.workspace = true common-macro.workspace = true -common-meta = { workspace = true, features = ["testing"] } +common-meta.workspace = true common-query.workspace = true common-recordbatch.workspace = true common-runtime.workspace = true @@ -75,6 +75,7 @@ uuid.workspace = true [dev-dependencies] common-function.workspace = true +common-meta = { workspace = true, features = ["testing"] } common-procedure-test.workspace = true common-test-util.workspace = true criterion = "0.4"