Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(meta): batch delete time travel metadata (#20169) #20184

Open
wants to merge 1 commit into
base: release-2.1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/meta/src/hummock/manager/time_travel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ impl HummockManager {
);
}
let mut next_version_sst_ids = latest_valid_version_sst_ids;
let mut sst_ids_to_delete: HashSet<_> = HashSet::default();
for prev_version_id in version_ids_to_delete {
let prev_version = {
let prev_version = hummock_time_travel_version::Entity::find_by_id(prev_version_id)
Expand All @@ -188,20 +189,41 @@ impl HummockManager {
};
let sst_ids = prev_version.get_sst_ids();
// The SST ids deleted by compaction between the 2 versions.
let sst_ids_to_delete = &sst_ids - &next_version_sst_ids;
sst_ids_to_delete.extend(&sst_ids - &next_version_sst_ids);
// Reuse hummock_time_travel_epoch_version_insert_batch_size as threshold.
if sst_ids_to_delete.len()
>= self
.env
.opts
.hummock_time_travel_epoch_version_insert_batch_size
{
let res = hummock_sstable_info::Entity::delete_many()
.filter(
hummock_sstable_info::Column::SstId
.is_in(std::mem::take(&mut sst_ids_to_delete)),
)
.exec(&txn)
.await?;
tracing::debug!(
"delete {} rows from hummock_sstable_info",
res.rows_affected
);
}
let new_object_ids = prev_version.get_object_ids();
object_ids_to_delete.extend(&new_object_ids - &latest_valid_version_object_ids);
next_version_sst_ids = sst_ids;
}
if !sst_ids_to_delete.is_empty() {
let res = hummock_sstable_info::Entity::delete_many()
.filter(hummock_sstable_info::Column::SstId.is_in(sst_ids_to_delete))
.exec(&txn)
.await?;
let new_object_ids = prev_version.get_object_ids();
object_ids_to_delete.extend(&new_object_ids - &latest_valid_version_object_ids);
tracing::debug!(
prev_version_id,
"delete {} rows from hummock_sstable_info",
res.rows_affected
);
next_version_sst_ids = sst_ids;
}

if !object_ids_to_delete.is_empty() {
// IMPORTANT: object_ids_to_delete may include objects that are still being used by SSTs not included in time travel metadata.
// So it's crucial to filter out those objects before actually deleting them, i.e. when using `try_take_may_delete_object_ids`.
Expand Down