From 3d3191017966718fc022547410727428ad0ce16e Mon Sep 17 00:00:00 2001 From: Alexander Sopov Date: Wed, 11 Jun 2025 17:40:10 +0200 Subject: [PATCH 1/4] Skip internal keys' lookup in LRU for the DefaultCache. Relates-To: DATASDK-71 Signed-off-by: sopov --- .../src/cache/DefaultCacheImpl.cpp | 2 +- .../tests/cache/DefaultCacheImplTest.cpp | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp index 1c53c4457..2922d86ab 100644 --- a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp +++ b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp @@ -881,7 +881,7 @@ OperationOutcomeEmpty DefaultCacheImpl::GetFromDiskCache( if (expiry > 0 || protected_keys_.IsProtected(key)) { // Entry didn't expire yet, we can still use it - if (!PromoteKeyLru(key)) { + if (!IsInternalKey(key) && !PromoteKeyLru(key)) { // If not found in LRU or not protected no need to look in disk cache // either. OLP_SDK_LOG_DEBUG_F(kLogTag, diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp index 338489678..8d6d1425b 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp @@ -990,6 +990,38 @@ TEST_F(DefaultCacheImplTest, LruCacheEvictionWithProtected) { } } +TEST_F(DefaultCacheImplTest, InternalKeysBypassLru) { + { + SCOPED_TRACE("Protect and release keys, which suppose to be evicted"); + + const auto internal_key{"internal::protected::protected_data"}; + cache::CacheSettings settings; + settings.disk_path_mutable = cache_path_; + settings.max_disk_storage = 2u * 1024u * 1024u; + { + DefaultCacheImplHelper cache(settings); + ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open()); + cache.Clear(); + const std::string key{"somekey"}; + std::string data_string{"this is key's data"}; + + constexpr auto expiry = 2; + EXPECT_TRUE(cache.Put(key, data_string, + [data_string]() { return data_string; }, expiry)); + ASSERT_TRUE(cache.Protect({key})); + } + + settings.disk_path_mutable = cache_path_; + settings.disk_path_protected.reset(); + + DefaultCacheImplHelper cache(settings); + ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open()); + // no keys was evicted + EXPECT_TRUE(cache.Get(internal_key)); + cache.Clear(); + } +} + TEST_F(DefaultCacheImplTest, ReadOnlyPartitionForProtectedCache) { SCOPED_TRACE("Read only partition protected cache"); const std::string key{"somekey"}; From 10d83950187cedf521f205d7d3193a48c44b796f Mon Sep 17 00:00:00 2001 From: Alexander Sopov Date: Thu, 12 Jun 2025 13:41:27 +0200 Subject: [PATCH 2/4] Skip internal keys' lookup in LRU for the DefaultCache. Add test. Relates-To: DATASDK-71 Signed-off-by: sopov --- .../tests/cache/DefaultCacheImplTest.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp index 8d6d1425b..d5304c2ef 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp @@ -995,29 +995,34 @@ TEST_F(DefaultCacheImplTest, InternalKeysBypassLru) { SCOPED_TRACE("Protect and release keys, which suppose to be evicted"); const auto internal_key{"internal::protected::protected_data"}; + const auto data_string{"this is key's data"}; cache::CacheSettings settings; settings.disk_path_mutable = cache_path_; settings.max_disk_storage = 2u * 1024u * 1024u; { + settings.eviction_policy = cache::EvictionPolicy::kNone; DefaultCacheImplHelper cache(settings); ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open()); cache.Clear(); - const std::string key{"somekey"}; - std::string data_string{"this is key's data"}; constexpr auto expiry = 2; - EXPECT_TRUE(cache.Put(key, data_string, + EXPECT_TRUE(cache.Put(internal_key, data_string, [data_string]() { return data_string; }, expiry)); - ASSERT_TRUE(cache.Protect({key})); } settings.disk_path_mutable = cache_path_; settings.disk_path_protected.reset(); + settings.eviction_policy = cache::EvictionPolicy::kLeastRecentlyUsed; DefaultCacheImplHelper cache(settings); ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open()); // no keys was evicted - EXPECT_TRUE(cache.Get(internal_key)); + auto stored_dats = cache.Get(internal_key); + ASSERT_TRUE(stored_dats); + std::string stored_string( + reinterpret_cast(stored_dats->data()), + stored_dats->size()); + EXPECT_EQ(stored_string, data_string); cache.Clear(); } } From 26e82c525ec8025a799f30ce6a9bc5f0f321b3c4 Mon Sep 17 00:00:00 2001 From: Alexander Sopov Date: Thu, 12 Jun 2025 13:55:09 +0200 Subject: [PATCH 3/4] Skip internal keys' lookup in LRU for the DefaultCache. Add test. Relates-To: DATASDK-71 Signed-off-by: sopov --- olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp index d5304c2ef..09db44a02 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp @@ -998,7 +998,6 @@ TEST_F(DefaultCacheImplTest, InternalKeysBypassLru) { const auto data_string{"this is key's data"}; cache::CacheSettings settings; settings.disk_path_mutable = cache_path_; - settings.max_disk_storage = 2u * 1024u * 1024u; { settings.eviction_policy = cache::EvictionPolicy::kNone; DefaultCacheImplHelper cache(settings); From ad6e5c2162f4f4201f537bfe50a4b23ce209fae6 Mon Sep 17 00:00:00 2001 From: Alexander Sopov Date: Thu, 12 Jun 2025 14:02:13 +0200 Subject: [PATCH 4/4] Skip internal keys' lookup in LRU for the DefaultCache. Add test. Relates-To: DATASDK-71 Signed-off-by: sopov --- olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp index 09db44a02..e78454d87 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp @@ -1015,13 +1015,15 @@ TEST_F(DefaultCacheImplTest, InternalKeysBypassLru) { DefaultCacheImplHelper cache(settings); ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open()); - // no keys was evicted + auto stored_dats = cache.Get(internal_key); ASSERT_TRUE(stored_dats); + std::string stored_string( reinterpret_cast(stored_dats->data()), stored_dats->size()); EXPECT_EQ(stored_string, data_string); + cache.Clear(); } }