diff options
| author | Dan Engelbrecht <[email protected]> | 2023-10-18 21:53:59 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-18 21:53:59 +0200 |
| commit | 6db4b4d1e023f4c17f12cb0915e0552f21d705f7 (patch) | |
| tree | a380f15a653be4dc273eefaca1599467a7866b6e /src/zenstore/include | |
| parent | 0.2.28 (diff) | |
| download | zen-6db4b4d1e023f4c17f12cb0915e0552f21d705f7.tar.xz zen-6db4b4d1e023f4c17f12cb0915e0552f21d705f7.zip | |
add `flush` command and more gc status info (#483)
- Feature: New endpoint `/admin/flush ` to flush all storage - CAS, Cache and ProjectStore
- Feature: New command `zen flush` to flush all storage - CAS, Cache and ProjectStore
- Improved: Command `zen gc-status` now gives details about storage, when last GC occured, how long until next GC etc
- Changed: Cache access and write log are disabled by default
Diffstat (limited to 'src/zenstore/include')
| -rw-r--r-- | src/zenstore/include/zenstore/gc.h | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/src/zenstore/include/zenstore/gc.h b/src/zenstore/include/zenstore/gc.h index 2e52218f8..aaa156ebf 100644 --- a/src/zenstore/include/zenstore/gc.h +++ b/src/zenstore/include/zenstore/gc.h @@ -7,6 +7,10 @@ #include <zenstore/caslog.h> #include <zenstore/scrubcontext.h> +ZEN_THIRD_PARTY_INCLUDES_START +#include <fmt/format.h> +ZEN_THIRD_PARTY_INCLUDES_END + #include <atomic> #include <chrono> #include <condition_variable> @@ -149,8 +153,8 @@ public: void AddGcStorage(GcStorage* Contributor); void RemoveGcStorage(GcStorage* Contributor); - void CollectGarbage(GcContext& GcCtx); - void ScrubStorage(ScrubContext& GcCtx); + GcStorageSize CollectGarbage(GcContext& GcCtx); + void ScrubStorage(ScrubContext& GcCtx); GcStorageSize TotalStorageSize() const; @@ -189,6 +193,29 @@ struct GcSchedulerConfig std::chrono::seconds LightweightInterval{}; }; +struct GcSchedulerState +{ + GcSchedulerStatus Status; + + GcSchedulerConfig Config; + + bool AreDiskWritesBlocked = false; + bool HasDiskReserve = false; + uint64_t DiskSize = 0; + uint64_t DiskUsed = 0; + uint64_t DiskFree = 0; + GcClock::TimePoint LastFullGcTime{}; + GcClock::TimePoint LastLightweightGcTime{}; + std::chrono::seconds RemainingTimeUntilLightweightGc; + std::chrono::seconds RemainingTimeUntilFullGc; + uint64_t RemainingSpaceUntilFullGC = 0; + + std::chrono::seconds LastFullGcDuration{}; + GcStorageSize LastFullGCDiff; + std::chrono::seconds LastLightweightGcDuration{}; + GcStorageSize LastLightweightGCDiff; +}; + class DiskUsageWindow { public: @@ -221,6 +248,7 @@ public: void Initialize(const GcSchedulerConfig& Config); void Shutdown(); GcSchedulerStatus Status() const { return static_cast<GcSchedulerStatus>(m_Status.load()); } + GcSchedulerState GetState() const; struct TriggerGcParams { @@ -253,15 +281,21 @@ private: virtual bool AreDiskWritesAllowed() const override { return !m_AreDiskWritesBlocked.load(); } DiskSpace CheckDiskSpace(); - spdlog::logger& m_Log; - GcManager& m_GcManager; - GcSchedulerConfig m_Config; - GcClock::TimePoint m_LastGcTime{}; - GcClock::TimePoint m_LastLightweightGcTime{}; - GcClock::TimePoint m_LastGcExpireTime{}; + spdlog::logger& m_Log; + GcManager& m_GcManager; + GcSchedulerConfig m_Config; + GcClock::TimePoint m_LastGcTime{}; + GcClock::TimePoint m_LastLightweightGcTime{}; + GcClock::TimePoint m_LastGcExpireTime{}; + + std::chrono::seconds m_LastFullGcDuration{}; + GcStorageSize m_LastFullGCDiff; + std::chrono::seconds m_LastLightweightGcDuration{}; + GcStorageSize m_LastLightweightGCDiff; + std::atomic_uint32_t m_Status{}; std::thread m_GcThread; - std::mutex m_GcMutex; + mutable std::mutex m_GcMutex; std::condition_variable m_GcSignal; std::optional<TriggerGcParams> m_TriggerGcParams; std::optional<TriggerScrubParams> m_TriggerScrubParams; @@ -274,3 +308,16 @@ private: void gc_forcelink(); } // namespace zen + +template<> +struct fmt::formatter<zen::GcClock::TimePoint> : formatter<string_view> +{ + template<typename FormatContext> + auto format(const zen::GcClock::TimePoint& TimePoint, FormatContext& ctx) + { + std::time_t Time = std::chrono::system_clock::to_time_t(TimePoint); + char TimeString[std::size("yyyy-mm-ddThh:mm:ss")]; + std::strftime(std::data(TimeString), std::size(TimeString), "%FT%T", std::localtime(&Time)); + return fmt::format_to(ctx.out(), "{}", TimeString); + } +}; |