Skip to content

Commit

Permalink
chore: simplify get_gc_table_info()
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Sep 23, 2024
1 parent 163a04a commit 2c56294
Showing 1 changed file with 8 additions and 39 deletions.
47 changes: 8 additions & 39 deletions src/meta/api/src/schema_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3613,18 +3613,17 @@ fn build_upsert_table_deduplicated_label(deduplicated_label: String) -> TxnOp {
#[fastrace::trace]
async fn batch_filter_table_info(
kv_api: &(impl kvapi::KVApi<Error = MetaError> + ?Sized),
filter_db_info_with_table_name_list: &[(&TableInfoFilter, &Arc<DatabaseInfo>, u64, &String)],
args: &[(&TableInfoFilter, &Arc<DatabaseInfo>, u64, String)],
filter_tb_infos: &mut Vec<(Arc<TableInfo>, u64)>,
) -> Result<(), KVAppError> {
let table_id_idents = filter_db_info_with_table_name_list
let table_id_idents = args
.iter()
.map(|(_f, _db, table_id, _table_name)| TableId::new(*table_id));

let seq_metas = kv_api.get_pb_values_vec(table_id_idents).await?;

for (seq_meta, (filter, db_info, table_id, table_name)) in seq_metas
.into_iter()
.zip(filter_db_info_with_table_name_list.iter())
for (seq_meta, (filter, db_info, table_id, table_name)) in
seq_metas.into_iter().zip(args.iter())
{
let Some(seq_meta) = seq_meta else {
error!(
Expand Down Expand Up @@ -3671,42 +3670,12 @@ async fn get_gc_table_info(
limit: usize,
table_id_list: &TableFilterInfoList<'_>,
) -> Result<Vec<(Arc<TableInfo>, u64)>, KVAppError> {
let mut filter_tb_infos = vec![];

let mut filter_db_info_with_table_name_list: Vec<(
&TableInfoFilter,
&Arc<DatabaseInfo>,
u64,
&String,
)> = vec![];

for (filter, db_info, table_id, table_name) in table_id_list {
filter_db_info_with_table_name_list.push((filter, db_info, *table_id, table_name));
if filter_db_info_with_table_name_list.len() < DEFAULT_MGET_SIZE {
continue;
}
let table_id_list = &table_id_list[..std::cmp::min(limit, table_id_list.len())];

batch_filter_table_info(
kv_api,
&filter_db_info_with_table_name_list,
&mut filter_tb_infos,
)
.await?;

filter_db_info_with_table_name_list.clear();

if filter_tb_infos.len() >= limit {
return Ok(filter_tb_infos);
}
}
let mut filter_tb_infos = vec![];

if !filter_db_info_with_table_name_list.is_empty() {
batch_filter_table_info(
kv_api,
&filter_db_info_with_table_name_list,
&mut filter_tb_infos,
)
.await?;
for chunk in table_id_list.chunks(DEFAULT_MGET_SIZE) {
batch_filter_table_info(kv_api, &chunk, &mut filter_tb_infos).await?;
}

Ok(filter_tb_infos)
Expand Down

0 comments on commit 2c56294

Please sign in to comment.