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

clear old range before apply snapshot #4668

Merged
merged 3 commits into from
Apr 20, 2022
Merged
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
19 changes: 16 additions & 3 deletions dbms/src/Storages/Transaction/ApplySnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,33 @@ void KVStore::onSnapshot(const RegionPtrWrap & new_region_wrap, RegionPtr old_re
// Acquire `drop_lock` so that no other threads can drop the storage. `alter_lock` is not required.
auto table_lock = storage->lockForShare(getThreadName());
auto dm_storage = std::dynamic_pointer_cast<StorageDeltaMerge>(storage);
auto key_range = DM::RowKeyRange::fromRegionRange(
auto new_key_range = DM::RowKeyRange::fromRegionRange(
new_region_wrap->getRange(),
table_id,
storage->isCommonHandle(),
storage->getRowKeyColumnSize());
if (old_region)
{
auto old_key_range = DM::RowKeyRange::fromRegionRange(
old_region->getRange(),
table_id,
storage->isCommonHandle(),
storage->getRowKeyColumnSize());
if (old_key_range != new_key_range)
{
LOG_FMT_INFO(log, "clear region {} old range {} before apply snapshot of new range {}", region_id, old_key_range.toDebugString(), new_key_range.toDebugString());
dm_storage->deleteRange(old_key_range, context.getSettingsRef());
}
}
if constexpr (std::is_same_v<RegionPtrWrap, RegionPtrWithSnapshotFiles>)
{
// Call `ingestFiles` to delete data for range and ingest external DTFiles.
dm_storage->ingestFiles(key_range, new_region_wrap.ingest_ids, /*clear_data_in_range=*/true, context.getSettingsRef());
dm_storage->ingestFiles(new_key_range, new_region_wrap.ingest_ids, /*clear_data_in_range=*/true, context.getSettingsRef());
}
else
{
// Call `deleteRange` to delete data for range
dm_storage->deleteRange(key_range, context.getSettingsRef());
dm_storage->deleteRange(new_key_range, context.getSettingsRef());
}
}
catch (DB::Exception & e)
Expand Down