Skip to content

Commit

Permalink
fix: properly clear tiered stashes upon expirations
Browse files Browse the repository at this point in the history
Fixes #4387

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange committed Jan 2, 2025
1 parent 7a68528 commit 59a8e1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/server/db_slice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1474,9 +1474,13 @@ void DbSlice::PerformDeletion(Iterator del_it, ExpIterator exp_it, DbTable* tabl
}

DbTableStats& stats = table->stats;
const PrimeValue& pv = del_it->second;
PrimeValue& pv = del_it->second;

if (pv.IsExternal() && shard_owner()->tiered_storage()) {
if (pv.HasStashPending()) {
string scratch;
string_view key = del_it->first.GetSlice(&scratch);
shard_owner()->tiered_storage()->CancelStash(table->index, key, &pv);
} else if (pv.IsExternal()) {
shard_owner()->tiered_storage()->Delete(table->index, &del_it->second);
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/tiered_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ bool TieredStorage::TryStash(DbIndex dbid, string_view key, PrimeValue* value) {
return false;

// This invariant should always hold because ShouldStash tests for IoPending flag.
DCHECK(!bins_->IsPending(dbid, key));
CHECK(!bins_->IsPending(dbid, key));

// TODO: When we are low on memory we should introduce a back-pressure, to avoid OOMs
// with a lot of underutilized disk space.
Expand Down
9 changes: 9 additions & 0 deletions src/server/tiered_storage_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,13 @@ TEST_F(TieredStorageTest, MemoryPressure) {
EXPECT_LT(used_mem_peak.load(), 20_MB);
}

TEST_F(TieredStorageTest, Expiry) {
string val = BuildString(100);
Run({"psetex", "key1", "1", val});
AdvanceTime(10);
Run({"psetex", "key1", "1", val});
auto resp = Run({"get", "key1"});
EXPECT_EQ(resp, val);
}

} // namespace dfly

0 comments on commit 59a8e1d

Please sign in to comment.