From 68a72b68592c416969bd36f413eb2b2762b9fcff Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Tue, 3 Oct 2023 13:31:02 +0200 Subject: faster accesstime save restore (#439) - Improvement: Reduce time a cache bucket is locked for write when flushing/garbage collecting - Change format for faster read/write and reduced size on disk - Don't lock index while writing manifest to disk - Skip garbage collect if we are currently in a Flush operation - BlockStore::Flush no longer terminates currently writing block - Garbage collect references to currently writing block but keep the block as new data may be added - Fix BlockStore::Prune used disk space calculation - Don't materialize data in filecas when we just need the size --- src/zenserver/cache/structuredcachestore.cpp | 62 +++++++++++++++------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'src/zenserver/cache/structuredcachestore.cpp') diff --git a/src/zenserver/cache/structuredcachestore.cpp b/src/zenserver/cache/structuredcachestore.cpp index 0a2947b16..1b6eeca3a 100644 --- a/src/zenserver/cache/structuredcachestore.cpp +++ b/src/zenserver/cache/structuredcachestore.cpp @@ -1030,46 +1030,50 @@ TEST_CASE("z$.gc") { ScopedTemporaryDirectory TempDir; GcManager Gc; - ZenCacheNamespace Zcs(Gc, *JobQueue, TempDir.Path() / "cache"); - const auto Bucket = "rightintwo"sv; - - std::vector Keys{CreateKey(1), CreateKey(2), CreateKey(3)}; - - for (const auto& Key : Keys) { - IoBuffer Value = testutils::CreateBinaryCacheValue(128); - Zcs.Put(Bucket, Key, {.Value = Value}); - } - - { - GcContext GcCtx(GcClock::Now() - std::chrono::hours(2), GcClock::Now() - std::chrono::hours(2)); - GcCtx.CollectSmallObjects(true); + ZenCacheNamespace Zcs(Gc, *JobQueue, TempDir.Path() / "cache"); + const auto Bucket = "rightintwo"sv; - Gc.CollectGarbage(GcCtx); + std::vector Keys{CreateKey(1), CreateKey(2), CreateKey(3)}; for (const auto& Key : Keys) { - ZenCacheValue CacheValue; - const bool Exists = Zcs.Get(Bucket, Key, CacheValue); - CHECK(Exists); + IoBuffer Value = testutils::CreateBinaryCacheValue(128); + Zcs.Put(Bucket, Key, {.Value = Value}); } - } - // Move forward in time and collect again - { - GcContext GcCtx(GcClock::Now() + std::chrono::minutes(2), GcClock::Now() + std::chrono::minutes(2)); - GcCtx.CollectSmallObjects(true); + { + GcContext GcCtx(GcClock::Now() - std::chrono::hours(2), GcClock::Now() - std::chrono::hours(2)); + GcCtx.CollectSmallObjects(true); - Zcs.Flush(); - Gc.CollectGarbage(GcCtx); + Gc.CollectGarbage(GcCtx); - for (const auto& Key : Keys) - { - ZenCacheValue CacheValue; - const bool Exists = Zcs.Get(Bucket, Key, CacheValue); - CHECK(!Exists); + for (const auto& Key : Keys) + { + ZenCacheValue CacheValue; + const bool Exists = Zcs.Get(Bucket, Key, CacheValue); + CHECK(Exists); + } } + // Move forward in time and collect again + { + GcContext GcCtx(GcClock::Now() + std::chrono::minutes(2), GcClock::Now() + std::chrono::minutes(2)); + GcCtx.CollectSmallObjects(true); + + Zcs.Flush(); + Gc.CollectGarbage(GcCtx); + + for (const auto& Key : Keys) + { + ZenCacheValue CacheValue; + const bool Exists = Zcs.Get(Bucket, Key, CacheValue); + CHECK(!Exists); + } + } + } + { + ZenCacheNamespace Zcs(Gc, *JobQueue, TempDir.Path() / "cache"); CHECK_EQ(0, Zcs.StorageSize().DiskSize); } } -- cgit v1.2.3