mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
chore: add db_slice lock to protect segments from preemptions (#3406)
DastTable::Traverse is error prone when the callback passed preempts because the segment might change. This is problematic and we need atomicity while traversing segments with preemption. The fix is to add Traverse in DbSlice and protect the traversal via ThreadLocalMutex. * add ConditionFlag to DbSlice * add Traverse in DbSlice and protect it with the ConditionFlag * remove condition flag from snapshot * remove condition flag from streamer --------- Signed-off-by: kostas <kostas@dragonflydb.io>
This commit is contained in:
parent
f536f8afbd
commit
aa02070e3d
13 changed files with 65 additions and 71 deletions
|
@ -213,9 +213,7 @@ void RestoreStreamer::Run() {
|
|||
return;
|
||||
|
||||
bool written = false;
|
||||
cursor = pt->Traverse(cursor, [&](PrimeTable::bucket_iterator it) {
|
||||
ConditionGuard guard(&bucket_ser_);
|
||||
|
||||
cursor = db_slice_->Traverse(pt, cursor, [&](PrimeTable::bucket_iterator it) {
|
||||
db_slice_->FlushChangeToEarlierCallbacks(0 /*db_id always 0 for cluster*/,
|
||||
DbSlice::Iterator::FromPrime(it), snapshot_version_);
|
||||
if (WriteBucket(it)) {
|
||||
|
@ -313,8 +311,6 @@ bool RestoreStreamer::WriteBucket(PrimeTable::bucket_iterator it) {
|
|||
void RestoreStreamer::OnDbChange(DbIndex db_index, const DbSlice::ChangeReq& req) {
|
||||
DCHECK_EQ(db_index, 0) << "Restore migration only allowed in cluster mode in db0";
|
||||
|
||||
ConditionGuard guard(&bucket_ser_);
|
||||
|
||||
PrimeTable* table = db_slice_->GetTables(0).first;
|
||||
|
||||
if (const PrimeTable::bucket_iterator* bit = req.update()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue