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).
8 #include "rocksdb/utilities/ldb_cmd.h"
15 namespace ROCKSDB_NAMESPACE
{
17 class CompactorCommand
: public LDBCommand
{
19 static std::string
Name() { return "compact"; }
21 CompactorCommand(const std::vector
<std::string
>& params
,
22 const std::map
<std::string
, std::string
>& options
,
23 const std::vector
<std::string
>& flags
);
25 static void Help(std::string
& ret
);
27 virtual void DoCommand() override
;
36 class DBFileDumperCommand
: public LDBCommand
{
38 static std::string
Name() { return "dump_live_files"; }
40 DBFileDumperCommand(const std::vector
<std::string
>& params
,
41 const std::map
<std::string
, std::string
>& options
,
42 const std::vector
<std::string
>& flags
);
44 static void Help(std::string
& ret
);
46 virtual void DoCommand() override
;
49 class DBDumperCommand
: public LDBCommand
{
51 static std::string
Name() { return "dump"; }
53 DBDumperCommand(const std::vector
<std::string
>& params
,
54 const std::map
<std::string
, std::string
>& options
,
55 const std::vector
<std::string
>& flags
);
57 static void Help(std::string
& ret
);
59 virtual void DoCommand() override
;
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.
66 static std::string
GetFileNameFromPath(const std::string
& s
) {
67 std::size_t n
= s
.find_last_of("/\\");
69 if (std::string::npos
== n
) {
72 return s
.substr(n
+ 1);
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
;
95 class InternalDumpCommand
: public LDBCommand
{
97 static std::string
Name() { return "idump"; }
99 InternalDumpCommand(const std::vector
<std::string
>& params
,
100 const std::map
<std::string
, std::string
>& options
,
101 const std::vector
<std::string
>& flags
);
103 static void Help(std::string
& ret
);
105 virtual void DoCommand() override
;
117 bool is_input_key_hex_
;
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
;
126 class DBLoaderCommand
: public LDBCommand
{
128 static std::string
Name() { return "load"; }
130 DBLoaderCommand(std::string
& db_name
, std::vector
<std::string
>& args
);
132 DBLoaderCommand(const std::vector
<std::string
>& params
,
133 const std::map
<std::string
, std::string
>& options
,
134 const std::vector
<std::string
>& flags
);
136 static void Help(std::string
& ret
);
137 virtual void DoCommand() override
;
139 virtual void OverrideBaseOptions() override
;
146 static const std::string ARG_DISABLE_WAL
;
147 static const std::string ARG_BULK_LOAD
;
148 static const std::string ARG_COMPACT
;
151 class ManifestDumpCommand
: public LDBCommand
{
153 static std::string
Name() { return "manifest_dump"; }
155 ManifestDumpCommand(const std::vector
<std::string
>& params
,
156 const std::map
<std::string
, std::string
>& options
,
157 const std::vector
<std::string
>& flags
);
159 static void Help(std::string
& ret
);
160 virtual void DoCommand() override
;
162 virtual bool NoDBOpen() override
{ return true; }
169 static const std::string ARG_VERBOSE
;
170 static const std::string ARG_JSON
;
171 static const std::string ARG_PATH
;
174 class FileChecksumDumpCommand
: public LDBCommand
{
176 static std::string
Name() { return "file_checksum_dump"; }
178 FileChecksumDumpCommand(const std::vector
<std::string
>& params
,
179 const std::map
<std::string
, std::string
>& options
,
180 const std::vector
<std::string
>& flags
);
182 static void Help(std::string
& ret
);
183 void DoCommand() override
;
185 bool NoDBOpen() override
{ return true; }
190 static const std::string ARG_PATH
;
193 class ListColumnFamiliesCommand
: public LDBCommand
{
195 static std::string
Name() { return "list_column_families"; }
197 ListColumnFamiliesCommand(const std::vector
<std::string
>& params
,
198 const std::map
<std::string
, std::string
>& options
,
199 const std::vector
<std::string
>& flags
);
201 static void Help(std::string
& ret
);
202 virtual void DoCommand() override
;
204 virtual bool NoDBOpen() override
{ return true; }
207 class CreateColumnFamilyCommand
: public LDBCommand
{
209 static std::string
Name() { return "create_column_family"; }
211 CreateColumnFamilyCommand(const std::vector
<std::string
>& params
,
212 const std::map
<std::string
, std::string
>& options
,
213 const std::vector
<std::string
>& flags
);
215 static void Help(std::string
& ret
);
216 virtual void DoCommand() override
;
218 virtual bool NoDBOpen() override
{ return false; }
221 std::string new_cf_name_
;
224 class DropColumnFamilyCommand
: public LDBCommand
{
226 static std::string
Name() { return "drop_column_family"; }
228 DropColumnFamilyCommand(const std::vector
<std::string
>& params
,
229 const std::map
<std::string
, std::string
>& options
,
230 const std::vector
<std::string
>& flags
);
232 static void Help(std::string
& ret
);
233 virtual void DoCommand() override
;
235 virtual bool NoDBOpen() override
{ return false; }
238 std::string cf_name_to_drop_
;
241 class ReduceDBLevelsCommand
: public LDBCommand
{
243 static std::string
Name() { return "reduce_levels"; }
245 ReduceDBLevelsCommand(const std::vector
<std::string
>& params
,
246 const std::map
<std::string
, std::string
>& options
,
247 const std::vector
<std::string
>& flags
);
249 virtual void OverrideBaseOptions() override
;
251 virtual void DoCommand() override
;
253 virtual bool NoDBOpen() override
{ return true; }
255 static void Help(std::string
& msg
);
257 static std::vector
<std::string
> PrepareArgs(const std::string
& db_path
,
259 bool print_old_level
= false);
264 bool print_old_levels_
;
266 static const std::string ARG_NEW_LEVELS
;
267 static const std::string ARG_PRINT_OLD_LEVELS
;
269 Status
GetOldNumOfLevels(Options
& opt
, int* levels
);
272 class ChangeCompactionStyleCommand
: public LDBCommand
{
274 static std::string
Name() { return "change_compaction_style"; }
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
);
281 virtual void OverrideBaseOptions() override
;
283 virtual void DoCommand() override
;
285 static void Help(std::string
& msg
);
288 int old_compaction_style_
;
289 int new_compaction_style_
;
291 static const std::string ARG_OLD_COMPACTION_STYLE
;
292 static const std::string ARG_NEW_COMPACTION_STYLE
;
295 class WALDumperCommand
: public LDBCommand
{
297 static std::string
Name() { return "dump_wal"; }
299 WALDumperCommand(const std::vector
<std::string
>& params
,
300 const std::map
<std::string
, std::string
>& options
,
301 const std::vector
<std::string
>& flags
);
303 virtual bool NoDBOpen() override
{ return true; }
305 static void Help(std::string
& ret
);
306 virtual void DoCommand() override
;
310 std::string wal_file_
;
312 bool is_write_committed_
; // default will be set to true
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
;
320 class GetCommand
: public LDBCommand
{
322 static std::string
Name() { return "get"; }
324 GetCommand(const std::vector
<std::string
>& params
,
325 const std::map
<std::string
, std::string
>& options
,
326 const std::vector
<std::string
>& flags
);
328 virtual void DoCommand() override
;
330 static void Help(std::string
& ret
);
336 class ApproxSizeCommand
: public LDBCommand
{
338 static std::string
Name() { return "approxsize"; }
340 ApproxSizeCommand(const std::vector
<std::string
>& params
,
341 const std::map
<std::string
, std::string
>& options
,
342 const std::vector
<std::string
>& flags
);
344 virtual void DoCommand() override
;
346 static void Help(std::string
& ret
);
349 std::string start_key_
;
350 std::string end_key_
;
353 class BatchPutCommand
: public LDBCommand
{
355 static std::string
Name() { return "batchput"; }
357 BatchPutCommand(const std::vector
<std::string
>& params
,
358 const std::map
<std::string
, std::string
>& options
,
359 const std::vector
<std::string
>& flags
);
361 virtual void DoCommand() override
;
363 static void Help(std::string
& ret
);
365 virtual void OverrideBaseOptions() override
;
369 * The key-values to be inserted.
371 std::vector
<std::pair
<std::string
, std::string
>> key_values_
;
374 class ScanCommand
: public LDBCommand
{
376 static std::string
Name() { return "scan"; }
378 ScanCommand(const std::vector
<std::string
>& params
,
379 const std::map
<std::string
, std::string
>& options
,
380 const std::vector
<std::string
>& flags
);
382 virtual void DoCommand() override
;
384 static void Help(std::string
& ret
);
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_
;
395 class DeleteCommand
: public LDBCommand
{
397 static std::string
Name() { return "delete"; }
399 DeleteCommand(const std::vector
<std::string
>& params
,
400 const std::map
<std::string
, std::string
>& options
,
401 const std::vector
<std::string
>& flags
);
403 virtual void DoCommand() override
;
405 static void Help(std::string
& ret
);
411 class DeleteRangeCommand
: public LDBCommand
{
413 static std::string
Name() { return "deleterange"; }
415 DeleteRangeCommand(const std::vector
<std::string
>& params
,
416 const std::map
<std::string
, std::string
>& options
,
417 const std::vector
<std::string
>& flags
);
419 virtual void DoCommand() override
;
421 static void Help(std::string
& ret
);
424 std::string begin_key_
;
425 std::string end_key_
;
428 class PutCommand
: public LDBCommand
{
430 static std::string
Name() { return "put"; }
432 PutCommand(const std::vector
<std::string
>& params
,
433 const std::map
<std::string
, std::string
>& options
,
434 const std::vector
<std::string
>& flags
);
436 virtual void DoCommand() override
;
438 static void Help(std::string
& ret
);
440 virtual void OverrideBaseOptions() override
;
448 * Command that starts up a REPL shell that allows
451 class DBQuerierCommand
: public LDBCommand
{
453 static std::string
Name() { return "query"; }
455 DBQuerierCommand(const std::vector
<std::string
>& params
,
456 const std::map
<std::string
, std::string
>& options
,
457 const std::vector
<std::string
>& flags
);
459 static void Help(std::string
& ret
);
461 virtual void DoCommand() override
;
464 static const char* HELP_CMD
;
465 static const char* GET_CMD
;
466 static const char* PUT_CMD
;
467 static const char* DELETE_CMD
;
470 class CheckConsistencyCommand
: public LDBCommand
{
472 static std::string
Name() { return "checkconsistency"; }
474 CheckConsistencyCommand(const std::vector
<std::string
>& params
,
475 const std::map
<std::string
, std::string
>& options
,
476 const std::vector
<std::string
>& flags
);
478 virtual void DoCommand() override
;
480 virtual bool NoDBOpen() override
{ return true; }
482 static void Help(std::string
& ret
);
485 class CheckPointCommand
: public LDBCommand
{
487 static std::string
Name() { return "checkpoint"; }
489 CheckPointCommand(const std::vector
<std::string
>& params
,
490 const std::map
<std::string
, std::string
>& options
,
491 const std::vector
<std::string
>& flags
);
493 virtual void DoCommand() override
;
495 static void Help(std::string
& ret
);
497 std::string checkpoint_dir_
;
499 static const std::string ARG_CHECKPOINT_DIR
;
502 class RepairCommand
: public LDBCommand
{
504 static std::string
Name() { return "repair"; }
506 RepairCommand(const std::vector
<std::string
>& params
,
507 const std::map
<std::string
, std::string
>& options
,
508 const std::vector
<std::string
>& flags
);
510 virtual void DoCommand() override
;
512 virtual bool NoDBOpen() override
{ return true; }
514 virtual void OverrideBaseOptions() override
;
516 static void Help(std::string
& ret
);
519 class BackupableCommand
: public LDBCommand
{
521 BackupableCommand(const std::vector
<std::string
>& params
,
522 const std::map
<std::string
, std::string
>& options
,
523 const std::vector
<std::string
>& flags
);
526 static void Help(const std::string
& name
, std::string
& ret
);
527 std::string backup_env_uri_
;
528 std::string backup_dir_
;
530 std::unique_ptr
<Logger
> logger_
;
531 std::shared_ptr
<Env
> backup_env_guard_
;
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
;
540 class BackupCommand
: public BackupableCommand
{
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
);
550 class RestoreCommand
: public BackupableCommand
{
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
);
561 class WriteExternalSstFilesCommand
: public LDBCommand
{
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
);
569 virtual void DoCommand() override
;
571 virtual bool NoDBOpen() override
{ return false; }
573 virtual void OverrideBaseOptions() override
;
575 static void Help(std::string
& ret
);
578 std::string output_sst_path_
;
581 class IngestExternalSstFilesCommand
: public LDBCommand
{
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
);
589 virtual void DoCommand() override
;
591 virtual bool NoDBOpen() override
{ return false; }
593 virtual void OverrideBaseOptions() override
;
595 static void Help(std::string
& ret
);
598 std::string input_sst_path_
;
600 bool snapshot_consistency_
;
601 bool allow_global_seqno_
;
602 bool allow_blocking_flush_
;
604 bool write_global_seqno_
;
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
;
614 // Command that prints out range delete tombstones in SST files.
615 class ListFileRangeDeletesCommand
: public LDBCommand
{
617 static std::string
Name() { return "list_file_range_deletes"; }
619 ListFileRangeDeletesCommand(const std::map
<std::string
, std::string
>& options
,
620 const std::vector
<std::string
>& flags
);
622 void DoCommand() override
;
624 static void Help(std::string
& ret
);
627 int max_keys_
= 1000;
630 // Command that removes the SST file forcibly from the manifest.
631 class UnsafeRemoveSstFileCommand
: public LDBCommand
{
633 static std::string
Name() { return "unsafe_remove_sst_file"; }
635 UnsafeRemoveSstFileCommand(const std::vector
<std::string
>& params
,
636 const std::map
<std::string
, std::string
>& options
,
637 const std::vector
<std::string
>& flags
);
639 static void Help(std::string
& ret
);
641 virtual void DoCommand() override
;
643 virtual bool NoDBOpen() override
{ return true; }
646 uint64_t sst_file_number_
;
649 } // namespace ROCKSDB_NAMESPACE