Skip to content

Commit 3f8e36c

Browse files
authored
refactor: remove get_table_name_by_id() (#15389)
1 parent ef0fdc9 commit 3f8e36c

File tree

13 files changed

+7
-199
lines changed

13 files changed

+7
-199
lines changed

src/meta/api/src/schema_api.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ pub trait SchemaApi: Send + Sync {
215215
table_ids: &[MetaId],
216216
) -> Result<Vec<Option<String>>, KVAppError>;
217217

218-
async fn get_table_name_by_id(&self, table_id: MetaId) -> Result<String, KVAppError>;
219218
async fn mget_database_names_by_ids(
220219
&self,
221220
db_ids: &[MetaId],

src/meta/api/src/schema_api_impl.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,27 +2245,6 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {
22452245
Ok(seq_table_meta)
22462246
}
22472247

2248-
#[logcall::logcall("debug")]
2249-
#[minitrace::trace]
2250-
async fn get_table_name_by_id(&self, table_id: MetaId) -> Result<String, KVAppError> {
2251-
debug!(req :? =(&table_id); "SchemaApi: {}", func_name!());
2252-
2253-
let table_id_to_name_key = TableIdToName { table_id };
2254-
2255-
let (tb_meta_seq, table_name): (_, Option<DBIdTableName>) =
2256-
get_pb_value(self, &table_id_to_name_key).await?;
2257-
2258-
debug!(ident :% =(&table_id_to_name_key); "get_table_name_by_id");
2259-
2260-
if tb_meta_seq == 0 || table_name.is_none() {
2261-
return Err(KVAppError::AppError(AppError::UnknownTableId(
2262-
UnknownTableId::new(table_id, "get_table_name_by_id"),
2263-
)));
2264-
}
2265-
2266-
Ok(table_name.unwrap().table_name)
2267-
}
2268-
22692248
#[logcall::logcall("debug")]
22702249
#[minitrace::trace]
22712250
async fn mget_table_names_by_ids(

src/meta/api/src/schema_api_test_suite.rs

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ impl SchemaApiTestSuite {
354354
.drop_table_without_tableid_to_name(&b.build().await)
355355
.await?;
356356

357-
suite.get_table_name_by_id(&b.build().await).await?;
358357
suite.get_db_name_by_id(&b.build().await).await?;
359358
suite.test_sequence(&b.build().await).await?;
360359

@@ -5044,106 +5043,6 @@ impl SchemaApiTestSuite {
50445043
Ok(())
50455044
}
50465045

5047-
#[minitrace::trace]
5048-
async fn get_table_name_by_id<MT: SchemaApi>(&self, mt: &MT) -> anyhow::Result<()> {
5049-
let tenant_name = "tenant1";
5050-
let tenant = Tenant::new_or_err(tenant_name, func_name!())?;
5051-
5052-
let db_name = "db1";
5053-
let tbl_name = "tb2";
5054-
5055-
let schema = || {
5056-
Arc::new(TableSchema::new(vec![TableField::new(
5057-
"number",
5058-
TableDataType::Number(NumberDataType::UInt64),
5059-
)]))
5060-
};
5061-
5062-
let options = || maplit::btreemap! {"opt‐1".into() => "val-1".into()};
5063-
5064-
let table_meta = |created_on| TableMeta {
5065-
schema: schema(),
5066-
engine: "JSON".to_string(),
5067-
options: options(),
5068-
created_on,
5069-
..TableMeta::default()
5070-
};
5071-
5072-
info!("--- prepare db");
5073-
{
5074-
let plan = CreateDatabaseReq {
5075-
create_option: CreateOption::Create,
5076-
name_ident: DatabaseNameIdent::new(&tenant, db_name),
5077-
meta: DatabaseMeta {
5078-
engine: "".to_string(),
5079-
..DatabaseMeta::default()
5080-
},
5081-
};
5082-
5083-
let res = mt.create_database(plan).await?;
5084-
info!("create database res: {:?}", res);
5085-
5086-
assert_eq!(1, res.db_id, "first database id is 1");
5087-
}
5088-
5089-
info!("--- create and get table");
5090-
{
5091-
let created_on = Utc::now();
5092-
5093-
let req = CreateTableReq {
5094-
create_option: CreateOption::Create,
5095-
name_ident: TableNameIdent {
5096-
tenant: Tenant::new_or_err(tenant_name, func_name!())?,
5097-
db_name: db_name.to_string(),
5098-
table_name: tbl_name.to_string(),
5099-
},
5100-
table_meta: table_meta(created_on),
5101-
as_dropped: false,
5102-
};
5103-
5104-
{
5105-
let old_db = mt.get_database(Self::req_get_db(&tenant, db_name)).await?;
5106-
let res = mt.create_table(req.clone()).await?;
5107-
let cur_db = mt.get_database(Self::req_get_db(&tenant, db_name)).await?;
5108-
assert!(old_db.ident.seq < cur_db.ident.seq);
5109-
assert!(res.table_id >= 1, "table id >= 1");
5110-
let tb_id = res.table_id;
5111-
5112-
let got = mt.get_table_name_by_id(tb_id).await?;
5113-
5114-
let want = tbl_name.to_string();
5115-
assert_eq!(want, got, "get created table");
5116-
}
5117-
}
5118-
5119-
info!("--- get_table_name_by_id ");
5120-
{
5121-
info!("--- get_table_name_by_id ");
5122-
{
5123-
let table = mt
5124-
.get_table((tenant_name, "db1", "tb2").into())
5125-
.await
5126-
.unwrap();
5127-
5128-
let want = table.name.clone();
5129-
let got = mt.get_table_name_by_id(table.ident.table_id).await?;
5130-
5131-
assert_eq!(want, got);
5132-
}
5133-
5134-
info!("--- get_table_name_by_id with not exists table_id");
5135-
{
5136-
let got = mt.get_table_name_by_id(1024).await;
5137-
5138-
let err = got.unwrap_err();
5139-
let err = ErrorCode::from(err);
5140-
5141-
assert_eq!(ErrorCode::UNKNOWN_TABLE_ID, err.code());
5142-
}
5143-
}
5144-
Ok(())
5145-
}
5146-
51475046
#[minitrace::trace]
51485047
async fn get_db_name_by_id<MT: SchemaApi>(&self, mt: &MT) -> anyhow::Result<()> {
51495048
let tenant_name = "tenant1";

src/meta/service/src/metrics/meta_metrics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub mod server_metrics {
9797
);
9898
registry.register(
9999
key!("applying_snapshot"),
100-
"applying snapshot",
100+
"if this node is applying snapshot",
101101
metrics.applying_snapshot.clone(),
102102
);
103103
registry.register(
@@ -118,12 +118,12 @@ pub mod server_metrics {
118118
);
119119
registry.register(
120120
key!("proposals_pending"),
121-
"proposals pending",
121+
"proposals pending, raft-log is proposed, not yet applied",
122122
metrics.proposals_pending.clone(),
123123
);
124124
registry.register(
125125
key!("proposals_failed"),
126-
"proposals failed",
126+
"number of failed proposals(raft-log), due to leader change or storage error",
127127
metrics.proposals_failed.clone(),
128128
);
129129
registry.register(

src/query/catalog/src/catalog/interface.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,6 @@ pub trait Catalog: DynClone + Send + Sync + Debug {
198198
/// Get the table meta by table id.
199199
async fn get_table_meta_by_id(&self, table_id: MetaId) -> Result<Option<SeqV<TableMeta>>>;
200200

201-
// Get the table name by meta id.
202-
async fn get_table_name_by_id(&self, table_id: MetaId) -> Result<String>;
203-
204201
// List the tables name by meta ids.
205202
async fn mget_table_names_by_ids(
206203
&self,

src/query/catalog/src/catalog/session_catalog.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,6 @@ impl Catalog for SessionCatalog {
240240
}
241241
}
242242

243-
// Get the table name by meta id.
244-
async fn get_table_name_by_id(&self, table_id: MetaId) -> Result<String> {
245-
let state = self.txn_mgr.lock().state();
246-
match state {
247-
TxnState::Active => {
248-
let mutated_table = self.txn_mgr.lock().get_table_from_buffer_by_id(table_id);
249-
if let Some(t) = mutated_table {
250-
Ok(t.name.clone())
251-
} else {
252-
self.inner.get_table_name_by_id(table_id).await
253-
}
254-
}
255-
_ => self.inner.get_table_name_by_id(table_id).await,
256-
}
257-
}
258-
259243
// Mget the dbs name by meta ids.
260244
async fn mget_table_names_by_ids(
261245
&self,

src/query/service/src/catalogs/default/database_catalog.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,6 @@ impl Catalog for DatabaseCatalog {
271271
}
272272
}
273273

274-
#[async_backtrace::framed]
275-
async fn get_table_name_by_id(&self, table_id: MetaId) -> Result<String> {
276-
let res = self.immutable_catalog.get_table_name_by_id(table_id).await;
277-
278-
if let Ok(x) = res {
279-
Ok(x)
280-
} else {
281-
self.mutable_catalog.get_table_name_by_id(table_id).await
282-
}
283-
}
284-
285274
#[async_backtrace::framed]
286275
async fn mget_table_names_by_ids(
287276
&self,

src/query/service/src/catalogs/default/immutable_catalog.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,6 @@ impl Catalog for ImmutableCatalog {
203203
Ok(Some(seq_table_meta))
204204
}
205205

206-
async fn get_table_name_by_id(&self, table_id: MetaId) -> Result<String> {
207-
let table = self
208-
.sys_db_meta
209-
.get_by_id(&table_id)
210-
.ok_or_else(|| ErrorCode::UnknownTable(format!("Unknown table id: '{}'", table_id)))?;
211-
Ok(table.name().to_string())
212-
}
213-
214206
async fn mget_table_names_by_ids(
215207
&self,
216208
_tenant: &Tenant,

src/query/service/src/catalogs/default/mutable_catalog.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,6 @@ impl Catalog for MutableCatalog {
371371
Ok(res)
372372
}
373373

374-
#[async_backtrace::framed]
375-
async fn get_table_name_by_id(
376-
&self,
377-
table_id: MetaId,
378-
) -> databend_common_exception::Result<String> {
379-
let res = self.ctx.meta.get_table_name_by_id(table_id).await?;
380-
Ok(res)
381-
}
382-
383374
async fn mget_table_names_by_ids(
384375
&self,
385376
_tenant: &Tenant,

src/query/service/tests/it/sql/exec/get_table_bind_test.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,6 @@ impl Catalog for FakedCatalog {
188188
self.cat.get_table_by_info(table_info)
189189
}
190190

191-
async fn get_table_meta_by_id(&self, table_id: MetaId) -> Result<Option<SeqV<TableMeta>>> {
192-
self.cat.get_table_meta_by_id(table_id).await
193-
}
194-
195-
async fn get_table_name_by_id(&self, table_id: MetaId) -> Result<String> {
196-
self.cat.get_table_name_by_id(table_id).await
197-
}
198-
199191
async fn mget_table_names_by_ids(
200192
&self,
201193
tenant: &Tenant,
@@ -419,6 +411,10 @@ impl Catalog for FakedCatalog {
419411
async fn drop_sequence(&self, _req: DropSequenceReq) -> Result<DropSequenceReply> {
420412
unimplemented!()
421413
}
414+
415+
async fn get_table_meta_by_id(&self, table_id: MetaId) -> Result<Option<SeqV<TableMeta>>> {
416+
self.cat.get_table_meta_by_id(table_id).await
417+
}
422418
}
423419

424420
struct CtxDelegation {

0 commit comments

Comments
 (0)