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/zenserver/admin/admin.cpp | |
| 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/zenserver/admin/admin.cpp')
| -rw-r--r-- | src/zenserver/admin/admin.cpp | 127 |
1 files changed, 103 insertions, 24 deletions
diff --git a/src/zenserver/admin/admin.cpp b/src/zenserver/admin/admin.cpp index 60599a992..5313a7592 100644 --- a/src/zenserver/admin/admin.cpp +++ b/src/zenserver/admin/admin.cpp @@ -3,8 +3,10 @@ #include "admin.h" #include <zencore/compactbinarybuilder.h> +#include <zencore/fmtutils.h> #include <zencore/jobqueue.h> #include <zencore/string.h> + #if ZEN_WITH_TRACE # include <zencore/trace.h> #endif // ZEN_WITH_TRACE @@ -13,8 +15,11 @@ # include <mimalloc.h> #endif +#include <zenstore/cidstore.h> #include <zenstore/gc.h> + #include "cache/structuredcachestore.h" +#include "projectstore/projectstore.h" #include <chrono> @@ -26,11 +31,15 @@ namespace zen { HttpAdminService::HttpAdminService(GcScheduler& Scheduler, JobQueue& BackgroundJobQueue, - ZenCacheStore& CacheStore, + ZenCacheStore* CacheStore, + CidStore* CidStore, + ProjectStore* ProjectStore, const LogPaths& LogPaths) : m_GcScheduler(Scheduler) , m_BackgroundJobQueue(BackgroundJobQueue) , m_CacheStore(CacheStore) +, m_CidStore(CidStore) +, m_ProjectStore(ProjectStore) , m_LogPaths(LogPaths) { using namespace std::literals; @@ -188,10 +197,57 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler, m_Router.RegisterRoute( "gc", [this](HttpRouterRequest& Req) { - const GcSchedulerStatus Status = m_GcScheduler.Status(); + const GcSchedulerState State = m_GcScheduler.GetState(); + + auto SecondsToString = [](std::chrono::seconds Secs) { + return NiceTimeSpanMs(uint64_t(std::chrono::milliseconds(Secs).count())); + }; CbObjectWriter Response; - Response << "Status"sv << (GcSchedulerStatus::kIdle == Status ? "Idle"sv : "Running"sv); + Response << "Status"sv << (GcSchedulerStatus::kIdle == State.Status ? "Idle"sv : "Running"sv); + Response.BeginObject("Config"); + { + Response << "RootDirectory" << State.Config.RootDirectory.string(); + Response << "MonitorInterval" << SecondsToString(State.Config.MonitorInterval); + Response << "Interval" << SecondsToString(State.Config.Interval); + Response << "MaxCacheDuration" << SecondsToString(State.Config.MaxCacheDuration); + Response << "MaxProjectStoreDuration" << SecondsToString(State.Config.MaxProjectStoreDuration); + Response << "CollectSmallObjects" << State.Config.CollectSmallObjects; + Response << "Enabled" << State.Config.Enabled; + Response << "DiskReserveSize" << NiceBytes(State.Config.DiskReserveSize); + Response << "DiskSizeSoftLimit" << NiceBytes(State.Config.DiskSizeSoftLimit); + Response << "MinimumFreeDiskSpaceToAllowWrites" << NiceBytes(State.Config.MinimumFreeDiskSpaceToAllowWrites); + Response << "LightweightInterval" << SecondsToString(State.Config.LightweightInterval); + } + Response.EndObject(); + Response << "AreDiskWritesBlocked" << State.AreDiskWritesBlocked; + Response << "HasDiskReserve" << State.HasDiskReserve; + Response << "DiskSize" << NiceBytes(State.DiskSize); + Response << "DiskUsed" << NiceBytes(State.DiskUsed); + Response << "DiskFree" << NiceBytes(State.DiskFree); + + Response.BeginObject("FullGC"); + { + Response << "LastTime" << fmt::format("{}", State.LastFullGcTime); + Response << "TimeToNext" << SecondsToString(State.RemainingTimeUntilFullGc); + if (State.Config.DiskSizeSoftLimit != 0) + { + Response << "SpaceToNext" << NiceBytes(State.RemainingSpaceUntilFullGC); + } + Response << "LastDuration" << SecondsToString(State.LastFullGcDuration); + Response << "LastDiskFreed" << NiceBytes(State.LastFullGCDiff.DiskSize); + Response << "LastMemoryFreed" << NiceBytes(State.LastFullGCDiff.MemorySize); + } + Response.EndObject(); + Response.BeginObject("LightweightGC"); + { + Response << "LastTime" << fmt::format("{}", State.LastLightweightGcTime); + Response << "TimeToNext" << SecondsToString(State.RemainingTimeUntilLightweightGc); + Response << "LastDuration" << SecondsToString(State.LastLightweightGcDuration); + Response << "LastDiskFreed" << NiceBytes(State.LastLightweightGCDiff.DiskSize); + Response << "LastMemoryFreed" << NiceBytes(State.LastLightweightGCDiff.MemorySize); + } + Response.EndObject(); Req.ServerRequest().WriteResponse(HttpResponseCode::OK, Response.Save()); }, HttpVerb::kGet); @@ -379,8 +435,9 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler, Obj.AddString("loglevel", std::string_view(LogLevel.data(), LogLevel.size())); Obj.AddString("Logfile", PathToUtf8(m_LogPaths.AbsLogPath)); Obj.BeginObject("cache"); + if (m_CacheStore) { - const ZenCacheStore::Configuration& CacheConfig = m_CacheStore.GetConfiguration(); + const ZenCacheStore::Configuration& CacheConfig = m_CacheStore->GetConfiguration(); Obj.AddString("Logfile", PathToUtf8(m_LogPaths.CacheLogPath)); Obj.AddBool("Write", CacheConfig.Logging.EnableWriteLog); Obj.AddBool("Access", CacheConfig.Logging.EnableAccessLog); @@ -398,27 +455,30 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler, m_Router.RegisterRoute( "logs", [this](HttpRouterRequest& Req) { - HttpServerRequest& HttpReq = Req.ServerRequest(); - const HttpServerRequest::QueryParams Params = HttpReq.GetQueryParams(); - bool SetCacheLogConfig = false; - ExtendableStringBuilder<256> StringBuilder; - ZenCacheStore::Configuration::LogConfig LoggingConfig = m_CacheStore.GetConfiguration().Logging; - if (std::string Param(Params.GetValue("cacheenablewritelog")); Param.empty() == false) - { - LoggingConfig.EnableWriteLog = StrCaseCompare(Param.c_str(), "true") == 0; - SetCacheLogConfig = true; - } - if (std::string Param(Params.GetValue("cacheenableaccesslog")); Param.empty() == false) - { - LoggingConfig.EnableAccessLog = StrCaseCompare(Param.c_str(), "true") == 0; - SetCacheLogConfig = true; - } - if (SetCacheLogConfig) + HttpServerRequest& HttpReq = Req.ServerRequest(); + const HttpServerRequest::QueryParams Params = HttpReq.GetQueryParams(); + bool SetCacheLogConfig = false; + ExtendableStringBuilder<256> StringBuilder; + if (m_CacheStore) { - m_CacheStore.SetLoggingConfig(LoggingConfig); - StringBuilder.Append(fmt::format("cache write log: {}, cache access log: {}", - LoggingConfig.EnableWriteLog ? "true" : "false", - LoggingConfig.EnableAccessLog ? "true" : "false")); + ZenCacheStore::Configuration::LogConfig LoggingConfig = m_CacheStore->GetConfiguration().Logging; + if (std::string Param(Params.GetValue("cacheenablewritelog")); Param.empty() == false) + { + LoggingConfig.EnableWriteLog = StrCaseCompare(Param.c_str(), "true") == 0; + SetCacheLogConfig = true; + } + if (std::string Param(Params.GetValue("cacheenableaccesslog")); Param.empty() == false) + { + LoggingConfig.EnableAccessLog = StrCaseCompare(Param.c_str(), "true") == 0; + SetCacheLogConfig = true; + } + if (SetCacheLogConfig) + { + m_CacheStore->SetLoggingConfig(LoggingConfig); + StringBuilder.Append(fmt::format("cache write log: {}, cache access log: {}", + LoggingConfig.EnableWriteLog ? "true" : "false", + LoggingConfig.EnableAccessLog ? "true" : "false")); + } } if (std::string Param(Params.GetValue("loglevel")); Param.empty() == false) { @@ -441,6 +501,25 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler, return Req.ServerRequest().WriteResponse(HttpResponseCode::OK, HttpContentType::kText, StringBuilder.ToView()); }, HttpVerb::kPost); + m_Router.RegisterRoute( + "flush", + [this](HttpRouterRequest& Req) { + HttpServerRequest& HttpReq = Req.ServerRequest(); + if (m_CidStore) + { + m_CidStore->Flush(); + } + if (m_CacheStore) + { + m_CacheStore->Flush(); + } + if (m_ProjectStore) + { + m_ProjectStore->Flush(); + } + HttpReq.WriteResponse(HttpResponseCode::OK); + }, + HttpVerb::kPost); } HttpAdminService::~HttpAdminService() |