diff options
| author | Per Larsson <[email protected]> | 2021-12-12 12:04:31 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-12-12 12:04:31 +0100 |
| commit | a40133fe893100631f9bb8cd68fb7c2edbab0759 (patch) | |
| tree | 80cdcb8af8fad50d1004116671a655ec4495d729 /zenstore/include | |
| parent | Added size to GcStorage. (diff) | |
| download | zen-a40133fe893100631f9bb8cd68fb7c2edbab0759.tar.xz zen-a40133fe893100631f9bb8cd68fb7c2edbab0759.zip | |
Added support for triggering GC with different params and refactored GC scheduler.
Diffstat (limited to 'zenstore/include')
| -rw-r--r-- | zenstore/include/zenstore/gc.h | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/zenstore/include/zenstore/gc.h b/zenstore/include/zenstore/gc.h index 2ea35b131..20aada746 100644 --- a/zenstore/include/zenstore/gc.h +++ b/zenstore/include/zenstore/gc.h @@ -9,6 +9,7 @@ #include <chrono> #include <filesystem> #include <functional> +#include <optional> #include <span> #include <thread> @@ -42,7 +43,6 @@ public: /** Garbage Collection context object */ - class GcContext { public: @@ -83,7 +83,6 @@ private: retain. */ - class GcContributor { public: @@ -119,7 +118,6 @@ private: /** GC orchestrator */ - class CasGc { public: @@ -134,13 +132,14 @@ public: void CollectGarbage(GcContext& GcCtx); - void SetCidStore(CidStore* Cids); - void OnNewCidReferences(std::span<IoHash> Hashes); - void OnCommittedCidReferences(std::span<IoHash> Hashes); - void OnDroppedCidReferences(std::span<IoHash> Hashes); + void SetCidStore(CidStore* Cids); + void OnNewCidReferences(std::span<IoHash> Hashes); + void OnCommittedCidReferences(std::span<IoHash> Hashes); + void OnDroppedCidReferences(std::span<IoHash> Hashes); + GcStorageSize TotalStorageSize() const; private: - RwLock m_Lock; + mutable RwLock m_Lock; std::vector<GcContributor*> m_GcContribs; std::vector<GcStorage*> m_GcStorage; CidStore* m_CidStore; @@ -156,12 +155,16 @@ enum class GcSchedulerStatus : uint32_t struct GcSchedulerConfig { std::filesystem::path RootDirectory; + std::chrono::seconds MonitorInterval{30}; std::chrono::seconds Interval{}; std::chrono::seconds MaxCacheDuration{86400}; bool CollectSmallObjects = false; bool Enabled = false; }; +/** + * GC scheduler + */ class GcScheduler { public: @@ -169,23 +172,32 @@ public: ~GcScheduler(); void Initialize(const GcSchedulerConfig& Config); - bool ScheduleNow(); - GcSchedulerStatus Status() const { return static_cast<GcSchedulerStatus>(m_Status.load()); } void Shutdown(); + GcSchedulerStatus Status() const { return static_cast<GcSchedulerStatus>(m_Status.load()); } + + struct TriggerParams + { + bool CollectSmallObjects = false; + std::chrono::seconds MaxCacheDuration = std::chrono::seconds::max(); + }; + + bool Trigger(const TriggerParams& Params); private: void SchedulerThread(); GcClock::TimePoint NextGcTime(GcClock::TimePoint CurrentTime); spdlog::logger& Log() { return m_Log; } - spdlog::logger& m_Log; - CasGc& m_CasGc; - GcSchedulerConfig m_Config; - GcClock::TimePoint m_NextGcTime{}; - std::atomic_uint32_t m_Status{}; - std::jthread m_GcThread; - std::mutex m_GcMutex; - std::condition_variable m_GcSignal; + spdlog::logger& m_Log; + CasGc& m_CasGc; + GcSchedulerConfig m_Config; + GcClock::TimePoint m_LastGcTime{}; + GcClock::TimePoint m_NextGcTime{}; + std::atomic_uint32_t m_Status{}; + std::jthread m_GcThread; + std::mutex m_GcMutex; + std::condition_variable m_GcSignal; + std::optional<TriggerParams> m_TriggerParams; }; } // namespace zen |