From 88a884edeebda84cdc44ba7a7b57343b511f48a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=82=8E=E6=B3=BC?= Date: Sat, 30 Mar 2024 13:23:02 +0800 Subject: [PATCH] refactor: remove count-table for tenant. It is not used at all (#15134) --- src/meta/api/src/schema_api.rs | 4 - src/meta/api/src/schema_api_impl.rs | 193 ------------------ src/meta/api/src/schema_api_test_suite.rs | 117 ----------- src/meta/app/src/schema/mod.rs | 3 - src/meta/app/src/schema/table.rs | 55 ++--- src/query/catalog/src/catalog/interface.rs | 4 - .../catalog/src/catalog/session_catalog.rs | 6 - .../src/catalogs/default/database_catalog.rs | 15 -- .../src/catalogs/default/immutable_catalog.rs | 9 - .../src/catalogs/default/mutable_catalog.rs | 8 - .../tests/it/sql/exec/get_table_bind_test.rs | 6 - .../it/storages/fuse/operations/commit.rs | 6 - .../storages/hive/hive/src/hive_catalog.rs | 7 - src/query/storages/iceberg/src/catalog.rs | 7 - 14 files changed, 13 insertions(+), 427 deletions(-) diff --git a/src/meta/api/src/schema_api.rs b/src/meta/api/src/schema_api.rs index 3e82b1f3cb782..d5341ad3f6297 100644 --- a/src/meta/api/src/schema_api.rs +++ b/src/meta/api/src/schema_api.rs @@ -15,8 +15,6 @@ use std::sync::Arc; use databend_common_meta_app::schema::CatalogInfo; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateCatalogReply; use databend_common_meta_app::schema::CreateCatalogReq; use databend_common_meta_app::schema::CreateDatabaseReply; @@ -272,8 +270,6 @@ pub trait SchemaApi: Send + Sync { req: GcDroppedTableReq, ) -> Result; - async fn count_tables(&self, req: CountTablesReq) -> Result; - async fn list_lock_revisions( &self, req: ListLockRevReq, diff --git a/src/meta/api/src/schema_api_impl.rs b/src/meta/api/src/schema_api_impl.rs index 32d85bd129ff9..6c795f2f3f407 100644 --- a/src/meta/api/src/schema_api_impl.rs +++ b/src/meta/api/src/schema_api_impl.rs @@ -65,9 +65,6 @@ use databend_common_meta_app::schema::CatalogIdToName; use databend_common_meta_app::schema::CatalogInfo; use databend_common_meta_app::schema::CatalogMeta; use databend_common_meta_app::schema::CatalogNameIdent; -use databend_common_meta_app::schema::CountTablesKey; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateCatalogReply; use databend_common_meta_app::schema::CreateCatalogReq; use databend_common_meta_app::schema::CreateDatabaseReply; @@ -204,7 +201,6 @@ use databend_common_meta_types::TxnGetRequest; use databend_common_meta_types::TxnGetResponse; use databend_common_meta_types::TxnOp; use databend_common_meta_types::TxnRequest; -use databend_common_meta_types::UpsertKV; use futures::TryStreamExt; use log::debug; use log::error; @@ -1521,7 +1517,6 @@ impl + ?Sized> SchemaApi for KV { debug!(req :? =(&req); "SchemaApi: {}", func_name!()); - let tenant = req.name_ident.tenant(); let tenant_dbname_tbname = &req.name_ident; let tenant_dbname = req.name_ident.db_name_ident(); @@ -1554,15 +1549,11 @@ impl + ?Sized> SchemaApi for KV { table_name: req.name_ident.table_name.clone(), }; - // fixed - let key_table_count = CountTablesKey::new(tenant.name()); - // The keys of values to re-fetch for every retry in this txn. let keys = vec![ key_dbid.to_string_key(), key_dbid_tbname.to_string_key(), key_table_id_list.to_string_key(), - key_table_count.to_string_key(), ]; // Initialize required key-values @@ -1574,21 +1565,6 @@ impl + ?Sized> SchemaApi for KV { .collect::>() }; - // Initialize table count if needed - assert_eq!(data[3].key, key_table_count.to_string_key()); - if data[3].value.is_none() { - init_table_count(self, &key_table_count).await?; - - // Re-fetch - data = { - let values = self.mget_kv(&keys).await?; - keys.iter() - .zip(values.into_iter()) - .map(|(k, v)| TxnGetResponse::new(k, v.map(pb::SeqV::from))) - .collect::>() - }; - } - let mut trials = txn_backoff(None, func_name!()); loop { trials.next().unwrap()?.await; @@ -1630,7 +1606,6 @@ impl + ?Sized> SchemaApi for KV { let mut condition = vec![]; let mut if_then = vec![]; - let mut tb_count = None; let opt = { let d = data.remove(0); @@ -1660,7 +1635,6 @@ impl + ?Sized> SchemaApi for KV { db_id.data, false, false, - &mut tb_count, &mut condition, &mut if_then, ) @@ -1680,14 +1654,6 @@ impl + ?Sized> SchemaApi for KV { v.unwrap_or_default() }; - let mut tb_count = { - let d = data.remove(0); - let (k, v) = deserialize_id_get_response::(d)?; - assert_eq!(key_table_count, k); - - v.unwrap_or_default() - }; - // Table id is unique and does not need to re-generate in every loop. if key_table_id.is_none() { let id = fetch_id(self, IdGenerator::table_id()).await?; @@ -1733,15 +1699,6 @@ impl + ?Sized> SchemaApi for KV { txn_op_put(&key_table_id_to_name, serialize_struct(&key_dbid_tbname)?), /* __fd_table_id_to_name/db_id/table_name -> DBIdTableName */ ]); - // tb_id_seq is 0 means that is a create operation, in this case need to update table count - if tb_id_seq == 0 { - tb_count.data.0 += 1; - // update table count atomically - condition.push(txn_cond_seq(&key_table_count, Eq, tb_count.seq)); - // _fd_table_count/tenant -> tb_count - if_then.push(txn_op_put(&key_table_count, serialize_u64(tb_count.data)?)); - } - let txn_req = TxnRequest { condition, if_then, @@ -1811,9 +1768,6 @@ impl + ?Sized> SchemaApi for KV { let tenant_dbname_tbname = &req.name_ident; let tenant_dbname = req.name_ident.db_name_ident(); - let mut tbcount_found = false; - let mut tb_count = 0; - let mut tb_count_seq; let mut trials = txn_backoff(None, func_name!()); loop { @@ -1883,22 +1837,6 @@ impl + ?Sized> SchemaApi for KV { let tbid = TableId { table_id }; let (tb_meta_seq, tb_meta): (_, Option) = get_pb_value(self, &tbid).await?; - // get current table count from _fd_table_count/tenant - let tb_count_key = CountTablesKey { - tenant: tenant_dbname.tenant.name().to_string(), - }; - (tb_count_seq, tb_count) = { - let (seq, count) = get_u64_value(self, &tb_count_key).await?; - if seq > 0 { - (seq, count) - } else if !tbcount_found { - // only count_tables for the first time. - tbcount_found = true; - (0, count_tables(self, &tb_count_key).await?) - } else { - (0, tb_count) - } - }; // add drop_on time on table meta // (db_id, table_name) -> table_id @@ -1928,8 +1866,6 @@ impl + ?Sized> SchemaApi for KV { txn_cond_seq(&dbid_tbname, Eq, tb_id_seq), // table is not changed txn_cond_seq(&tbid, Eq, tb_meta_seq), - // update table count atomically - txn_cond_seq(&tb_count_key, Eq, tb_count_seq), ], if_then: vec![ // Changing a table in a db has to update the seq of db_meta, @@ -1938,7 +1874,6 @@ impl + ?Sized> SchemaApi for KV { txn_op_put(&dbid_tbname, serialize_u64(table_id)?), /* (tenant, db_id, tb_name) -> tb_id */ // txn_op_put(&dbid_tbname_idlist, serialize_struct(&tb_id_list)?)?, // _fd_table_id_list/db_id/table_name -> tb_id_list txn_op_put(&tbid, serialize_struct(&tb_meta)?), /* (tenant, db_id, tb_id) -> tb_meta */ - txn_op_put(&tb_count_key, serialize_u64(tb_count + 1)?), /* _fd_table_count/tenant -> tb_count */ ], else_then: vec![], }; @@ -2564,7 +2499,6 @@ impl + ?Sized> SchemaApi for KV { let table_id = req.tb_id; debug!(req :? =(&table_id); "SchemaApi: {}", func_name!()); - let mut tb_count = None; let tenant = &req.tenant; let mut trials = txn_backoff(None, func_name!()); @@ -2582,7 +2516,6 @@ impl + ?Sized> SchemaApi for KV { req.db_id, req.if_exists, true, - &mut tb_count, &mut condition, &mut if_then, ) @@ -3584,65 +3517,6 @@ impl + ?Sized> SchemaApi for KV { Ok(GcDroppedTableResp {}) } - /// Get the count of tables for one tenant. - /// - /// Accept tenant name and returns the count of tables for the tenant. - /// - /// It get the count from kv space first, - /// if not found, it will compute the count by listing all databases and table ids. - #[logcall::logcall("debug")] - #[minitrace::trace] - async fn count_tables(&self, req: CountTablesReq) -> Result { - debug!(req :? =(&req); "SchemaApi: {}", func_name!()); - - let key = CountTablesKey { - tenant: req.tenant.to_string_key(), - }; - - let count = loop { - let (seq, cnt) = { - // get the count from kv space first - let (seq, c) = get_u64_value(self, &key).await?; - if seq > 0 { - // if seq > 0, we can get the count directly - break c; - } - - // if not, we should compute the count from by listing all databases and table ids - - // this line of codes will only be executed once, - // because if `send_txn` failed, it means another txn will put the count value into the kv spaceļ¼Œ - // and then the next loop will get the count value through `get_u64_value`. - (0, count_tables(self, &key).await?) - }; - - let key = CountTablesKey { - tenant: req.tenant.clone(), - }; - - let txn_req = TxnRequest { - // table count should not be changed. - condition: vec![txn_cond_seq(&key, Eq, seq)], - if_then: vec![txn_op_put(&key, serialize_u64(cnt)?)], - else_then: vec![], - }; - - let (succ, _) = send_txn(self, txn_req).await?; - // if txn succeeds, count can be returned safely - if succ { - break cnt; - } - }; - - debug!( - tenant = &req.tenant, - count = count; - "count tables for a tenant" - ); - - Ok(CountTablesReply { count }) - } - #[minitrace::trace] async fn list_lock_revisions( &self, @@ -4275,7 +4149,6 @@ async fn construct_drop_table_txn_operations( db_id: u64, if_exists: bool, if_delete: bool, - tb_count_opt: &mut Option, condition: &mut Vec, if_then: &mut Vec, ) -> Result<(Option<(Vec, Vec)>, u64), KVAppError> { @@ -4322,24 +4195,6 @@ async fn construct_drop_table_txn_operations( }; } - // get current table count from _fd_table_count/ - let tb_count_key = CountTablesKey { - tenant: tenant.name().to_string(), - }; - let (tb_count_seq, tb_count) = { - let (seq, count) = get_u64_value(kv_api, &tb_count_key).await?; - if seq > 0 { - (seq, count) - } else if tb_count_opt.is_none() { - // only count_tables for the first time. - let count = count_tables(kv_api, &tb_count_key).await?; - *tb_count_opt = Some(count); - (0, count) - } else { - (0, tb_count_opt.unwrap()) - } - }; - let (db_meta_seq, db_meta) = get_db_by_id_or_err(kv_api, db_id, "drop_table_by_id").await?; // cannot operate on shared database @@ -4385,11 +4240,6 @@ async fn construct_drop_table_txn_operations( condition.push(txn_cond_seq(&dbid_tbname, Eq, tb_id_seq)); // (db_id, tb_name) -> tb_id if_then.push(txn_op_del(&dbid_tbname)); - - // update table count atomically - condition.push(txn_cond_seq(&tb_count_key, Eq, tb_count_seq)); - // _fd_table_count/tenant -> tb_count - if_then.push(txn_op_put(&tb_count_key, serialize_u64(tb_count - 1)?)); } // remove table from share @@ -4771,49 +4621,6 @@ fn table_has_to_not_exist( } } -/// Initialize count of tables for one tenant. -async fn init_table_count( - kv_api: &(impl kvapi::KVApi + ?Sized), - key: &CountTablesKey, -) -> Result<(), KVAppError> { - let n = count_tables(kv_api, key).await?; - - kv_api - .upsert_kv(UpsertKV::insert(key.to_string_key(), &serialize_u64(n)?)) - .await?; - - Ok(()) -} - -/// Get the count of tables for one tenant by listing databases and table ids. -/// -/// It returns (seq, `u64` value). -/// If the count value is not in the kv space, (0, `u64` value) is returned. -async fn count_tables( - kv_api: &(impl kvapi::KVApi + ?Sized), - key: &CountTablesKey, -) -> Result { - // For backward compatibility: - // If the table count of a tenant is not found in kv space,, - // we should compute the count by listing all tables of the tenant. - let databases = kv_api - .list_databases(ListDatabaseReq { - tenant: Tenant::new_or_err(&key.tenant, func_name!())?, - filter: None, - }) - .await?; - let mut count = 0; - for db in databases.into_iter() { - let dbid_tbname = DBIdTableName { - db_id: db.ident.db_id, - table_name: "".to_string(), - }; - let (_, ids) = list_u64_value(kv_api, &dbid_tbname).await?; - count += ids.len() as u64; - } - Ok(count) -} - async fn get_share_table_info_map( kv_api: &(impl kvapi::KVApi + ?Sized), table_meta: &TableMeta, diff --git a/src/meta/api/src/schema_api_test_suite.rs b/src/meta/api/src/schema_api_test_suite.rs index c521dce20df6f..73bb59f3cd56c 100644 --- a/src/meta/api/src/schema_api_test_suite.rs +++ b/src/meta/api/src/schema_api_test_suite.rs @@ -37,7 +37,6 @@ use databend_common_meta_app::data_mask::MaskpolicyTableIdList; use databend_common_meta_app::schema::CatalogMeta; use databend_common_meta_app::schema::CatalogNameIdent; use databend_common_meta_app::schema::CatalogOption; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateCatalogReq; use databend_common_meta_app::schema::CreateDatabaseReply; use databend_common_meta_app::schema::CreateDatabaseReq; @@ -1665,7 +1664,6 @@ impl SchemaApiTestSuite { let db_name = "db1"; let tbl_name = "tb2"; - let mut expected_tb_count: u64 = 0; let schema = || { Arc::new(TableSchema::new(vec![TableField::new( @@ -1747,11 +1745,6 @@ impl SchemaApiTestSuite { res.db_id }; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - info!("--- create tb2 and get table"); let created_on = Utc::now(); @@ -1797,12 +1790,6 @@ impl SchemaApiTestSuite { } }; - expected_tb_count += 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - info!("--- create table again with if_not_exists = true"); { req.create_option = CreateOption::CreateIfNotExists; @@ -1825,11 +1812,6 @@ impl SchemaApiTestSuite { assert_meta_eq_without_updated!(want, got.as_ref().clone(), "get created table"); } - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - info!("--- create table again with if_not_exists = false"); { req.create_option = CreateOption::Create; @@ -1863,11 +1845,6 @@ impl SchemaApiTestSuite { assert_meta_eq_without_updated!(want, got.as_ref().clone(), "get old table"); } - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - info!("--- create another table"); { let created_on = Utc::now(); @@ -1897,12 +1874,6 @@ impl SchemaApiTestSuite { ); } - expected_tb_count += 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - let req = GetTableReq::new(&tenant, db_name, tbl_name); let tb_info = mt.get_table(req).await?; let tb_id = tb_info.ident.table_id; @@ -1968,12 +1939,6 @@ impl SchemaApiTestSuite { }; mt.drop_table_by_id(plan.clone()).await?; } - - expected_tb_count -= 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); } info!("--- create or replace db1"); @@ -1999,11 +1964,6 @@ impl SchemaApiTestSuite { let res = mt.create_table(req.clone()).await?; let old_table_id = res.table_id; - let tb_count = mt - .count_tables(Self::req_count_table(tenant_name)) - .await? - .count; - let req = GetTableReq::new(&tenant, db_name, table); let res = mt.get_table(req).await?; assert_eq!(res.meta.created_on, old_created_on); @@ -2032,13 +1992,6 @@ impl SchemaApiTestSuite { let res = mt.create_table(req.clone()).await?; let table_id = res.table_id; - // table count dose not change - assert_eq!( - tb_count, - mt.count_tables(Self::req_count_table(tenant_name)) - .await? - .count - ); // table meta has been changed let req = GetTableReq::new(&tenant, db_name, table); let res = mt.get_table(req).await?; @@ -4554,7 +4507,6 @@ impl SchemaApiTestSuite { db_name: db_name.to_string(), table_name: new_tbl_name.to_string(), }; - let mut expected_tb_count: u64 = 0; let schema = || { Arc::new(TableSchema::new(vec![TableField::new( @@ -4593,11 +4545,6 @@ impl SchemaApiTestSuite { assert_eq!(1, res.db_id, "first database id is 1"); } - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - let created_on = Utc::now(); let create_table_meta = table_meta(created_on); info!("--- create and get table"); @@ -4636,11 +4583,6 @@ impl SchemaApiTestSuite { .get_table((tenant_name, db_name, tbl_name).into()) .await?; let tb_id = tb_info.ident.table_id; - expected_tb_count += 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); info!("--- drop and undrop table"); { @@ -4661,12 +4603,6 @@ impl SchemaApiTestSuite { .await?; assert!(old_db.ident.seq < cur_db.ident.seq); - expected_tb_count -= 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - let res = mt .get_table_history(ListTableReq::new(&tenant, db_name)) .await?; @@ -4693,12 +4629,6 @@ impl SchemaApiTestSuite { .await?; assert!(old_db.ident.seq < cur_db.ident.seq); - expected_tb_count += 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - let res = mt .get_table_history(ListTableReq::new(&tenant, db_name)) .await?; @@ -4732,12 +4662,6 @@ impl SchemaApiTestSuite { .await?; assert!(old_db.ident.seq < cur_db.ident.seq); - expected_tb_count -= 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - let res = mt .get_table_history(ListTableReq::new(&tenant, db_name)) .await?; @@ -4768,12 +4692,6 @@ impl SchemaApiTestSuite { assert!(old_db.ident.seq < cur_db.ident.seq); assert!(res.table_id >= 1, "table id >= 1"); - expected_tb_count += 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - let res = mt .get_table_history(ListTableReq::new(&tenant, db_name)) .await?; @@ -4808,12 +4726,6 @@ impl SchemaApiTestSuite { .await?; assert!(old_db.ident.seq < cur_db.ident.seq); - expected_tb_count -= 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - let res = mt .get_table_history(ListTableReq::new(&tenant, db_name)) .await?; @@ -4839,12 +4751,6 @@ impl SchemaApiTestSuite { .await?; assert!(old_db.ident.seq < cur_db.ident.seq); - expected_tb_count += 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - let res = mt .get_table_history(ListTableReq::new(&tenant, db_name)) .await?; @@ -4891,12 +4797,6 @@ impl SchemaApiTestSuite { .await?; assert!(old_db.ident.seq < cur_db.ident.seq); - expected_tb_count += 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - calc_and_compare_drop_on_table_result(res, vec![ DroponInfo { name: tbl_name.to_string(), @@ -4940,12 +4840,6 @@ impl SchemaApiTestSuite { .await?; assert!(old_db.ident.seq < cur_db.ident.seq); - expected_tb_count -= 1; - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - let res = mt .get_table_history(ListTableReq::new(&tenant, db_name)) .await?; @@ -4987,11 +4881,6 @@ impl SchemaApiTestSuite { .await?; assert!(old_db.ident.seq < cur_db.ident.seq); - // check table count - info!("--- check table count of tenant1"); - let tb_count = mt.count_tables(Self::req_count_table(tenant_name)).await?; - assert_eq!(expected_tb_count, tb_count.count); - let res = mt .get_table_history(ListTableReq::new(&tenant, db_name)) .await?; @@ -6704,12 +6593,6 @@ impl SchemaApiTestSuite { } } - fn req_count_table(tenant: impl ToString) -> CountTablesReq { - CountTablesReq { - tenant: tenant.to_string(), - } - } - async fn create_database( &self, mt: &MT, diff --git a/src/meta/app/src/schema/mod.rs b/src/meta/app/src/schema/mod.rs index 23f9d8108d783..a1f35e83e5fa3 100644 --- a/src/meta/app/src/schema/mod.rs +++ b/src/meta/app/src/schema/mod.rs @@ -66,9 +66,6 @@ pub use lock::LockMeta; pub use lock::LockType; pub use lock::TableLockKey; pub use ownership::Ownership; -pub use table::CountTablesKey; -pub use table::CountTablesReply; -pub use table::CountTablesReq; pub use table::CreateTableIndexReply; pub use table::CreateTableIndexReq; pub use table::CreateTableReply; diff --git a/src/meta/app/src/schema/table.rs b/src/meta/app/src/schema/table.rs index 57ea4202dc4f5..0a7f02e75e2a7 100644 --- a/src/meta/app/src/schema/table.rs +++ b/src/meta/app/src/schema/table.rs @@ -896,36 +896,6 @@ pub struct GcDroppedTableReq { #[derive(Clone, Debug, PartialEq, Eq)] pub struct GcDroppedTableResp {} -#[derive(Clone, Debug, Eq, PartialEq, Default)] -pub struct CountTablesKey { - pub tenant: String, -} - -impl Display for CountTablesKey { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "'{}'", self.tenant) - } -} - -impl CountTablesKey { - pub fn new(tenant: impl ToString) -> Self { - Self { - tenant: tenant.to_string(), - } - } -} - -/// count tables for a tenant -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct CountTablesReq { - pub tenant: String, -} - -#[derive(Debug)] -pub struct CountTablesReply { - pub count: u64, -} - #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct TableIdToName { pub table_id: u64, @@ -991,7 +961,6 @@ mod kvapi_key_impl { use databend_common_meta_kvapi::kvapi::Key; use crate::primitive::Id; - use crate::schema::CountTablesKey; use crate::schema::DBIdTableName; use crate::schema::DatabaseId; use crate::schema::LeastVisibleTime; @@ -1113,29 +1082,31 @@ mod kvapi_key_impl { } } + /// Reserved removed key, never reused: /// "__fd_table_count/" -> + /// + /// It was used for count number of tables belonging to a tenant + #[derive(Debug)] + struct CountTablesKey { + #[allow(dead_code)] + tenant: Tenant, + } + impl kvapi::Key for CountTablesKey { const PREFIX: &'static str = "__fd_table_count"; type ValueType = Id; fn parent(&self) -> Option { - Some(Tenant::new(&self.tenant).to_string_key()) + None } fn to_string_key(&self) -> String { - kvapi::KeyBuilder::new_prefixed(Self::PREFIX) - .push_raw(&self.tenant) - .done() + unimplemented!("removed and reserved") } - fn from_str_key(s: &str) -> Result { - let mut p = kvapi::KeyParser::new_prefixed(s, Self::PREFIX)?; - - let tenant = p.next_str()?; - p.done()?; - - Ok(CountTablesKey { tenant }) + fn from_str_key(_s: &str) -> Result { + unimplemented!("removed and reserved") } } diff --git a/src/query/catalog/src/catalog/interface.rs b/src/query/catalog/src/catalog/interface.rs index d2b68a423af57..4201ba24034de 100644 --- a/src/query/catalog/src/catalog/interface.rs +++ b/src/query/catalog/src/catalog/interface.rs @@ -19,8 +19,6 @@ use std::sync::Arc; use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_meta_app::schema::CatalogInfo; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateDatabaseReply; use databend_common_meta_app::schema::CreateDatabaseReq; use databend_common_meta_app::schema::CreateIndexReply; @@ -285,8 +283,6 @@ pub trait Catalog: DynClone + Send + Sync + Debug { async fn drop_table_index(&self, req: DropTableIndexReq) -> Result; - async fn count_tables(&self, req: CountTablesReq) -> Result; - async fn get_table_copied_file_info( &self, tenant: &str, diff --git a/src/query/catalog/src/catalog/session_catalog.rs b/src/query/catalog/src/catalog/session_catalog.rs index c5ee3de951728..40cdb14c82b95 100644 --- a/src/query/catalog/src/catalog/session_catalog.rs +++ b/src/query/catalog/src/catalog/session_catalog.rs @@ -18,8 +18,6 @@ use std::sync::Arc; use databend_common_exception::Result; use databend_common_meta_app::schema::CatalogInfo; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateDatabaseReply; use databend_common_meta_app::schema::CreateDatabaseReq; use databend_common_meta_app::schema::CreateIndexReply; @@ -385,10 +383,6 @@ impl Catalog for SessionCatalog { self.inner.drop_table_index(req).await } - async fn count_tables(&self, req: CountTablesReq) -> Result { - self.inner.count_tables(req).await - } - async fn get_table_copied_file_info( &self, tenant: &str, diff --git a/src/query/service/src/catalogs/default/database_catalog.rs b/src/query/service/src/catalogs/default/database_catalog.rs index 894de68d25ac3..1abf29a8374c9 100644 --- a/src/query/service/src/catalogs/default/database_catalog.rs +++ b/src/query/service/src/catalogs/default/database_catalog.rs @@ -26,8 +26,6 @@ use databend_common_config::InnerConfig; use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_meta_app::schema::CatalogInfo; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateDatabaseReply; use databend_common_meta_app::schema::CreateDatabaseReq; use databend_common_meta_app::schema::CreateIndexReply; @@ -480,19 +478,6 @@ impl Catalog for DatabaseCatalog { self.mutable_catalog.drop_table_index(req).await } - #[async_backtrace::framed] - async fn count_tables(&self, req: CountTablesReq) -> Result { - if req.tenant.is_empty() { - return Err(ErrorCode::TenantIsEmpty( - "Tenant can not empty(while count tables)", - )); - } - - let res = self.mutable_catalog.count_tables(req).await?; - - Ok(res) - } - #[async_backtrace::framed] async fn get_table_copied_file_info( &self, diff --git a/src/query/service/src/catalogs/default/immutable_catalog.rs b/src/query/service/src/catalogs/default/immutable_catalog.rs index 08983d23e48e8..6fb536a9a2372 100644 --- a/src/query/service/src/catalogs/default/immutable_catalog.rs +++ b/src/query/service/src/catalogs/default/immutable_catalog.rs @@ -22,8 +22,6 @@ use databend_common_config::InnerConfig; use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_meta_app::schema::CatalogInfo; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateDatabaseReply; use databend_common_meta_app::schema::CreateDatabaseReq; use databend_common_meta_app::schema::CreateIndexReply; @@ -310,13 +308,6 @@ impl Catalog for ImmutableCatalog { unimplemented!() } - #[async_backtrace::framed] - async fn count_tables(&self, _req: CountTablesReq) -> Result { - Err(ErrorCode::Unimplemented( - "Cannot count tables in system database", - )) - } - #[async_backtrace::framed] async fn get_table_copied_file_info( &self, diff --git a/src/query/service/src/catalogs/default/mutable_catalog.rs b/src/query/service/src/catalogs/default/mutable_catalog.rs index 76e9d357aef03..493c6af209e9c 100644 --- a/src/query/service/src/catalogs/default/mutable_catalog.rs +++ b/src/query/service/src/catalogs/default/mutable_catalog.rs @@ -22,8 +22,6 @@ use databend_common_config::InnerConfig; use databend_common_exception::Result; use databend_common_meta_api::SchemaApi; use databend_common_meta_app::schema::CatalogInfo; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateDatabaseReply; use databend_common_meta_app::schema::CreateDatabaseReq; use databend_common_meta_app::schema::CreateIndexReply; @@ -567,12 +565,6 @@ impl Catalog for MutableCatalog { Ok(self.ctx.meta.drop_table_index(req).await?) } - #[async_backtrace::framed] - async fn count_tables(&self, req: CountTablesReq) -> Result { - let res = self.ctx.meta.count_tables(req).await?; - Ok(res) - } - #[async_backtrace::framed] async fn list_lock_revisions(&self, req: ListLockRevReq) -> Result> { Ok(self.ctx.meta.list_lock_revisions(req).await?) diff --git a/src/query/service/tests/it/sql/exec/get_table_bind_test.rs b/src/query/service/tests/it/sql/exec/get_table_bind_test.rs index ad38fb5a8dc5d..c55367c403964 100644 --- a/src/query/service/tests/it/sql/exec/get_table_bind_test.rs +++ b/src/query/service/tests/it/sql/exec/get_table_bind_test.rs @@ -51,8 +51,6 @@ use databend_common_meta_app::principal::RoleInfo; use databend_common_meta_app::principal::UserDefinedConnection; use databend_common_meta_app::principal::UserInfo; use databend_common_meta_app::schema::CatalogInfo; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateDatabaseReply; use databend_common_meta_app::schema::CreateDatabaseReq; use databend_common_meta_app::schema::CreateIndexReply; @@ -275,10 +273,6 @@ impl Catalog for FakedCatalog { unimplemented!() } - async fn count_tables(&self, _req: CountTablesReq) -> Result { - todo!() - } - async fn get_table_copied_file_info( &self, _tenant: &str, diff --git a/src/query/service/tests/it/storages/fuse/operations/commit.rs b/src/query/service/tests/it/storages/fuse/operations/commit.rs index caa9bf02fd542..582eb573aae50 100644 --- a/src/query/service/tests/it/storages/fuse/operations/commit.rs +++ b/src/query/service/tests/it/storages/fuse/operations/commit.rs @@ -50,8 +50,6 @@ use databend_common_meta_app::principal::RoleInfo; use databend_common_meta_app::principal::UserDefinedConnection; use databend_common_meta_app::principal::UserInfo; use databend_common_meta_app::schema::CatalogInfo; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateDatabaseReply; use databend_common_meta_app::schema::CreateDatabaseReq; use databend_common_meta_app::schema::CreateIndexReply; @@ -901,10 +899,6 @@ impl Catalog for FakedCatalog { unimplemented!() } - async fn count_tables(&self, _req: CountTablesReq) -> Result { - todo!() - } - async fn get_table_copied_file_info( &self, _tenant: &str, diff --git a/src/query/storages/hive/hive/src/hive_catalog.rs b/src/query/storages/hive/hive/src/hive_catalog.rs index 06663f5b055cd..d88a80645c20f 100644 --- a/src/query/storages/hive/hive/src/hive_catalog.rs +++ b/src/query/storages/hive/hive/src/hive_catalog.rs @@ -29,8 +29,6 @@ use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_meta_app::schema::CatalogInfo; use databend_common_meta_app::schema::CatalogOption; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateDatabaseReply; use databend_common_meta_app::schema::CreateDatabaseReq; use databend_common_meta_app::schema::CreateIndexReply; @@ -581,11 +579,6 @@ impl Catalog for HiveCatalog { unimplemented!() } - #[async_backtrace::framed] - async fn count_tables(&self, _req: CountTablesReq) -> Result { - unimplemented!() - } - #[async_backtrace::framed] async fn create_index(&self, _req: CreateIndexReq) -> Result { unimplemented!() diff --git a/src/query/storages/iceberg/src/catalog.rs b/src/query/storages/iceberg/src/catalog.rs index 3b2dbd77451a2..7a90b1059b23e 100644 --- a/src/query/storages/iceberg/src/catalog.rs +++ b/src/query/storages/iceberg/src/catalog.rs @@ -27,8 +27,6 @@ use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_meta_app::schema::CatalogInfo; use databend_common_meta_app::schema::CatalogOption; -use databend_common_meta_app::schema::CountTablesReply; -use databend_common_meta_app::schema::CountTablesReq; use databend_common_meta_app::schema::CreateDatabaseReply; use databend_common_meta_app::schema::CreateDatabaseReq; use databend_common_meta_app::schema::CreateIndexReply; @@ -382,11 +380,6 @@ impl Catalog for IcebergCatalog { unimplemented!() } - #[async_backtrace::framed] - async fn count_tables(&self, _req: CountTablesReq) -> Result { - unimplemented!() - } - #[async_backtrace::framed] async fn get_table_copied_file_info( &self,