From 91e8ead6d133033a65b093886b4baebbbfc93c41 Mon Sep 17 00:00:00 2001 From: Kostas Kyrimis Date: Mon, 25 Sep 2023 11:02:53 +0300 Subject: [PATCH] fix(dragonfly_test): failing bug207 on build opt (#1919) The issue was that the Heartbeat would run every 1ms and this is problematic because the for-loop would take less than 1ms to finish. Therefore, the memory pool would not adjust and items would not be evicted from the store. By doubling the amount of elements created in the for-loop, we give enough time for the first heartbeat to run and adjust the memory available (which will cause the evictions to happen). --- src/server/db_slice.cc | 2 +- src/server/dragonfly_test.cc | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/server/db_slice.cc b/src/server/db_slice.cc index 769ae5ea8..70a12845b 100644 --- a/src/server/db_slice.cc +++ b/src/server/db_slice.cc @@ -152,7 +152,7 @@ bool PrimeEvictionPolicy::CanGrow(const PrimeTable& tbl) const { if (!apply_memory_limit_ || mem_budget_ > soft_limit_) return true; - DCHECK_LT(tbl.size(), tbl.capacity()); + DCHECK_LE(tbl.size(), tbl.capacity()); // We take a conservative stance here - // we estimate how much memory we will take with the current capacity diff --git a/src/server/dragonfly_test.cc b/src/server/dragonfly_test.cc index 0ad66e808..cde768de9 100644 --- a/src/server/dragonfly_test.cc +++ b/src/server/dragonfly_test.cc @@ -382,16 +382,15 @@ TEST_F(DflyEngineTest, OOM) { /// Reproduces the case where items with expiry data were evicted, /// and then written with the same key. TEST_F(DflyEngineTest, Bug207) { + max_memory_limit = 300000; shard_set->TEST_EnableHeartBeat(); shard_set->TEST_EnableCacheMode(); absl::FlagSaver fs; absl::SetFlag(&FLAGS_oom_deny_ratio, 4); - max_memory_limit = 300000; - ssize_t i = 0; RespExpr resp; - for (; i < 5000; ++i) { + for (; i < 10000; ++i) { resp = Run({"setex", StrCat("key", i), "30", "bar"}); // we evict some items because 5000 is too much when max_memory_limit is 300000. ASSERT_EQ(resp, "OK");