Skip to content

Commit

Permalink
refactor: use unified global var
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePieWw committed Jan 6, 2025
1 parent 7b0a3f8 commit eb5f268
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/cli/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use common_meta::key::{TableMetadataManager, TableMetadataManagerRef};
use common_meta::kv_backend::etcd::EtcdStore;
use common_meta::kv_backend::memory::MemoryKvBackend;
#[cfg(feature = "pg_kvbackend")]
use common_meta::kv_backend::postgres::PgStore;
use common_meta::kv_backend::postgres::{PgStore, META_TABLE_NAME};
use common_meta::peer::Peer;
use common_meta::rpc::router::{Region, RegionRoute};
use common_telemetry::info;
Expand Down Expand Up @@ -78,7 +78,7 @@ impl BenchTableMetadataCommand {
#[cfg(feature = "pg_kvbackend")]
let kv_backend = if let Some(postgres_addr) = &self.postgres_addr {
info!("Using postgres as kv backend");
PgStore::with_url(postgres_addr, 128, "greptime_metakv".to_string())
PgStore::with_url(postgres_addr, 128, META_TABLE_NAME.to_string())
.await
.unwrap()
} else {
Expand Down
11 changes: 5 additions & 6 deletions src/common/meta/src/kv_backend/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ use crate::rpc::store::{
};
use crate::rpc::KeyValue;

pub const META_TABLE_NAME: &str = "greptime_metakv";

type PgClient = deadpool::managed::Object<deadpool_postgres::Manager>;

enum PgQueryExecutor<'a> {
Expand Down Expand Up @@ -981,17 +983,14 @@ mod tests {
.unwrap();
let client = pool.get().await.unwrap();
client
.execute(
&replace_table_name(METADKV_CREATION, "greptime_metakv"),
&[],
)
.execute(&replace_table_name(METADKV_CREATION, META_TABLE_NAME), &[])
.await
.context(PostgresExecutionSnafu)
.unwrap();
Some(PgStore {
pool,
max_txn_ops: 128,
table_name: "greptime_metakv".to_string(),
table_name: META_TABLE_NAME.to_string(),
})
}

Expand Down Expand Up @@ -1046,7 +1045,7 @@ mod tests {
.get_client()
.await
.unwrap()
.execute("DELETE FROM greptime_metakv", &[])
.execute(&replace_table_name("DELETE FROM {}", META_TABLE_NAME), &[])
.await
.unwrap();
}
Expand Down
20 changes: 12 additions & 8 deletions src/meta-srv/src/election/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ impl PgElection {
mod tests {
use std::env;

use common_meta::kv_backend::postgres::META_TABLE_NAME;
use tokio_postgres::{Client, NoTls};

use super::*;
Expand All @@ -668,7 +669,10 @@ mod tests {
});
let _ = client
.execute(
"CREATE TABLE IF NOT EXISTS greptime_metakv(k varchar PRIMARY KEY, v varchar)",
&replace_table_name(
"CREATE TABLE IF NOT EXISTS {}(k varchar PRIMARY KEY, v varchar)",
META_TABLE_NAME,
),
&[],
)
.await
Expand All @@ -692,7 +696,7 @@ mod tests {
leader_watcher: tx,
store_key_prefix: uuid::Uuid::new_v4().to_string(),
candidate_lease_ttl_secs: 10,
table_name: "greptime_metakv".to_string(),
table_name: META_TABLE_NAME.to_string(),
lock_id: 28319,
};

Expand Down Expand Up @@ -767,7 +771,7 @@ mod tests {
leader_watcher: tx,
store_key_prefix,
candidate_lease_ttl_secs,
table_name: "greptime_metakv".to_string(),
table_name: META_TABLE_NAME.to_string(),
lock_id: 28319,
};

Expand Down Expand Up @@ -810,7 +814,7 @@ mod tests {
leader_watcher: tx,
store_key_prefix: store_key_prefix.clone(),
candidate_lease_ttl_secs,
table_name: "greptime_metakv".to_string(),
table_name: META_TABLE_NAME.to_string(),
lock_id: 28319,
};

Expand Down Expand Up @@ -852,7 +856,7 @@ mod tests {
leader_watcher: tx,
store_key_prefix: uuid::Uuid::new_v4().to_string(),
candidate_lease_ttl_secs,
table_name: "greptime_metakv".to_string(),
table_name: META_TABLE_NAME.to_string(),
lock_id: 28320,
};

Expand Down Expand Up @@ -962,7 +966,7 @@ mod tests {
leader_watcher: tx,
store_key_prefix,
candidate_lease_ttl_secs,
table_name: "greptime_metakv".to_string(),
table_name: META_TABLE_NAME.to_string(),
lock_id: 28321,
};

Expand Down Expand Up @@ -1193,7 +1197,7 @@ mod tests {
leader_watcher: tx,
store_key_prefix: store_key_prefix.clone(),
candidate_lease_ttl_secs,
table_name: "greptime_metakv".to_string(),
table_name: META_TABLE_NAME.to_string(),
lock_id: 28322,
};

Expand All @@ -1207,7 +1211,7 @@ mod tests {
leader_watcher: tx,
store_key_prefix,
candidate_lease_ttl_secs,
table_name: "greptime_metakv".to_string(),
table_name: META_TABLE_NAME.to_string(),
lock_id: 28322,
};

Expand Down
6 changes: 3 additions & 3 deletions src/meta-srv/src/metasrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use common_meta::cache_invalidator::CacheInvalidatorRef;
use common_meta::ddl::ProcedureExecutorRef;
use common_meta::key::maintenance::MaintenanceModeManagerRef;
use common_meta::key::TableMetadataManagerRef;
#[cfg(feature = "pg_kvbackend")]
use common_meta::kv_backend::postgres::META_TABLE_NAME;
use common_meta::kv_backend::{KvBackendRef, ResettableKvBackend, ResettableKvBackendRef};
use common_meta::leadership_notifier::{
LeadershipChangeNotifier, LeadershipChangeNotifierCustomizerRef,
Expand Down Expand Up @@ -70,8 +72,6 @@ use crate::state::{become_follower, become_leader, StateRef};
pub const TABLE_ID_SEQ: &str = "table_id";
pub const FLOW_ID_SEQ: &str = "flow_id";
pub const METASRV_HOME: &str = "/tmp/metasrv";
#[cfg(feature = "pg_kvbackend")]
pub const PG_TABLE_NAME: &str = "greptime_metakv";

// The datastores that implements metadata kvbackend.
#[derive(Clone, Debug, PartialEq, Serialize, Default, Deserialize, ValueEnum)]
Expand Down Expand Up @@ -179,7 +179,7 @@ impl Default for MetasrvOptions {
tracing: TracingOptions::default(),
backend: BackendImpl::EtcdStore,
#[cfg(feature = "pg_kvbackend")]
meta_table_name: PG_TABLE_NAME.to_string(),
meta_table_name: META_TABLE_NAME.to_string(),
}
}
}
Expand Down

0 comments on commit eb5f268

Please sign in to comment.