From 20ac7384f8ca558f1fb933eda846604792240ea0 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 5 Oct 2021 22:25:53 +0200 Subject: Merged from upstream --- zenserver/cache/structuredcachestore.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'zenserver/cache/structuredcachestore.h') diff --git a/zenserver/cache/structuredcachestore.h b/zenserver/cache/structuredcachestore.h index 011f13323..4753af627 100644 --- a/zenserver/cache/structuredcachestore.h +++ b/zenserver/cache/structuredcachestore.h @@ -46,6 +46,11 @@ struct ZenCacheValue CbObject IndexData; }; +/** In-memory cache storage + + Intended for small values which are frequently accessed + + */ class ZenCacheMemoryLayer { public: @@ -58,19 +63,39 @@ public: void Scrub(ScrubContext& Ctx); void GarbageCollect(GcContext& GcCtx); + struct Configuration + { + uint64_t TargetFootprintBytes = 16 * 1024 * 1024; + uint64_t ScavengeThreshold = 4 * 1024 * 1024; + }; + + const Configuration& GetConfiguration() const { return m_Configuration; } + void SetConfiguration(const Configuration& NewConfig) { m_Configuration = NewConfig; } + private: struct CacheBucket { - RwLock m_bucketLock; - tsl::robin_map m_cacheMap; + struct BucketValue + { + uint64_t LastAccess = 0; + IoBuffer Payload; + }; + + RwLock m_bucketLock; + tsl::robin_map m_cacheMap; bool Get(const IoHash& HashKey, ZenCacheValue& OutValue); void Put(const IoHash& HashKey, const ZenCacheValue& Value); void Scrub(ScrubContext& Ctx); + void GarbageCollect(GcContext& GcCtx); + + private: + uint64_t GetCurrentTimeStamp(); }; RwLock m_Lock; std::unordered_map m_Buckets; + Configuration m_Configuration; }; class ZenCacheDiskLayer @@ -86,6 +111,8 @@ public: void Scrub(ScrubContext& Ctx); void GarbageCollect(GcContext& GcCtx); + void DiscoverBuckets(); + private: /** A cache bucket manages a single directory containing metadata and data for that bucket -- cgit v1.2.3