Skip to content

Commit d11c4fa

Browse files
authored
fix: vacuum drop table with limit does not work (#18460)
* fix: vacuum drop table with limit does not work * add result set * fix test * fix test
1 parent 4f7398a commit d11c4fa

File tree

7 files changed

+48
-26
lines changed

7 files changed

+48
-26
lines changed

src/meta/api/src/schema_api_impl.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,31 +3703,40 @@ async fn get_history_tables_for_gc(
37033703
}
37043704

37053705
let mut filter_tb_infos = vec![];
3706+
const BATCH_SIZE: usize = 1000;
37063707

3707-
let limited_args = &args[..std::cmp::min(limit, args.len())];
3708-
let table_id_idents = limited_args.iter().map(|(table_id, _)| table_id.clone());
3708+
// Process in batches to avoid performance issues
3709+
for chunk in args.chunks(BATCH_SIZE) {
3710+
// Get table metadata for current batch
3711+
let table_id_idents = chunk.iter().map(|(table_id, _)| table_id.clone());
3712+
let seq_metas = kv_api.get_pb_values_vec(table_id_idents).await?;
37093713

3710-
let seq_metas = kv_api.get_pb_values_vec(table_id_idents).await?;
3714+
// Filter by drop_time_range for current batch
3715+
for (seq_meta, (table_id, table_name)) in seq_metas.into_iter().zip(chunk.iter()) {
3716+
let Some(seq_meta) = seq_meta else {
3717+
error!(
3718+
"batch_filter_table_info cannot find {:?} table_meta",
3719+
table_id
3720+
);
3721+
continue;
3722+
};
37113723

3712-
for (seq_meta, (table_id, table_name)) in seq_metas.into_iter().zip(limited_args.iter()) {
3713-
let Some(seq_meta) = seq_meta else {
3714-
error!(
3715-
"batch_filter_table_info cannot find {:?} table_meta",
3716-
table_id
3717-
);
3718-
continue;
3719-
};
3724+
if !drop_time_range.contains(&seq_meta.data.drop_on) {
3725+
info!("table {:?} is not in drop_time_range", seq_meta.data);
3726+
continue;
3727+
}
37203728

3721-
if !drop_time_range.contains(&seq_meta.data.drop_on) {
3722-
info!("table {:?} is not in drop_time_range", seq_meta.data);
3723-
continue;
3724-
}
3729+
filter_tb_infos.push(TableNIV::new(
3730+
DBIdTableName::new(db_id, table_name.clone()),
3731+
table_id.clone(),
3732+
seq_meta,
3733+
));
37253734

3726-
filter_tb_infos.push(TableNIV::new(
3727-
DBIdTableName::new(db_id, table_name.clone()),
3728-
table_id.clone(),
3729-
seq_meta,
3730-
));
3735+
// Check if we have reached the limit
3736+
if filter_tb_infos.len() >= limit {
3737+
return Ok(filter_tb_infos);
3738+
}
3739+
}
37313740
}
37323741

37333742
Ok(filter_tb_infos)

src/query/service/src/interpreters/interpreter_vacuum_drop_tables.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ impl Interpreter for VacuumDropTablesInterpreter {
182182
tables.len()
183183
);
184184

185+
let tables_count = tables.len();
186+
185187
let handler = get_vacuum_handler();
186188
let threads_nums = self.ctx.get_settings().get_max_threads()? as usize;
187189
let (files_opt, failed_tables) = handler
@@ -230,7 +232,10 @@ impl Interpreter for VacuumDropTablesInterpreter {
230232
}
231233

232234
match files_opt {
233-
None => return Ok(PipelineBuildResult::create()),
235+
None => PipelineBuildResult::from_blocks(vec![DataBlock::new_from_columns(vec![
236+
UInt64Type::from_data(vec![tables_count as u64 - failed_tables.len() as u64]),
237+
UInt64Type::from_data(vec![failed_tables.len() as u64]),
238+
])]),
234239
Some(purge_files) => {
235240
let mut len = min(purge_files.len(), DRY_RUN_LIMIT);
236241
if let Some(limit) = self.plan.option.limit {

src/query/sql/src/planner/plans/ddl/table.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,16 @@ impl VacuumDropTablePlan {
168168
]))
169169
}
170170
} else {
171-
Arc::new(DataSchema::empty())
171+
Arc::new(DataSchema::new(vec![
172+
DataField::new(
173+
"success_tables_count",
174+
DataType::Number(NumberDataType::UInt64),
175+
),
176+
DataField::new(
177+
"failed_tables_count",
178+
DataType::Number(NumberDataType::UInt64),
179+
),
180+
]))
172181
}
173182
}
174183
}

tests/suites/5_ee/01_vacuum/01_003_vacuum_drop_table_continue.result

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
>>>> insert into test_vacuum_drop_table_continue.d values (1)
1313
1
1414
>>>> drop database test_vacuum_drop_table_continue
15-
>>>> set data_retention_time_in_days=0; vacuum drop table
1615
>>>> undrop database test_vacuum_drop_table_continue
1716
>>>> use test_vacuum_drop_table_continue;show tables
1817
a

tests/suites/5_ee/01_vacuum/01_003_vacuum_drop_table_continue.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ chmod 444 /tmp/test_vacuum_drop_table_continue/
2929
stmt "drop database test_vacuum_drop_table_continue"
3030

3131
# can't vacuum files of table a, but can go on vacuum other tables
32-
stmt "set data_retention_time_in_days=0; vacuum drop table"
32+
stmt "set data_retention_time_in_days=0; vacuum drop table" > /dev/null 2>&1
3333

3434
chmod 755 /tmp/test_vacuum_drop_table_continue/
3535
find /tmp/test_vacuum_drop_table_continue/ -type d -exec chmod 755 {} +

tests/suites/5_ee/04_attach_read_only/02_0006_attach_table_ro_issue_16121.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ echo "attach table issue_16121.attach_read_only 's3://testbucket/admin/$storage_
1313
echo "drop table issue_16121.base;" | $BENDSQL_CLIENT_CONNECT
1414

1515
# purge base table data
16-
echo "set data_retention_time_in_days=0;vacuum drop table from issue_16121;" | $BENDSQL_CLIENT_CONNECT
16+
echo "set data_retention_time_in_days=0;vacuum drop table from issue_16121;" | $BENDSQL_CLIENT_CONNECT > /dev/null
1717

1818
echo "expects no error(nothing outputs)"
1919
echo "drop table issue_16121.attach_read_only" | $BENDSQL_CLIENT_CONNECT

tests/suites/5_ee/04_attach_read_only/04_0001_check_mutations.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ echo "VACUUM TABLE test_attach_only.test_json_read_only;" | $BENDSQL_CLIENT_CONN
2525
echo "vacuum drop table from db should not include the read_only attach table"
2626
# drop & vacuum
2727
echo "drop table test_attach_only.test_json_read_only" | $BENDSQL_CLIENT_CONNECT
28-
echo "vacuum drop table from test_attach_only" | $BENDSQL_CLIENT_CONNECT
28+
echo "vacuum drop table from test_attach_only" | $BENDSQL_CLIENT_CONNECT > /dev/null
2929
# attach it back
3030
echo "attach table test_attach_only.test_json_read_only 's3://testbucket/admin/data/$storage_prefix' connection=(access_key_id ='minioadmin' secret_access_key ='minioadmin' endpoint_url='${STORAGE_S3_ENDPOINT_URL}')" | $BENDSQL_CLIENT_CONNECT
3131
echo "expect table data still there"

0 commit comments

Comments
 (0)