Skip to content

Commit

Permalink
clear old range before apply snapshot (#4668) (#4715)
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 18e9266 commit 4eac5c3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions dbms/src/Storages/Transaction/ApplySnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,30 @@ 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_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());
}
}
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

0 comments on commit 4eac5c3

Please sign in to comment.