]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/tools/ldb_cmd_impl.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / tools / ldb_cmd_impl.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5
6 #pragma once
7
8 #include "rocksdb/utilities/ldb_cmd.h"
9
10 #include <map>
11 #include <string>
12 #include <utility>
13 #include <vector>
14
15 namespace ROCKSDB_NAMESPACE {
16
17 class CompactorCommand : public LDBCommand {
18 public:
19 static std::string Name() { return "compact"; }
20
21 CompactorCommand(const std::vector<std::string>& params,
22 const std::map<std::string, std::string>& options,
23 const std::vector<std::string>& flags);
24
25 static void Help(std::string& ret);
26
27 virtual void DoCommand() override;
28
29 private:
30 bool null_from_;
31 std::string from_;
32 bool null_to_;
33 std::string to_;
34 };
35
36 class DBFileDumperCommand : public LDBCommand {
37 public:
38 static std::string Name() { return "dump_live_files"; }
39
40 DBFileDumperCommand(const std::vector<std::string>& params,
41 const std::map<std::string, std::string>& options,
42 const std::vector<std::string>& flags);
43
44 static void Help(std::string& ret);
45
46 virtual void DoCommand() override;
47 };
48
49 class DBDumperCommand : public LDBCommand {
50 public:
51 static std::string Name() { return "dump"; }
52
53 DBDumperCommand(const std::vector<std::string>& params,
54 const std::map<std::string, std::string>& options,
55 const std::vector<std::string>& flags);
56
57 static void Help(std::string& ret);
58
59 virtual void DoCommand() override;
60
61 private:
62 /**
63 * Extract file name from the full path. We handle both the forward slash (/)
64 * and backslash (\) to make sure that different OS-s are supported.
65 */
66 static std::string GetFileNameFromPath(const std::string& s) {
67 std::size_t n = s.find_last_of("/\\");
68
69 if (std::string::npos == n) {
70 return s;
71 } else {
72 return s.substr(n + 1);
73 }
74 }
75
76 void DoDumpCommand();
77
78 bool null_from_;
79 std::string from_;
80 bool null_to_;
81 std::string to_;
82 int max_keys_;
83 std::string delim_;
84 bool count_only_;
85 bool count_delim_;
86 bool print_stats_;
87 std::string path_;
88
89 static const std::string ARG_COUNT_ONLY;
90 static const std::string ARG_COUNT_DELIM;
91 static const std::string ARG_STATS;
92 static const std::string ARG_TTL_BUCKET;
93 };
94
95 class InternalDumpCommand : public LDBCommand {
96 public:
97 static std::string Name() { return "idump"; }
98
99 InternalDumpCommand(const std::vector<std::string>& params,
100 const std::map<std::string, std::string>& options,
101 const std::vector<std::string>& flags);
102
103 static void Help(std::string& ret);
104
105 virtual void DoCommand() override;
106
107 private:
108 bool has_from_;
109 std::string from_;
110 bool has_to_;
111 std::string to_;
112 int max_keys_;
113 std::string delim_;
114 bool count_only_;
115 bool count_delim_;
116 bool print_stats_;
117 bool is_input_key_hex_;
118
119 static const std::string ARG_DELIM;
120 static const std::string ARG_COUNT_ONLY;
121 static const std::string ARG_COUNT_DELIM;
122 static const std::string ARG_STATS;
123 static const std::string ARG_INPUT_KEY_HEX;
124 };
125
126 class DBLoaderCommand : public LDBCommand {
127 public:
128 static std::string Name() { return "load"; }
129
130 DBLoaderCommand(std::string& db_name, std::vector<std::string>& args);
131
132 DBLoaderCommand(const std::vector<std::string>& params,
133 const std::map<std::string, std::string>& options,
134 const std::vector<std::string>& flags);
135
136 static void Help(std::string& ret);
137 virtual void DoCommand() override;
138
139 virtual void OverrideBaseOptions() override;
140
141 private:
142 bool disable_wal_;
143 bool bulk_load_;
144 bool compact_;
145
146 static const std::string ARG_DISABLE_WAL;
147 static const std::string ARG_BULK_LOAD;
148 static const std::string ARG_COMPACT;
149 };
150
151 class ManifestDumpCommand : public LDBCommand {
152 public:
153 static std::string Name() { return "manifest_dump"; }
154
155 ManifestDumpCommand(const std::vector<std::string>& params,
156 const std::map<std::string, std::string>& options,
157 const std::vector<std::string>& flags);
158
159 static void Help(std::string& ret);
160 virtual void DoCommand() override;
161
162 virtual bool NoDBOpen() override { return true; }
163
164 private:
165 bool verbose_;
166 bool json_;
167 std::string path_;
168
169 static const std::string ARG_VERBOSE;
170 static const std::string ARG_JSON;
171 static const std::string ARG_PATH;
172 };
173
174 class FileChecksumDumpCommand : public LDBCommand {
175 public:
176 static std::string Name() { return "file_checksum_dump"; }
177
178 FileChecksumDumpCommand(const std::vector<std::string>& params,
179 const std::map<std::string, std::string>& options,
180 const std::vector<std::string>& flags);
181
182 static void Help(std::string& ret);
183 void DoCommand() override;
184
185 bool NoDBOpen() override { return true; }
186
187 private:
188 std::string path_;
189
190 static const std::string ARG_PATH;
191 };
192
193 class ListColumnFamiliesCommand : public LDBCommand {
194 public:
195 static std::string Name() { return "list_column_families"; }
196
197 ListColumnFamiliesCommand(const std::vector<std::string>& params,
198 const std::map<std::string, std::string>& options,
199 const std::vector<std::string>& flags);
200
201 static void Help(std::string& ret);
202 virtual void DoCommand() override;
203
204 virtual bool NoDBOpen() override { return true; }
205 };
206
207 class CreateColumnFamilyCommand : public LDBCommand {
208 public:
209 static std::string Name() { return "create_column_family"; }
210
211 CreateColumnFamilyCommand(const std::vector<std::string>& params,
212 const std::map<std::string, std::string>& options,
213 const std::vector<std::string>& flags);
214
215 static void Help(std::string& ret);
216 virtual void DoCommand() override;
217
218 virtual bool NoDBOpen() override { return false; }
219
220 private:
221 std::string new_cf_name_;
222 };
223
224 class DropColumnFamilyCommand : public LDBCommand {
225 public:
226 static std::string Name() { return "drop_column_family"; }
227
228 DropColumnFamilyCommand(const std::vector<std::string>& params,
229 const std::map<std::string, std::string>& options,
230 const std::vector<std::string>& flags);
231
232 static void Help(std::string& ret);
233 virtual void DoCommand() override;
234
235 virtual bool NoDBOpen() override { return false; }
236
237 private:
238 std::string cf_name_to_drop_;
239 };
240
241 class ReduceDBLevelsCommand : public LDBCommand {
242 public:
243 static std::string Name() { return "reduce_levels"; }
244
245 ReduceDBLevelsCommand(const std::vector<std::string>& params,
246 const std::map<std::string, std::string>& options,
247 const std::vector<std::string>& flags);
248
249 virtual void OverrideBaseOptions() override;
250
251 virtual void DoCommand() override;
252
253 virtual bool NoDBOpen() override { return true; }
254
255 static void Help(std::string& msg);
256
257 static std::vector<std::string> PrepareArgs(const std::string& db_path,
258 int new_levels,
259 bool print_old_level = false);
260
261 private:
262 int old_levels_;
263 int new_levels_;
264 bool print_old_levels_;
265
266 static const std::string ARG_NEW_LEVELS;
267 static const std::string ARG_PRINT_OLD_LEVELS;
268
269 Status GetOldNumOfLevels(Options& opt, int* levels);
270 };
271
272 class ChangeCompactionStyleCommand : public LDBCommand {
273 public:
274 static std::string Name() { return "change_compaction_style"; }
275
276 ChangeCompactionStyleCommand(
277 const std::vector<std::string>& params,
278 const std::map<std::string, std::string>& options,
279 const std::vector<std::string>& flags);
280
281 virtual void OverrideBaseOptions() override;
282
283 virtual void DoCommand() override;
284
285 static void Help(std::string& msg);
286
287 private:
288 int old_compaction_style_;
289 int new_compaction_style_;
290
291 static const std::string ARG_OLD_COMPACTION_STYLE;
292 static const std::string ARG_NEW_COMPACTION_STYLE;
293 };
294
295 class WALDumperCommand : public LDBCommand {
296 public:
297 static std::string Name() { return "dump_wal"; }
298
299 WALDumperCommand(const std::vector<std::string>& params,
300 const std::map<std::string, std::string>& options,
301 const std::vector<std::string>& flags);
302
303 virtual bool NoDBOpen() override { return true; }
304
305 static void Help(std::string& ret);
306 virtual void DoCommand() override;
307
308 private:
309 bool print_header_;
310 std::string wal_file_;
311 bool print_values_;
312 bool is_write_committed_; // default will be set to true
313
314 static const std::string ARG_WAL_FILE;
315 static const std::string ARG_WRITE_COMMITTED;
316 static const std::string ARG_PRINT_HEADER;
317 static const std::string ARG_PRINT_VALUE;
318 };
319
320 class GetCommand : public LDBCommand {
321 public:
322 static std::string Name() { return "get"; }
323
324 GetCommand(const std::vector<std::string>& params,
325 const std::map<std::string, std::string>& options,
326 const std::vector<std::string>& flags);
327
328 virtual void DoCommand() override;
329
330 static void Help(std::string& ret);
331
332 private:
333 std::string key_;
334 };
335
336 class ApproxSizeCommand : public LDBCommand {
337 public:
338 static std::string Name() { return "approxsize"; }
339
340 ApproxSizeCommand(const std::vector<std::string>& params,
341 const std::map<std::string, std::string>& options,
342 const std::vector<std::string>& flags);
343
344 virtual void DoCommand() override;
345
346 static void Help(std::string& ret);
347
348 private:
349 std::string start_key_;
350 std::string end_key_;
351 };
352
353 class BatchPutCommand : public LDBCommand {
354 public:
355 static std::string Name() { return "batchput"; }
356
357 BatchPutCommand(const std::vector<std::string>& params,
358 const std::map<std::string, std::string>& options,
359 const std::vector<std::string>& flags);
360
361 virtual void DoCommand() override;
362
363 static void Help(std::string& ret);
364
365 virtual void OverrideBaseOptions() override;
366
367 private:
368 /**
369 * The key-values to be inserted.
370 */
371 std::vector<std::pair<std::string, std::string>> key_values_;
372 };
373
374 class ScanCommand : public LDBCommand {
375 public:
376 static std::string Name() { return "scan"; }
377
378 ScanCommand(const std::vector<std::string>& params,
379 const std::map<std::string, std::string>& options,
380 const std::vector<std::string>& flags);
381
382 virtual void DoCommand() override;
383
384 static void Help(std::string& ret);
385
386 private:
387 std::string start_key_;
388 std::string end_key_;
389 bool start_key_specified_;
390 bool end_key_specified_;
391 int max_keys_scanned_;
392 bool no_value_;
393 };
394
395 class DeleteCommand : public LDBCommand {
396 public:
397 static std::string Name() { return "delete"; }
398
399 DeleteCommand(const std::vector<std::string>& params,
400 const std::map<std::string, std::string>& options,
401 const std::vector<std::string>& flags);
402
403 virtual void DoCommand() override;
404
405 static void Help(std::string& ret);
406
407 private:
408 std::string key_;
409 };
410
411 class DeleteRangeCommand : public LDBCommand {
412 public:
413 static std::string Name() { return "deleterange"; }
414
415 DeleteRangeCommand(const std::vector<std::string>& params,
416 const std::map<std::string, std::string>& options,
417 const std::vector<std::string>& flags);
418
419 virtual void DoCommand() override;
420
421 static void Help(std::string& ret);
422
423 private:
424 std::string begin_key_;
425 std::string end_key_;
426 };
427
428 class PutCommand : public LDBCommand {
429 public:
430 static std::string Name() { return "put"; }
431
432 PutCommand(const std::vector<std::string>& params,
433 const std::map<std::string, std::string>& options,
434 const std::vector<std::string>& flags);
435
436 virtual void DoCommand() override;
437
438 static void Help(std::string& ret);
439
440 virtual void OverrideBaseOptions() override;
441
442 private:
443 std::string key_;
444 std::string value_;
445 };
446
447 /**
448 * Command that starts up a REPL shell that allows
449 * get/put/delete.
450 */
451 class DBQuerierCommand : public LDBCommand {
452 public:
453 static std::string Name() { return "query"; }
454
455 DBQuerierCommand(const std::vector<std::string>& params,
456 const std::map<std::string, std::string>& options,
457 const std::vector<std::string>& flags);
458
459 static void Help(std::string& ret);
460
461 virtual void DoCommand() override;
462
463 private:
464 static const char* HELP_CMD;
465 static const char* GET_CMD;
466 static const char* PUT_CMD;
467 static const char* DELETE_CMD;
468 };
469
470 class CheckConsistencyCommand : public LDBCommand {
471 public:
472 static std::string Name() { return "checkconsistency"; }
473
474 CheckConsistencyCommand(const std::vector<std::string>& params,
475 const std::map<std::string, std::string>& options,
476 const std::vector<std::string>& flags);
477
478 virtual void DoCommand() override;
479
480 virtual bool NoDBOpen() override { return true; }
481
482 static void Help(std::string& ret);
483 };
484
485 class CheckPointCommand : public LDBCommand {
486 public:
487 static std::string Name() { return "checkpoint"; }
488
489 CheckPointCommand(const std::vector<std::string>& params,
490 const std::map<std::string, std::string>& options,
491 const std::vector<std::string>& flags);
492
493 virtual void DoCommand() override;
494
495 static void Help(std::string& ret);
496
497 std::string checkpoint_dir_;
498 private:
499 static const std::string ARG_CHECKPOINT_DIR;
500 };
501
502 class RepairCommand : public LDBCommand {
503 public:
504 static std::string Name() { return "repair"; }
505
506 RepairCommand(const std::vector<std::string>& params,
507 const std::map<std::string, std::string>& options,
508 const std::vector<std::string>& flags);
509
510 virtual void DoCommand() override;
511
512 virtual bool NoDBOpen() override { return true; }
513
514 virtual void OverrideBaseOptions() override;
515
516 static void Help(std::string& ret);
517 };
518
519 class BackupableCommand : public LDBCommand {
520 public:
521 BackupableCommand(const std::vector<std::string>& params,
522 const std::map<std::string, std::string>& options,
523 const std::vector<std::string>& flags);
524
525 protected:
526 static void Help(const std::string& name, std::string& ret);
527 std::string backup_env_uri_;
528 std::string backup_dir_;
529 int num_threads_;
530 std::unique_ptr<Logger> logger_;
531 std::shared_ptr<Env> backup_env_guard_;
532
533 private:
534 static const std::string ARG_BACKUP_DIR;
535 static const std::string ARG_BACKUP_ENV_URI;
536 static const std::string ARG_NUM_THREADS;
537 static const std::string ARG_STDERR_LOG_LEVEL;
538 };
539
540 class BackupCommand : public BackupableCommand {
541 public:
542 static std::string Name() { return "backup"; }
543 BackupCommand(const std::vector<std::string>& params,
544 const std::map<std::string, std::string>& options,
545 const std::vector<std::string>& flags);
546 virtual void DoCommand() override;
547 static void Help(std::string& ret);
548 };
549
550 class RestoreCommand : public BackupableCommand {
551 public:
552 static std::string Name() { return "restore"; }
553 RestoreCommand(const std::vector<std::string>& params,
554 const std::map<std::string, std::string>& options,
555 const std::vector<std::string>& flags);
556 virtual void DoCommand() override;
557 virtual bool NoDBOpen() override { return true; }
558 static void Help(std::string& ret);
559 };
560
561 class WriteExternalSstFilesCommand : public LDBCommand {
562 public:
563 static std::string Name() { return "write_extern_sst"; }
564 WriteExternalSstFilesCommand(
565 const std::vector<std::string>& params,
566 const std::map<std::string, std::string>& options,
567 const std::vector<std::string>& flags);
568
569 virtual void DoCommand() override;
570
571 virtual bool NoDBOpen() override { return false; }
572
573 virtual void OverrideBaseOptions() override;
574
575 static void Help(std::string& ret);
576
577 private:
578 std::string output_sst_path_;
579 };
580
581 class IngestExternalSstFilesCommand : public LDBCommand {
582 public:
583 static std::string Name() { return "ingest_extern_sst"; }
584 IngestExternalSstFilesCommand(
585 const std::vector<std::string>& params,
586 const std::map<std::string, std::string>& options,
587 const std::vector<std::string>& flags);
588
589 virtual void DoCommand() override;
590
591 virtual bool NoDBOpen() override { return false; }
592
593 virtual void OverrideBaseOptions() override;
594
595 static void Help(std::string& ret);
596
597 private:
598 std::string input_sst_path_;
599 bool move_files_;
600 bool snapshot_consistency_;
601 bool allow_global_seqno_;
602 bool allow_blocking_flush_;
603 bool ingest_behind_;
604 bool write_global_seqno_;
605
606 static const std::string ARG_MOVE_FILES;
607 static const std::string ARG_SNAPSHOT_CONSISTENCY;
608 static const std::string ARG_ALLOW_GLOBAL_SEQNO;
609 static const std::string ARG_ALLOW_BLOCKING_FLUSH;
610 static const std::string ARG_INGEST_BEHIND;
611 static const std::string ARG_WRITE_GLOBAL_SEQNO;
612 };
613
614 // Command that prints out range delete tombstones in SST files.
615 class ListFileRangeDeletesCommand : public LDBCommand {
616 public:
617 static std::string Name() { return "list_file_range_deletes"; }
618
619 ListFileRangeDeletesCommand(const std::map<std::string, std::string>& options,
620 const std::vector<std::string>& flags);
621
622 void DoCommand() override;
623
624 static void Help(std::string& ret);
625
626 private:
627 int max_keys_ = 1000;
628 };
629
630 // Command that removes the SST file forcibly from the manifest.
631 class UnsafeRemoveSstFileCommand : public LDBCommand {
632 public:
633 static std::string Name() { return "unsafe_remove_sst_file"; }
634
635 UnsafeRemoveSstFileCommand(const std::vector<std::string>& params,
636 const std::map<std::string, std::string>& options,
637 const std::vector<std::string>& flags);
638
639 static void Help(std::string& ret);
640
641 virtual void DoCommand() override;
642
643 virtual bool NoDBOpen() override { return true; }
644
645 private:
646 uint64_t sst_file_number_;
647 };
648
649 } // namespace ROCKSDB_NAMESPACE