Skip to content

Commit

Permalink
fix: do not crash upon inconsistent expire iterator (#4658)
Browse files Browse the repository at this point in the history
Fixes #4656

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
  • Loading branch information
romange committed Mar 9, 2025
1 parent 21b19e9 commit 0e56a09
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/server/db_slice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1220,17 +1220,24 @@ auto DbSlice::DeleteExpiredStep(const Context& cntx, unsigned count) -> DeleteEx
std::string stash;

auto cb = [&](ExpireIterator it) {
auto key = it->first.GetSlice(&stash);
string_view key = it->first.GetSlice(&stash);
if (!CheckLock(IntentLock::EXCLUSIVE, cntx.db_index, key))
return;

result.traversed++;
time_t ttl = ExpireTime(it) - cntx.time_now_ms;
if (ttl <= 0) {
auto prime_it = db.prime.Find(it->first);
CHECK(!prime_it.is_done());
result.deleted_bytes += prime_it->first.MallocUsed() + prime_it->second.MallocUsed();
ExpireIfNeeded(cntx, prime_it);
if (prime_it.is_done()) { // A workaround for the case our tables are inconsistent.
LOG(DFATAL) << "Expired key " << key << " not found in prime table, expire_done: "
<< it.is_done();
if (!it.is_done()) {
db.expire.Erase(it->first);
}
} else {
result.deleted_bytes += prime_it->first.MallocUsed() + prime_it->second.MallocUsed();
ExpireIfNeeded(cntx, prime_it);
}
++result.deleted;
} else {
result.survivor_ttl_sum += ttl;
Expand Down

0 comments on commit 0e56a09

Please sign in to comment.