diff options
Diffstat (limited to 'src/zenserver/cache/cachememorylayer.h')
| -rw-r--r-- | src/zenserver/cache/cachememorylayer.h | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/zenserver/cache/cachememorylayer.h b/src/zenserver/cache/cachememorylayer.h index 0ef0c905f..f15fe241b 100644 --- a/src/zenserver/cache/cachememorylayer.h +++ b/src/zenserver/cache/cachememorylayer.h @@ -19,6 +19,8 @@ ZEN_THIRD_PARTY_INCLUDES_END namespace zen { +class JobQueue; + /** In-memory cache storage Intended for small values which are frequently accessed @@ -31,8 +33,9 @@ class ZenCacheMemoryLayer public: struct Configuration { - uint64_t TargetFootprintBytes = 16 * 1024 * 1024; - uint64_t ScavengeThreshold = 4 * 1024 * 1024; + uint64_t TargetFootprintBytes = 512 * 1024 * 1024; + uint64_t TrimIntervalSeconds = 60; + uint64_t MaxAgeSeconds = gsl::narrow<uint64_t>(std::chrono::seconds(std::chrono::days(1)).count()); }; struct BucketInfo @@ -49,16 +52,16 @@ public: uint64_t TotalSize = 0; }; - ZenCacheMemoryLayer(); + ZenCacheMemoryLayer(JobQueue& JobQueue, const Configuration& Config); ~ZenCacheMemoryLayer(); bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); + uint64_t CollectGarbage(GcClock::TimePoint ExpireTime); void Drop(); bool DropBucket(std::string_view Bucket); void ScrubStorage(ScrubContext& Ctx); void GatherAccessTimes(zen::access_tracking::AccessTimes& AccessTimes); - void Reset(); uint64_t TotalSize() const; Info GetInfo() const; @@ -68,6 +71,8 @@ public: void SetConfiguration(const Configuration& NewConfig) { m_Configuration = NewConfig; } private: + void Trim(); + struct CacheBucket { #pragma pack(push) @@ -93,21 +98,27 @@ private: std::atomic_uint64_t m_TotalSize{}; bool Get(const IoHash& HashKey, ZenCacheValue& OutValue); - void Put(const IoHash& HashKey, const ZenCacheValue& Value); + int64_t Put(const IoHash& HashKey, const ZenCacheValue& Value); + uint64_t Trim(GcClock::TimePoint ExpireTime); void Drop(); void ScrubStorage(ScrubContext& Ctx); void GatherAccessTimes(std::vector<zen::access_tracking::KeyAccessTime>& AccessTimes); inline uint64_t TotalSize() const { return m_TotalSize; } uint64_t EntryCount() const; + void GetUsageByAccess(GcClock::TimePoint TickStart, GcClock::Duration SectionLength, std::vector<uint64_t>& InOutUsageSlots); }; + JobQueue& m_JobQueue; mutable RwLock m_Lock; std::unordered_map<std::string, std::unique_ptr<CacheBucket>> m_Buckets; std::vector<std::unique_ptr<CacheBucket>> m_DroppedBuckets; Configuration m_Configuration; + std::atomic_uint64_t m_TotalSize{}; + std::atomic_bool m_IsTrimming = false; + std::atomic<GcClock::Tick> m_LastTickTrim; ZenCacheMemoryLayer(const ZenCacheMemoryLayer&) = delete; ZenCacheMemoryLayer& operator=(const ZenCacheMemoryLayer&) = delete; }; -} // namespace zen
\ No newline at end of file +} // namespace zen |