diff options
| author | Per Larsson <[email protected]> | 2021-11-29 12:55:08 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-11-29 12:55:08 +0100 |
| commit | 9a8e2c8d905bc1e5b62c6f5e246d2574a645b73e (patch) | |
| tree | fb6cd0492812dd8ea99ba3dde27cc2b49dd978dc /zenstore/gc.cpp | |
| parent | Merged main. (diff) | |
| download | zen-9a8e2c8d905bc1e5b62c6f5e246d2574a645b73e.tar.xz zen-9a8e2c8d905bc1e5b62c6f5e246d2574a645b73e.zip | |
Moved GC to background thread and added endpoint to trigger/status GC.
Diffstat (limited to 'zenstore/gc.cpp')
| -rw-r--r-- | zenstore/gc.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp index 278f09b0b..52bb33955 100644 --- a/zenstore/gc.cpp +++ b/zenstore/gc.cpp @@ -2,9 +2,11 @@ #include <zenstore/gc.h> +#include <zencore/logging.h> +#include <zencore/string.h> +#include <zencore/timer.h> #include <zenstore/CAS.h> #include <zenstore/cidstore.h> -#include <zencore/logging.h> namespace zen { @@ -202,4 +204,28 @@ CasGc::OnDroppedCidReferences(std::span<IoHash> Hashes) ZEN_UNUSED(Hashes); } +bool +Gc::Trigger() +{ + uint32_t Expected = uint32_t(GcStatus::kIdle); + if (!m_Status.compare_exchange_strong(Expected, static_cast<uint32_t>(GcStatus::kRunning))) + { + return false; + } + + ZEN_ASSERT(GcStatus::kRunning == Status()); + + m_GcThread = std::jthread([this]() { + Stopwatch Timer; + ZEN_INFO("garbage collection STARTING"); + + m_CasGc.CollectGarbage(); + m_Status = static_cast<uint32_t>(GcStatus::kIdle); + + ZEN_INFO("garbage collection DONE after {}", NiceTimeSpanMs(Timer.GetElapsedTimeMs())); + }); + + return true; +} + } // namespace zen |