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/zen/cmds/admin_cmd.cpp | |
| parent | 0.2.28 (diff) | |
| download | archived-zen-6db4b4d1e023f4c17f12cb0915e0552f21d705f7.tar.xz archived-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/zen/cmds/admin_cmd.cpp')
| -rw-r--r-- | src/zen/cmds/admin_cmd.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/zen/cmds/admin_cmd.cpp b/src/zen/cmds/admin_cmd.cpp index 9d8348b43..9713d8c87 100644 --- a/src/zen/cmds/admin_cmd.cpp +++ b/src/zen/cmds/admin_cmd.cpp @@ -374,4 +374,54 @@ LoggingCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 0; } +////////////////////////////////////////////////////////////////////////// + +FlushCommand::FlushCommand() +{ + m_Options.add_options()("h,help", "Print help"); + m_Options.add_option("", "u", "hosturl", "Host URL", cxxopts::value(m_HostName)->default_value(""), "<hosturl>"); +} + +FlushCommand::~FlushCommand() = default; + +int +FlushCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) +{ + ZEN_UNUSED(GlobalOptions); + + if (!ParseOptions(argc, argv)) + { + return 0; + } + + m_HostName = ResolveTargetHostSpec(m_HostName); + + if (m_HostName.empty()) + { + throw OptionParseException("unable to resolve server specification"); + } + + zen::HttpClient Http(m_HostName); + + if (zen::HttpClient::Response Response = Http.Post("/admin/flush"sv)) + { + ZEN_CONSOLE("OK: {}", Response.ToText()); + + return 0; + } + else if (int StatusCode = (int)Response.StatusCode) + { + ZEN_ERROR("flush failed: {}: {} ({})", + (int)Response.StatusCode, + ReasonStringForHttpResultCode((int)Response.StatusCode), + Response.AsText()); + } + else + { + ZEN_ERROR("flush failed: {}", Response.AsText()); + } + + return 1; +} + } // namespace zen |