Skip to content

Commit

Permalink
issue-1226: fix entry duplication in TLRUCache (#2803)
Browse files Browse the repository at this point in the history
  • Loading branch information
debnatkh authored Jan 7, 2025
1 parent a38b9ab commit d390000
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 0 additions & 1 deletion cloud/storage/core/libs/common/lru_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class TLRUCache: public TMapOps<TLRUCache<TKey, TValue>>
auto it = OrderPositions.find(key);
if (it != OrderPositions.end()) {
OrderList.splice(OrderList.begin(), OrderList, it->second);
it->second = OrderList.insert(OrderList.begin(), key);
} else {
OrderPositions.emplace(
key,
Expand Down
15 changes: 15 additions & 0 deletions cloud/storage/core/libs/common/lru_cache_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ Y_UNIT_TEST_SUITE(TLRUCache)

UNIT_ASSERT_VALUES_EQUAL(1, hashMap.size());
UNIT_ASSERT_VALUES_EQUAL("value1", hashMap.find("key1")->second);

// Test downsizing capacity
hashMap.SetCapacity(0);
hashMap.SetCapacity(3);
hashMap.emplace("key1", "value1");
hashMap.emplace("key2", "value2");
hashMap.emplace("key3", "value3");
hashMap.find("key1");
// Now the order is key1, key3, key2
hashMap.SetCapacity(2);
// Should evict key2
UNIT_ASSERT_EQUAL(hashMap.end(), hashMap.find("key2"));
UNIT_ASSERT_VALUES_EQUAL("value1", hashMap.find("key1")->second);
UNIT_ASSERT_VALUES_EQUAL("value3", hashMap.find("key3")->second);
UNIT_ASSERT_VALUES_EQUAL(2, hashMap.size());
}
}

Expand Down

0 comments on commit d390000

Please sign in to comment.