aboutsummaryrefslogtreecommitdiff
path: root/src/zen/cmds/cache_cmd.h
blob: a2834f73d14d124d8ff0d308e3c2e3065e281ce3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "../zen.h"

#include <filesystem>

namespace zen {

// 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:
	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;
};

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;

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};
};

class CacheInfoCommand : public DeprecatedCacheStoreCommand
{
public:
	static constexpr char Name[]		= "cache-info";
	static constexpr char Description[] = "(deprecated, use 'cache info') Info on cache, namespace or bucket";

	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};
};

class CacheStatsCommand : public DeprecatedCacheStoreCommand
{
public:
	static constexpr char Name[]		= "cache-stats";
	static constexpr char Description[] = "(deprecated, use 'cache stats') Stats on cache";

	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};
};

class CacheDetailsCommand : public DeprecatedCacheStoreCommand
{
public:
	static constexpr char Name[]		= "cache-details";
	static constexpr char Description[] = "(deprecated, use 'cache details') Details on cache";

	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};
};

class CacheGenerateCommand : public DeprecatedCacheStoreCommand
{
public:
	static constexpr char Name[]		= "cache-gen";
	static constexpr char Description[] = "(deprecated, use 'cache gen') Generates cache values into a bucket";

	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};
};

class CacheGetCommand : public DeprecatedCacheStoreCommand
{
public:
	static constexpr char Name[]		= "cache-get";
	static constexpr char Description[] = "(deprecated, use 'cache get') Get cache values/records or attachments from a bucket";

	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; }

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};
};

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