Skip to content

Commit

Permalink
properly clean up thread local
Browse files Browse the repository at this point in the history
  • Loading branch information
kostasrim committed Nov 14, 2024
1 parent c04f96d commit 7b50a5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/server/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ ThreadLocalMutex::ThreadLocalMutex() {
}

ThreadLocalMutex::~ThreadLocalMutex() {
// DCHECK_EQ(EngineShard::tlocal(), shard_);
DCHECK_EQ(EngineShard::tlocal(), shard_);
}

void ThreadLocalMutex::lock() {
Expand Down
11 changes: 5 additions & 6 deletions src/server/db_slice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ unsigned PrimeEvictionPolicy::Evict(const PrimeTable::HotspotBuckets& eb, PrimeT
if (auto journal = db_slice_->shard_owner()->journal(); journal) {
RecordExpiry(cntx_.db_index, key);
}
// Safe we already acquired util::fb2::LockGuard lk(db_slice_->GetSerializationMutex());
// on the flows that call this function
db_slice_->PerformDeletion(DbSlice::Iterator(last_slot_it, StringOrView::FromView(key)), table);

++evicted_;
Expand Down Expand Up @@ -1131,6 +1129,11 @@ DbSlice::PrimeItAndExp DbSlice::ExpireIfNeeded(const Context& cntx, PrimeIterato
<< ", prime table size: " << db->prime.size() << util::fb2::GetStacktrace();
}

// Replicate expiry
if (auto journal = owner_->journal(); journal) {
RecordExpiry(cntx.db_index, key);
}

if (expired_keys_events_recording_)
db->expired_keys_events_.emplace_back(key);

Expand All @@ -1142,10 +1145,6 @@ DbSlice::PrimeItAndExp DbSlice::ExpireIfNeeded(const Context& cntx, PrimeIterato
const_cast<DbSlice*>(this)->PerformDeletion(Iterator(it, StringOrView::FromView(key)),
ExpIterator(expire_it, StringOrView::FromView(key)),
db.get());
// Replicate expiry
if (auto journal = owner_->journal(); journal) {
RecordExpiry(cntx.db_index, key);
}

++events_.expired_keys;

Expand Down
10 changes: 6 additions & 4 deletions src/server/dflycmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ OpStatus DflyCmd::StartFullSyncInThread(FlowInfo* flow, Context* cntx, EngineSha
void DflyCmd::StopFullSyncInThread(FlowInfo* flow, Context* cntx, EngineShard* shard) {
DCHECK(shard);

absl::Cleanup clean([&]() {
// Reset cleanup and saver
flow->cleanup = []() {};
flow->saver.reset();
});

error_code ec = flow->saver->StopFullSyncInShard(shard);
if (ec) {
cntx->ReportError(ec);
Expand All @@ -600,10 +606,6 @@ void DflyCmd::StopFullSyncInThread(FlowInfo* flow, Context* cntx, EngineShard* s
cntx->ReportError(ec);
return;
}

// Reset cleanup and saver
flow->cleanup = []() {};
flow->saver.reset();
}

void DflyCmd::StartStableSyncInThread(FlowInfo* flow, Context* cntx, EngineShard* shard) {
Expand Down

0 comments on commit 7b50a5d

Please sign in to comment.