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 /zenserver/zenserver.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 'zenserver/zenserver.cpp')
| -rw-r--r-- | zenserver/zenserver.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index e9c41d070..b1bcb545f 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -195,6 +195,21 @@ public: .HttpServerClass = std::string(ServerOptions.HttpServerClass), .BuildVersion = std::string(BUILD_VERSION)}); + m_AdminService.RegisterGcHandler({.Trigger = + [this]() { + CbObjectWriter Writer; + const bool Started = m_Gc.Trigger(); + Writer << "Status"sv << (Started ? "Started"sv : "Running"sv); + return Writer.Save(); + }, + .Status = + [this]() { + CbObjectWriter Writer; + const GcStatus Status = m_Gc.Status(); + Writer << "Status"sv << (GcStatus::kIdle == Status ? "Idle"sv : "Running"sv); + return Writer.Save(); + }}); + // Ok so now we're configured, let's kick things off m_Http = zen::CreateHttpServer(ServerOptions.HttpServerClass); @@ -214,11 +229,11 @@ public: m_CasStore->Initialize(Config); m_CidStore = std::make_unique<zen::CidStore>(*m_CasStore, m_DataRoot / "cid"); - m_Gc.SetCidStore(m_CidStore.get()); + m_Gc.Cas().SetCidStore(m_CidStore.get()); ZEN_INFO("instantiating project service"); - m_ProjectStore = new zen::ProjectStore(*m_CidStore, m_DataRoot / "projects", m_Gc); + m_ProjectStore = new zen::ProjectStore(*m_CidStore, m_DataRoot / "projects", m_Gc.Cas()); m_HttpProjectService.reset(new zen::HttpProjectService{*m_CidStore, m_ProjectStore}); #if ZEN_USE_NAMED_PIPES @@ -440,16 +455,6 @@ public: NiceByteRate(Ctx.ScrubbedBytes(), ElapsedTimeMs)); } - void CollectGarbage() - { - Stopwatch Timer; - ZEN_INFO("Garbage collection STARTING"); - - m_Gc.CollectGarbage(); - - ZEN_INFO("Garbage collection DONE after {}", NiceTimeSpanMs(Timer.GetElapsedTimeMs())); - } - void Flush() { if (m_CasStore) @@ -513,8 +518,8 @@ private: zen::Ref<zen::HttpServer> m_Http; zen::HttpStatusService m_StatusService; zen::HttpStatsService m_StatsService; - zen::CasGc m_Gc; - std::unique_ptr<zen::CasStore> m_CasStore{zen::CreateCasStore(m_Gc)}; + zen::Gc m_Gc; + std::unique_ptr<zen::CasStore> m_CasStore{zen::CreateCasStore(m_Gc.Cas())}; std::unique_ptr<zen::CidStore> m_CidStore; std::unique_ptr<zen::ZenCacheStore> m_CacheStore; zen::CasScrubber m_Scrubber{*m_CasStore}; @@ -656,7 +661,7 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions) auto ValueOrDefault = [](std::string_view Value, std::string_view Default) { return Value.empty() ? Default : Value; }; ZEN_INFO("instantiating structured cache service"); - m_CacheStore = std::make_unique<ZenCacheStore>(m_Gc, m_DataRoot / "cache"); + m_CacheStore = std::make_unique<ZenCacheStore>(m_Gc.Cas(), m_DataRoot / "cache"); std::unique_ptr<zen::UpstreamCache> UpstreamCache; if (ServerOptions.UpstreamCacheConfig.CachePolicy != UpstreamCachePolicy::Disabled) |