-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpika_admin.h
458 lines (395 loc) · 15.3 KB
/
pika_admin.h
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
// Copyright (c) 2015-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef PIKA_ADMIN_H_
#define PIKA_ADMIN_H_
#include <sys/resource.h>
#include <sys/time.h>
#include <iomanip>
#include <sstream>
#include "storage/storage.h"
#include "include/pika_command.h"
/*
* Admin
*/
class SlaveofCmd : public Cmd {
public:
SlaveofCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), is_none_(false) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new SlaveofCmd(*this); }
private:
std::string master_ip_;
int64_t master_port_ = -1;
bool is_none_ = false;
virtual void DoInitial() override;
virtual void Clear() {
is_none_ = false;
master_ip_.clear();
master_port_ = 0;
}
};
class DbSlaveofCmd : public Cmd {
public:
DbSlaveofCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new DbSlaveofCmd(*this); }
private:
std::string db_name_;
bool force_sync_ = false;
bool is_none_ = false;
bool have_offset_ = false;
int64_t filenum_ = 0;
int64_t offset_ = 0;
virtual void DoInitial() override;
virtual void Clear() {
db_name_.clear();
force_sync_ = false;
is_none_ = false;
have_offset_ = false;
}
};
class AuthCmd : public Cmd {
public:
AuthCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new AuthCmd(*this); }
private:
std::string pwd_;
virtual void DoInitial() override;
};
class BgsaveCmd : public Cmd {
public:
BgsaveCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BgsaveCmd(*this); }
private:
virtual void DoInitial() override;
virtual void Clear() { bgsave_tables_.clear(); }
std::set<std::string> bgsave_tables_;
};
class CompactCmd : public Cmd {
public:
CompactCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new CompactCmd(*this); }
private:
virtual void DoInitial() override;
virtual void Clear() {
struct_type_.clear();
compact_tables_.clear();
}
std::string struct_type_;
std::set<std::string> compact_tables_;
};
class PurgelogstoCmd : public Cmd {
public:
PurgelogstoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), num_(0) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new PurgelogstoCmd(*this); }
private:
uint32_t num_ = 0;
std::string table_;
virtual void DoInitial() override;
};
class PingCmd : public Cmd {
public:
PingCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new PingCmd(*this); }
private:
virtual void DoInitial() override;
};
class SelectCmd : public Cmd {
public:
SelectCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new SelectCmd(*this); }
private:
virtual void DoInitial() override;
virtual void Clear() { table_name_.clear(); }
std::string table_name_;
};
class FlushallCmd : public Cmd {
public:
FlushallCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new FlushallCmd(*this); }
private:
virtual void DoInitial() override;
virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
};
class FlushdbCmd : public Cmd {
public:
FlushdbCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new FlushdbCmd(*this); }
private:
std::string db_name_;
virtual void DoInitial() override;
virtual void Clear() { db_name_.clear(); }
};
class ClientCmd : public Cmd {
public:
ClientCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
const static std::string CLIENT_LIST_S;
const static std::string CLIENT_KILL_S;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new ClientCmd(*this); }
private:
std::string operation_, info_;
virtual void DoInitial() override;
};
class InfoCmd : public Cmd {
public:
enum InfoSection {
kInfoErr = 0x0,
kInfoServer,
kInfoClients,
kInfoStats,
kInfoExecCount,
kInfoCPU,
kInfoReplication,
kInfoKeyspace,
kInfoLog,
kInfoData,
kInfo,
kInfoAll,
kInfoDebug
};
InfoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), rescan_(false), off_(false) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new InfoCmd(*this); }
private:
InfoSection info_section_;
bool rescan_ = false; // whether to rescan the keyspace
bool off_ = false;
std::set<std::string> keyspace_scan_tables_;
const static std::string kInfoSection;
const static std::string kAllSection;
const static std::string kServerSection;
const static std::string kClientsSection;
const static std::string kStatsSection;
const static std::string kExecCountSection;
const static std::string kCPUSection;
const static std::string kReplicationSection;
const static std::string kKeyspaceSection;
const static std::string kDataSection;
const static std::string kDebugSection;
virtual void DoInitial() override;
virtual void Clear() {
rescan_ = false;
off_ = false;
keyspace_scan_tables_.clear();
}
void InfoServer(std::string& info);
void InfoClients(std::string& info);
void InfoStats(std::string& info);
void InfoExecCount(std::string& info);
void InfoCPU(std::string& info);
void InfoShardingReplication(std::string& info);
void InfoReplication(std::string& info);
void InfoKeyspace(std::string& info);
void InfoData(std::string& info);
void InfoDebug(std::string& info);
};
class ShutdownCmd : public Cmd {
public:
ShutdownCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new ShutdownCmd(*this); }
private:
virtual void DoInitial() override;
};
class ConfigCmd : public Cmd {
public:
ConfigCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new ConfigCmd(*this); }
private:
std::vector<std::string> config_args_v_;
virtual void DoInitial() override;
void ConfigGet(std::string& ret);
void ConfigSet(std::string& ret);
void ConfigRewrite(std::string& ret);
void ConfigResetstat(std::string& ret);
};
class MonitorCmd : public Cmd {
public:
MonitorCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new MonitorCmd(*this); }
private:
virtual void DoInitial() override;
};
class DbsizeCmd : public Cmd {
public:
DbsizeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new DbsizeCmd(*this); }
private:
virtual void DoInitial() override;
};
class TimeCmd : public Cmd {
public:
TimeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new TimeCmd(*this); }
private:
virtual void DoInitial() override;
};
class DelbackupCmd : public Cmd {
public:
DelbackupCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new DelbackupCmd(*this); }
private:
virtual void DoInitial() override;
};
class EchoCmd : public Cmd {
public:
EchoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new EchoCmd(*this); }
private:
std::string body_;
virtual void DoInitial() override;
};
class ScandbCmd : public Cmd {
public:
ScandbCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), type_(storage::kAll) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new ScandbCmd(*this); }
private:
storage::DataType type_ = storage::kAll;
virtual void DoInitial() override;
virtual void Clear() { type_ = storage::kAll; }
};
class SlowlogCmd : public Cmd {
public:
enum SlowlogCondition { kGET, kLEN, kRESET };
SlowlogCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), condition_(kGET) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new SlowlogCmd(*this); }
private:
int64_t number_ = 10;
SlowlogCmd::SlowlogCondition condition_ = kGET;
virtual void DoInitial() override;
virtual void Clear() {
number_ = 10;
condition_ = kGET;
}
};
class PaddingCmd : public Cmd {
public:
PaddingCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new PaddingCmd(*this); }
private:
virtual void DoInitial();
virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
};
#ifdef TCMALLOC_EXTENSION
class TcmallocCmd : public Cmd {
public:
TcmallocCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new TcmallocCmd(*this); }
private:
int64_t type_;
int64_t rate_;
virtual void DoInitial() override;
};
#endif
class PKPatternMatchDelCmd : public Cmd {
public:
PKPatternMatchDelCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new PKPatternMatchDelCmd(*this); }
private:
storage::DataType type_ = storage::kAll;
std::string pattern_;
virtual void DoInitial() override;
};
class DummyCmd : public Cmd {
public:
DummyCmd() : Cmd("", 0, 0) {}
DummyCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new DummyCmd(*this); }
private:
virtual void DoInitial() override;
};
class QuitCmd : public Cmd {
public:
QuitCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new QuitCmd(*this); }
private:
virtual void DoInitial() override;
};
class HelloCmd : public Cmd {
public:
HelloCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new HelloCmd(*this); }
private:
virtual void DoInitial() override;
};
#endif // PIKA_ADMIN_H_