diff options
| author | Per Larsson <[email protected]> | 2021-11-29 19:13:18 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-11-29 19:13:18 +0100 |
| commit | 9b67ea0f16aad9345afafeef7ef406eafc51447f (patch) | |
| tree | 4a630493ae2bb1b62db3cc1468b4f46216eb137a /zenserver/cache/structuredcachestore.h | |
| parent | Moved GC to background thread and added endpoint to trigger/status GC. (diff) | |
| download | zen-9b67ea0f16aad9345afafeef7ef406eafc51447f.tar.xz zen-9b67ea0f16aad9345afafeef7ef406eafc51447f.zip | |
Added z$ memory/disk layer size.
Diffstat (limited to 'zenserver/cache/structuredcachestore.h')
| -rw-r--r-- | zenserver/cache/structuredcachestore.h | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/zenserver/cache/structuredcachestore.h b/zenserver/cache/structuredcachestore.h index 8e1260b52..d3c2227ac 100644 --- a/zenserver/cache/structuredcachestore.h +++ b/zenserver/cache/structuredcachestore.h @@ -16,6 +16,7 @@ ZEN_THIRD_PARTY_INCLUDES_START #include <tsl/robin_map.h> ZEN_THIRD_PARTY_INCLUDES_END +#include <atomic> #include <compare> #include <filesystem> #include <unordered_map> @@ -64,11 +65,12 @@ public: ZenCacheMemoryLayer(); ~ZenCacheMemoryLayer(); - 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 Scrub(ScrubContext& Ctx); - void GatherReferences(GcContext& GcCtx); + 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 Scrub(ScrubContext& Ctx); + void GatherReferences(GcContext& GcCtx); + uint64_t TotalSize() const; struct Configuration { @@ -91,16 +93,18 @@ private: RwLock m_bucketLock; tsl::robin_map<IoHash, BucketValue> m_cacheMap; - bool Get(const IoHash& HashKey, ZenCacheValue& OutValue); - void Put(const IoHash& HashKey, const ZenCacheValue& Value); - void Scrub(ScrubContext& Ctx); - void GatherReferences(GcContext& GcCtx); + bool Get(const IoHash& HashKey, ZenCacheValue& OutValue); + void Put(const IoHash& HashKey, const ZenCacheValue& Value); + void Scrub(ScrubContext& Ctx); + void GatherReferences(GcContext& GcCtx); + inline uint64_t TotalSize() const { return m_TotalSize; } private: - uint64_t GetCurrentTimeStamp(); + uint64_t GetCurrentTimeStamp(); + std::atomic_uint64_t m_TotalSize{}; }; - RwLock m_Lock; + mutable RwLock m_Lock; std::unordered_map<std::string, CacheBucket> m_Buckets; Configuration m_Configuration; @@ -121,7 +125,8 @@ public: void Scrub(ScrubContext& Ctx); void GatherReferences(GcContext& GcCtx); - void DiscoverBuckets(); + void DiscoverBuckets(); + uint64_t TotalSize() const; private: /** A cache bucket manages a single directory containing @@ -130,13 +135,19 @@ private: struct CacheBucket; std::filesystem::path m_RootDir; - RwLock m_Lock; + mutable RwLock m_Lock; std::unordered_map<std::string, CacheBucket> m_Buckets; // TODO: make this case insensitive ZenCacheDiskLayer(const ZenCacheDiskLayer&) = delete; ZenCacheDiskLayer& operator=(const ZenCacheDiskLayer&) = delete; }; +struct ZenCacheSize +{ + uint64_t MemorySize{}; + uint64_t DiskSize{}; +}; + class ZenCacheStore : public GcContributor { public: @@ -149,6 +160,8 @@ public: void Flush(); void Scrub(ScrubContext& Ctx); virtual void GatherReferences(GcContext& GcCtx) override; + ZenCacheSize TotalSize() const; + uint64_t DiskLayerThreshold() const { return m_DiskLayerSizeThreshold; } private: std::filesystem::path m_RootDir; |