Skip to content

Commit

Permalink
clear old range before apply snapshot (#4668) (#4720)
Browse files Browse the repository at this point in the history
close #4414
  • Loading branch information
ti-chi-bot authored Jun 2, 2022
1 parent 94609a6 commit 8c0492f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions dbms/src/Storages/Transaction/ApplySnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,22 @@ void KVStore::onSnapshot(const RegionPtrWithBlock & new_region_wrap, RegionPtr o
// 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_INFO(log,
"clear region " << region_id << " old range " << old_key_range.toDebugString()
<< " before apply snapshot of new range " << new_key_range.toDebugString());
dm_storage->deleteRange(old_key_range, context.getSettingsRef());
}
}
// 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

0 comments on commit 8c0492f

Please sign in to comment.