diff options
| author | Per Larsson <[email protected]> | 2021-12-10 15:29:18 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-12-10 15:29:18 +0100 |
| commit | 370d0134a7f755b1e39fbba5c9482ecc9ff3a0fe (patch) | |
| tree | 7329dc070434ccc265be6a7651274366d8c9fc06 /zenserver/cache | |
| parent | Set GC default enabled and interval set to zero (off). (diff) | |
| download | zen-370d0134a7f755b1e39fbba5c9482ecc9ff3a0fe.tar.xz zen-370d0134a7f755b1e39fbba5c9482ecc9ff3a0fe.zip | |
Added size to GcStorage.
Diffstat (limited to 'zenserver/cache')
| -rw-r--r-- | zenserver/cache/structuredcache.cpp | 4 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 24 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.h | 26 |
3 files changed, 24 insertions, 30 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index cf3915363..e74030e07 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -1192,8 +1192,8 @@ HttpStructuredCacheService::HandleStatsRequest(zen::HttpServerRequest& Request) const uint64_t MissCount = m_CacheStats.MissCount; const uint64_t TotalCount = HitCount + MissCount; - const CasStoreSize CasSize = m_CidStore.CasSize(); - const ZenCacheSize CacheSize = m_CacheStore.TotalSize(); + const CasStoreSize CasSize = m_CidStore.CasSize(); + const GcStorageSize CacheSize = m_CacheStore.StorageSize(); Cbo.BeginObject("cache"); Cbo.BeginObject("size"); diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index 64e597d53..f74bb05c1 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -200,10 +200,10 @@ ZenCacheStore::CollectGarbage(GcContext& GcCtx) m_DiskLayer.CollectGarbage(GcCtx); } -ZenCacheSize -ZenCacheStore::TotalSize() const +GcStorageSize +ZenCacheStore::StorageSize() const { - return {.MemorySize = m_MemLayer.TotalSize(), .DiskSize = m_DiskLayer.TotalSize()}; + return {.DiskSize = m_DiskLayer.TotalSize(), .MemorySize = m_MemLayer.TotalSize()}; } ////////////////////////////////////////////////////////////////////////// @@ -472,7 +472,7 @@ struct ZenCacheDiskLayer::CacheBucket void CollectGarbage(GcContext& GcCtx); inline bool IsOk() const { return m_IsOk; } - inline uint64_t TotalSize() const { return m_TotalSize; } + inline uint64_t TotalSize() const { return m_TotalSize.load(std::memory_order::relaxed); } private: std::filesystem::path m_BucketDir; @@ -1544,7 +1544,7 @@ TEST_CASE("zcache.size") const size_t Count = 16; ScopedTemporaryDirectory TempDir; - ZenCacheSize CacheSize; + GcStorageSize CacheSize; { CasGc Gc; @@ -1561,7 +1561,7 @@ TEST_CASE("zcache.size") Zcs.Put("test_bucket-{}"_format(Bucket), IoHash::HashBuffer(&Key, sizeof(uint32_t)), {.Value = Buffer}); } - CacheSize = Zcs.TotalSize(); + CacheSize = Zcs.StorageSize(); CHECK_EQ(CacheValue.GetSize() * Count, CacheSize.DiskSize); CHECK_EQ(CacheValue.GetSize() * Count, CacheSize.MemorySize); } @@ -1570,7 +1570,7 @@ TEST_CASE("zcache.size") CasGc Gc; ZenCacheStore Zcs(Gc, TempDir.Path() / "cache"); - const ZenCacheSize SerializedSize = Zcs.TotalSize(); + const GcStorageSize SerializedSize = Zcs.StorageSize(); CHECK_EQ(SerializedSize.MemorySize, 0); CHECK_EQ(SerializedSize.DiskSize, CacheSize.DiskSize); @@ -1578,7 +1578,7 @@ TEST_CASE("zcache.size") { Zcs.DropBucket("test_bucket-{}"_format(Bucket)); } - CHECK_EQ(0, Zcs.TotalSize().DiskSize); + CHECK_EQ(0, Zcs.StorageSize().DiskSize); } } @@ -1587,7 +1587,7 @@ TEST_CASE("zcache.size") const size_t Count = 16; ScopedTemporaryDirectory TempDir; - ZenCacheSize CacheSize; + GcStorageSize CacheSize; { CasGc Gc; @@ -1604,7 +1604,7 @@ TEST_CASE("zcache.size") Zcs.Put("test_bucket-{}"_format(Bucket), IoHash::HashBuffer(&Key, sizeof(uint32_t)), {.Value = Buffer}); } - CacheSize = Zcs.TotalSize(); + CacheSize = Zcs.StorageSize(); CHECK_EQ(CacheValue.GetSize() * Count, CacheSize.DiskSize); CHECK_EQ(0, CacheSize.MemorySize); } @@ -1613,7 +1613,7 @@ TEST_CASE("zcache.size") CasGc Gc; ZenCacheStore Zcs(Gc, TempDir.Path() / "cache"); - const ZenCacheSize SerializedSize = Zcs.TotalSize(); + const GcStorageSize SerializedSize = Zcs.StorageSize(); CHECK_EQ(SerializedSize.MemorySize, 0); CHECK_EQ(SerializedSize.DiskSize, CacheSize.DiskSize); @@ -1621,7 +1621,7 @@ TEST_CASE("zcache.size") { Zcs.DropBucket("test_bucket-{}"_format(Bucket)); } - CHECK_EQ(0, Zcs.TotalSize().DiskSize); + CHECK_EQ(0, Zcs.StorageSize().DiskSize); } } } diff --git a/zenserver/cache/structuredcachestore.h b/zenserver/cache/structuredcachestore.h index 437d06267..14670f88d 100644 --- a/zenserver/cache/structuredcachestore.h +++ b/zenserver/cache/structuredcachestore.h @@ -143,27 +143,21 @@ private: ZenCacheDiskLayer& operator=(const ZenCacheDiskLayer&) = delete; }; -struct ZenCacheSize -{ - uint64_t MemorySize{}; - uint64_t DiskSize{}; -}; - -class ZenCacheStore : public GcStorage, public GcContributor +class ZenCacheStore final : public GcStorage, public GcContributor { public: ZenCacheStore(CasGc& Gc, const std::filesystem::path& RootDir); ~ZenCacheStore(); - bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); - void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); - bool DropBucket(std::string_view Bucket); - void Flush(); - void Scrub(ScrubContext& Ctx); - virtual void GatherReferences(GcContext& GcCtx) override; - virtual void CollectGarbage(GcContext& GcCtx) override; - ZenCacheSize TotalSize() const; - uint64_t DiskLayerThreshold() const { return m_DiskLayerSizeThreshold; } + bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); + void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); + bool DropBucket(std::string_view Bucket); + void Flush(); + void Scrub(ScrubContext& Ctx); + uint64_t DiskLayerThreshold() const { return m_DiskLayerSizeThreshold; } + virtual void GatherReferences(GcContext& GcCtx) override; + virtual void CollectGarbage(GcContext& GcCtx) override; + virtual GcStorageSize StorageSize() const override; private: std::filesystem::path m_RootDir; |