From 5e9b5d981f4a614c31656b44ea1554e5acd2cc4c Mon Sep 17 00:00:00 2001 From: Weny Xu Date: Thu, 29 May 2025 11:58:06 +0800 Subject: [PATCH] chore: fix feature gates for pg and mysql kvbackend (#6211) --- src/cli/src/meta_snapshot.rs | 37 ++++++++++++++++++++----------- src/common/meta/src/kv_backend.rs | 3 +++ src/meta-srv/src/metasrv.rs | 9 +++----- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/cli/src/meta_snapshot.rs b/src/cli/src/meta_snapshot.rs index d0622bd7dc..670a9a2c10 100644 --- a/src/cli/src/meta_snapshot.rs +++ b/src/cli/src/meta_snapshot.rs @@ -20,10 +20,9 @@ use common_base::secrets::{ExposeSecret, SecretString}; use common_error::ext::BoxedError; use common_meta::kv_backend::chroot::ChrootKvBackend; use common_meta::kv_backend::etcd::EtcdStore; -use common_meta::kv_backend::rds::{MySqlStore, PgStore}; -use common_meta::kv_backend::{KvBackendRef, DEFAULT_META_TABLE_NAME}; +use common_meta::kv_backend::KvBackendRef; use common_meta::snapshot::MetadataSnapshotManager; -use meta_srv::bootstrap::{create_etcd_client, create_mysql_pool, create_postgres_pool}; +use meta_srv::bootstrap::create_etcd_client; use meta_srv::metasrv::BackendImpl; use object_store::services::{Fs, S3}; use object_store::ObjectStore; @@ -41,7 +40,8 @@ struct MetaConnection { backend: Option, #[clap(long, default_value = "")] store_key_prefix: String, - #[clap(long,default_value = DEFAULT_META_TABLE_NAME)] + #[cfg(any(feature = "pg_kvbackend", feature = "mysql_kvbackend"))] + #[clap(long,default_value = common_meta::kv_backend::DEFAULT_META_TABLE_NAME)] meta_table_name: String, #[clap(long, default_value = "128")] max_txn_ops: usize, @@ -50,7 +50,6 @@ struct MetaConnection { impl MetaConnection { pub async fn build(&self) -> Result { let max_txn_ops = self.max_txn_ops; - let table_name = &self.meta_table_name; let store_addrs = &self.store_addrs; if store_addrs.is_empty() { KvBackendNotSetSnafu { backend: "all" } @@ -64,21 +63,33 @@ impl MetaConnection { .map_err(BoxedError::new)?; Ok(EtcdStore::with_etcd_client(etcd_client, max_txn_ops)) } + #[cfg(feature = "pg_kvbackend")] Some(BackendImpl::PostgresStore) => { - let pool = create_postgres_pool(store_addrs) + let table_name = &self.meta_table_name; + let pool = meta_srv::bootstrap::create_postgres_pool(store_addrs) .await .map_err(BoxedError::new)?; - Ok(PgStore::with_pg_pool(pool, table_name, max_txn_ops) - .await - .map_err(BoxedError::new)?) + Ok(common_meta::kv_backend::rds::PgStore::with_pg_pool( + pool, + table_name, + max_txn_ops, + ) + .await + .map_err(BoxedError::new)?) } + #[cfg(feature = "mysql_kvbackend")] Some(BackendImpl::MysqlStore) => { - let pool = create_mysql_pool(store_addrs) + let table_name = &self.meta_table_name; + let pool = meta_srv::bootstrap::create_mysql_pool(store_addrs) .await .map_err(BoxedError::new)?; - Ok(MySqlStore::with_mysql_pool(pool, table_name, max_txn_ops) - .await - .map_err(BoxedError::new)?) + Ok(common_meta::kv_backend::rds::MySqlStore::with_mysql_pool( + pool, + table_name, + max_txn_ops, + ) + .await + .map_err(BoxedError::new)?) } _ => KvBackendNotSetSnafu { backend: "all" } .fail() diff --git a/src/common/meta/src/kv_backend.rs b/src/common/meta/src/kv_backend.rs index ea2736225d..ecc93c3ff5 100644 --- a/src/common/meta/src/kv_backend.rs +++ b/src/common/meta/src/kv_backend.rs @@ -39,8 +39,11 @@ pub mod util; pub type KvBackendRef = Arc + Send + Sync>; #[cfg(any(feature = "pg_kvbackend", feature = "mysql_kvbackend"))] +// The default meta table name, default is "greptime_metakv". pub const DEFAULT_META_TABLE_NAME: &str = "greptime_metakv"; + #[cfg(any(feature = "pg_kvbackend", feature = "mysql_kvbackend"))] +// The default lock id for election, default is 1. pub const DEFAULT_META_ELECTION_LOCK_ID: u64 = 1; #[async_trait] diff --git a/src/meta-srv/src/metasrv.rs b/src/meta-srv/src/metasrv.rs index 09f304b968..04042c5c54 100644 --- a/src/meta-srv/src/metasrv.rs +++ b/src/meta-srv/src/metasrv.rs @@ -29,10 +29,7 @@ use common_meta::ddl::ProcedureExecutorRef; use common_meta::distributed_time_constants; use common_meta::key::maintenance::MaintenanceModeManagerRef; use common_meta::key::TableMetadataManagerRef; -use common_meta::kv_backend::{ - KvBackendRef, ResettableKvBackend, ResettableKvBackendRef, DEFAULT_META_ELECTION_LOCK_ID, - DEFAULT_META_TABLE_NAME, -}; +use common_meta::kv_backend::{KvBackendRef, ResettableKvBackend, ResettableKvBackendRef}; use common_meta::leadership_notifier::{ LeadershipChangeNotifier, LeadershipChangeNotifierCustomizerRef, }; @@ -244,9 +241,9 @@ impl Default for MetasrvOptions { tracing: TracingOptions::default(), backend: BackendImpl::EtcdStore, #[cfg(any(feature = "pg_kvbackend", feature = "mysql_kvbackend"))] - meta_table_name: DEFAULT_META_TABLE_NAME.to_string(), + meta_table_name: common_meta::kv_backend::DEFAULT_META_TABLE_NAME.to_string(), #[cfg(feature = "pg_kvbackend")] - meta_election_lock_id: DEFAULT_META_ELECTION_LOCK_ID, + meta_election_lock_id: common_meta::kv_backend::DEFAULT_META_ELECTION_LOCK_ID, node_max_idle_time: Duration::from_secs(24 * 60 * 60), } }