aboutsummaryrefslogtreecommitdiff
path: root/src/zen/cmds/cache_cmd.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/zen/cmds/cache_cmd.h')
-rw-r--r--src/zen/cmds/cache_cmd.h330
1 files changed, 259 insertions, 71 deletions
diff --git a/src/zen/cmds/cache_cmd.h b/src/zen/cmds/cache_cmd.h
index 4f5b90f4d..a2834f73d 100644
--- a/src/zen/cmds/cache_cmd.h
+++ b/src/zen/cmds/cache_cmd.h
@@ -4,131 +4,319 @@
#include "../zen.h"
+#include <filesystem>
+
namespace zen {
-class DropCommand : public CacheStoreCommand
+// Base for `cache` subcommands. Registers the shared --hosturl option and
+// exposes ResolveHost() which subcommands must call before issuing HTTP
+// requests (it normalises m_HostName and throws if no host could be resolved).
+class CacheSubCmdBase : public ZenSubCmdBase
{
public:
- static constexpr char Name[] = "drop";
- static constexpr char Description[] = "Drop cache namespace or bucket";
+ CacheSubCmdBase(std::string_view Name, std::string_view Description);
+
+protected:
+ void ResolveHost();
+
+ std::string m_HostName;
+};
+
+class CacheDetailsSubCmd : public CacheSubCmdBase
+{
+public:
+ CacheDetailsSubCmd();
+ void Run(const ZenCliOptions& GlobalOptions) override;
+
+private:
+ bool m_CSV = false;
+ bool m_YAML = false;
+ bool m_Details = false;
+ bool m_AttachmentDetails = false;
+ std::string m_Namespace;
+ std::string m_Bucket;
+ std::string m_ValueKey;
+};
+
+class CacheDropSubCmd : public CacheSubCmdBase
+{
+public:
+ CacheDropSubCmd();
+ void Run(const ZenCliOptions& GlobalOptions) override;
+
+private:
+ std::string m_NamespaceName;
+ std::string m_BucketName;
+};
+
+class CacheGenSubCmd : public CacheSubCmdBase
+{
+public:
+ CacheGenSubCmd();
+ void Run(const ZenCliOptions& GlobalOptions) override;
+
+private:
+ std::string m_Namespace;
+ std::string m_Bucket;
+ uint64_t m_Count = 1;
+ uint64_t m_MinSize = 0;
+ uint64_t m_MaxSize = 0;
+ uint32_t m_MinAttachmentCount = 0;
+ uint32_t m_MaxAttachmentCount = 0;
+};
+
+class CacheGetSubCmd : public CacheSubCmdBase
+{
+public:
+ CacheGetSubCmd();
+ void Run(const ZenCliOptions& GlobalOptions) override;
+
+private:
+ std::string m_Namespace;
+ std::string m_Bucket;
+ std::string m_ValueKey;
+ std::string m_AttachmentHash;
+ std::filesystem::path m_OutputPath;
+ bool m_AsText = false;
+ bool m_Decompress = true;
+};
+
+class CacheInfoSubCmd : public CacheSubCmdBase
+{
+public:
+ CacheInfoSubCmd();
+ void Run(const ZenCliOptions& GlobalOptions) override;
+
+private:
+ std::string m_NamespaceName;
+ std::string m_SizeInfoBucketNames;
+ bool m_BucketSizeInfo = false;
+ bool m_YAML = false;
+ std::string m_BucketName;
+};
- DropCommand();
- ~DropCommand();
+class CacheRecordSubCmd : public CacheSubCmdBase
+{
+public:
+ CacheRecordSubCmd();
+ void Run(const ZenCliOptions& GlobalOptions) override;
+
+private:
+ std::string m_Path;
+};
+
+class CacheReplaySubCmd : public CacheSubCmdBase
+{
+public:
+ CacheReplaySubCmd();
+ void Run(const ZenCliOptions& GlobalOptions) override;
- virtual void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
- virtual cxxopts::Options& Options() override { return m_Options; }
+private:
+ std::string m_RecordingPath;
+ bool m_OnHost = false;
+ bool m_ShowMethodStats = false;
+ int m_ProcessCount = 1;
+ int m_ThreadCount = 0;
+ uint64_t m_Offset = 0;
+ uint64_t m_Stride = 1;
+ bool m_ForceAllowLocalRefs = false;
+ bool m_DisableLocalRefs = false;
+ bool m_ForceAllowLocalHandleRef = false;
+ bool m_DisableLocalHandleRefs = false;
+ bool m_ForceAllowPartialLocalRefs = false;
+ bool m_DisablePartialLocalRefs = false;
+ bool m_DryRun = false;
+};
+
+class CacheStatsSubCmd : public CacheSubCmdBase
+{
+public:
+ CacheStatsSubCmd();
+ void Run(const ZenCliOptions& GlobalOptions) override;
+
+private:
+ bool m_YAML = false;
+};
+
+class CacheCommand : public CacheStoreCmdWithSubCommands
+{
+public:
+ static constexpr char Name[] = "cache";
+ static constexpr char Description[] = "Manage cache - info, stats, details, get, gen, drop, record, replay";
+
+ CacheCommand();
+ ~CacheCommand();
+
+ cxxopts::Options& Options() override { return m_Options; }
+
+private:
+ cxxopts::Options m_Options{Name, Description};
+
+ CacheDetailsSubCmd m_DetailsSubCmd;
+ CacheDropSubCmd m_DropSubCmd;
+ CacheGenSubCmd m_GenSubCmd;
+ CacheGetSubCmd m_GetSubCmd;
+ CacheInfoSubCmd m_InfoSubCmd;
+ CacheRecordSubCmd m_RecordSubCmd;
+ CacheReplaySubCmd m_ReplaySubCmd;
+ CacheStatsSubCmd m_StatsSubCmd;
+};
+
+// ---------------------------------------------------------------------------
+// Deprecated legacy top-level commands. These forward to the corresponding
+// 'cache <sub>' subcommand so that existing scripts keep working. They are
+// hidden from the top-level `zen --help` listing; `zen cache --help` is the
+// canonical discovery surface now.
+
+namespace cache_legacy_shim {
+ void RunAs(const char* SubCommandName, const ZenCliOptions& GlobalOptions, int argc, char** argv);
+}
+
+class DeprecatedCacheStoreCommand : public CacheStoreCommand
+{
+public:
+ bool IsHidden() const override { return true; }
+};
+
+class DropCommand : public DeprecatedCacheStoreCommand
+{
+public:
+ static constexpr char Name[] = "drop";
+ static constexpr char Description[] = "(deprecated, use 'cache drop') Drop cache namespace or bucket";
+
+ void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override
+ {
+ cache_legacy_shim::RunAs("drop", GlobalOptions, argc, argv);
+ }
+ cxxopts::Options& Options() override { return m_Options; }
private:
cxxopts::Options m_Options{Name, Description};
- std::string m_HostName;
- std::string m_NamespaceName;
- std::string m_BucketName;
};
-class CacheInfoCommand : public CacheStoreCommand
+class CacheInfoCommand : public DeprecatedCacheStoreCommand
{
public:
static constexpr char Name[] = "cache-info";
- static constexpr char Description[] = "Info on cache, namespace or bucket";
+ static constexpr char Description[] = "(deprecated, use 'cache info') Info on cache, namespace or bucket";
- CacheInfoCommand();
- ~CacheInfoCommand();
- virtual void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
- virtual cxxopts::Options& Options() override { return m_Options; }
+ void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override
+ {
+ cache_legacy_shim::RunAs("info", GlobalOptions, argc, argv);
+ }
+ cxxopts::Options& Options() override { return m_Options; }
private:
cxxopts::Options m_Options{Name, Description};
- std::string m_HostName;
- std::string m_NamespaceName;
- std::string m_SizeInfoBucketNames;
- bool m_BucketSizeInfo = false;
- std::string m_BucketName;
};
-class CacheStatsCommand : public CacheStoreCommand
+class CacheStatsCommand : public DeprecatedCacheStoreCommand
{
public:
static constexpr char Name[] = "cache-stats";
- static constexpr char Description[] = "Stats on cache";
+ static constexpr char Description[] = "(deprecated, use 'cache stats') Stats on cache";
- CacheStatsCommand();
- ~CacheStatsCommand();
- virtual void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
- virtual cxxopts::Options& Options() override { return m_Options; }
+ void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override
+ {
+ cache_legacy_shim::RunAs("stats", GlobalOptions, argc, argv);
+ }
+ cxxopts::Options& Options() override { return m_Options; }
private:
cxxopts::Options m_Options{Name, Description};
- std::string m_HostName;
};
-class CacheDetailsCommand : public CacheStoreCommand
+class CacheDetailsCommand : public DeprecatedCacheStoreCommand
{
public:
static constexpr char Name[] = "cache-details";
- static constexpr char Description[] = "Details on cache";
+ static constexpr char Description[] = "(deprecated, use 'cache details') Details on cache";
- CacheDetailsCommand();
- ~CacheDetailsCommand();
- virtual void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
- virtual cxxopts::Options& Options() override { return m_Options; }
+ void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override
+ {
+ cache_legacy_shim::RunAs("details", GlobalOptions, argc, argv);
+ }
+ cxxopts::Options& Options() override { return m_Options; }
private:
cxxopts::Options m_Options{Name, Description};
- std::string m_HostName;
- bool m_CSV = false;
- bool m_Details = false;
- bool m_AttachmentDetails = false;
- std::string m_Namespace;
- std::string m_Bucket;
- std::string m_ValueKey;
};
-class CacheGenerateCommand : public CacheStoreCommand
+class CacheGenerateCommand : public DeprecatedCacheStoreCommand
{
public:
static constexpr char Name[] = "cache-gen";
- static constexpr char Description[] = "Generates cache values into a bucket";
+ static constexpr char Description[] = "(deprecated, use 'cache gen') Generates cache values into a bucket";
- CacheGenerateCommand();
- ~CacheGenerateCommand();
- virtual void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
- virtual cxxopts::Options& Options() override { return m_Options; }
+ void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override
+ {
+ cache_legacy_shim::RunAs("gen", GlobalOptions, argc, argv);
+ }
+ cxxopts::Options& Options() override { return m_Options; }
private:
cxxopts::Options m_Options{Name, Description};
- std::string m_HostName;
- std::string m_Namespace;
- std::string m_Bucket;
- uint64_t m_Count = 1;
-
- uint64_t m_MinSize = 0;
- uint64_t m_MaxSize = 0;
- uint32_t m_MinAttachmentCount = 0;
- uint32_t m_MaxAttachmentCount = 0;
};
-class CacheGetCommand : public CacheStoreCommand
+class CacheGetCommand : public DeprecatedCacheStoreCommand
{
public:
static constexpr char Name[] = "cache-get";
- static constexpr char Description[] = "Get cache values/records or attachments from a bucket";
+ static constexpr char Description[] = "(deprecated, use 'cache get') Get cache values/records or attachments from a bucket";
- CacheGetCommand();
- ~CacheGetCommand();
+ void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override
+ {
+ cache_legacy_shim::RunAs("get", GlobalOptions, argc, argv);
+ }
+ cxxopts::Options& Options() override { return m_Options; }
- virtual void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
- virtual cxxopts::Options& Options() override { return m_Options; }
+private:
+ cxxopts::Options m_Options{Name, Description};
+};
+
+class RpcStartRecordingCommand : public DeprecatedCacheStoreCommand
+{
+public:
+ static constexpr char Name[] = "rpc-record-start";
+ static constexpr char Description[] = "(deprecated, use 'cache record <path>') Starts recording of cache rpc requests on a host";
+
+ void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override
+ {
+ cache_legacy_shim::RunAs("record", GlobalOptions, argc, argv);
+ }
+ cxxopts::Options& Options() override { return m_Options; }
private:
- cxxopts::Options m_Options{Name, Description};
- std::string m_HostName;
- std::string m_Namespace;
- std::string m_Bucket;
- std::string m_ValueKey;
- std::string m_AttachmentHash;
- std::filesystem::path m_OutputPath;
- bool m_AsText = false;
- bool m_Decompress = true;
+ cxxopts::Options m_Options{Name, Description};
+};
+
+class RpcStopRecordingCommand : public DeprecatedCacheStoreCommand
+{
+public:
+ static constexpr char Name[] = "rpc-record-stop";
+ static constexpr char Description[] = "(deprecated, use 'cache record stop') Stops recording of cache rpc requests on a host";
+
+ void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
+ cxxopts::Options& Options() override { return m_Options; }
+
+private:
+ cxxopts::Options m_Options{Name, Description};
+};
+
+class RpcReplayCommand : public DeprecatedCacheStoreCommand
+{
+public:
+ static constexpr char Name[] = "rpc-record-replay";
+ static constexpr char Description[] = "(deprecated, use 'cache replay') Replays a previously recorded session of rpc requests";
+
+ void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override
+ {
+ cache_legacy_shim::RunAs("replay", GlobalOptions, argc, argv);
+ }
+ cxxopts::Options& Options() override { return m_Options; }
+
+private:
+ cxxopts::Options m_Options{Name, Description};
};
} // namespace zen