ldb_tool.cc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #ifndef ROCKSDB_LITE
  7. #include "rocksdb/ldb_tool.h"
  8. #include "rocksdb/utilities/ldb_cmd.h"
  9. #include "tools/ldb_cmd_impl.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. LDBOptions::LDBOptions() {}
  12. void LDBCommandRunner::PrintHelp(const LDBOptions& ldb_options,
  13. const char* /*exec_name*/) {
  14. std::string ret;
  15. ret.append(ldb_options.print_help_header);
  16. ret.append("\n\n");
  17. ret.append("commands MUST specify --" + LDBCommand::ARG_DB +
  18. "=<full_path_to_db_directory> when necessary\n");
  19. ret.append("\n");
  20. ret.append("commands can optionally specify --" + LDBCommand::ARG_ENV_URI +
  21. "=<uri_of_environment> if necessary\n\n");
  22. ret.append(
  23. "The following optional parameters control if keys/values are "
  24. "input/output as hex or as plain strings:\n");
  25. ret.append(" --" + LDBCommand::ARG_KEY_HEX +
  26. " : Keys are input/output as hex\n");
  27. ret.append(" --" + LDBCommand::ARG_VALUE_HEX +
  28. " : Values are input/output as hex\n");
  29. ret.append(" --" + LDBCommand::ARG_HEX +
  30. " : Both keys and values are input/output as hex\n");
  31. ret.append("\n");
  32. ret.append(
  33. "The following optional parameters control the database "
  34. "internals:\n");
  35. ret.append(
  36. " --" + LDBCommand::ARG_CF_NAME +
  37. "=<string> : name of the column family to operate on. default: default "
  38. "column family\n");
  39. ret.append(" --" + LDBCommand::ARG_TTL +
  40. " with 'put','get','scan','dump','query','batchput'"
  41. " : DB supports ttl and value is internally timestamp-suffixed\n");
  42. ret.append(" --" + LDBCommand::ARG_TRY_LOAD_OPTIONS +
  43. " : Try to load option file from DB.\n");
  44. ret.append(" --" + LDBCommand::ARG_IGNORE_UNKNOWN_OPTIONS +
  45. " : Ignore unknown options when loading option file.\n");
  46. ret.append(" --" + LDBCommand::ARG_BLOOM_BITS + "=<int,e.g.:14>\n");
  47. ret.append(" --" + LDBCommand::ARG_FIX_PREFIX_LEN + "=<int,e.g.:14>\n");
  48. ret.append(" --" + LDBCommand::ARG_COMPRESSION_TYPE +
  49. "=<no|snappy|zlib|bzip2|lz4|lz4hc|xpress|zstd>\n");
  50. ret.append(" --" + LDBCommand::ARG_COMPRESSION_MAX_DICT_BYTES +
  51. "=<int,e.g.:16384>\n");
  52. ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE + "=<block_size_in_bytes>\n");
  53. ret.append(" --" + LDBCommand::ARG_AUTO_COMPACTION + "=<true|false>\n");
  54. ret.append(" --" + LDBCommand::ARG_DB_WRITE_BUFFER_SIZE +
  55. "=<int,e.g.:16777216>\n");
  56. ret.append(" --" + LDBCommand::ARG_WRITE_BUFFER_SIZE +
  57. "=<int,e.g.:4194304>\n");
  58. ret.append(" --" + LDBCommand::ARG_FILE_SIZE + "=<int,e.g.:2097152>\n");
  59. ret.append("\n\n");
  60. ret.append("Data Access Commands:\n");
  61. PutCommand::Help(ret);
  62. GetCommand::Help(ret);
  63. BatchPutCommand::Help(ret);
  64. ScanCommand::Help(ret);
  65. DeleteCommand::Help(ret);
  66. DeleteRangeCommand::Help(ret);
  67. DBQuerierCommand::Help(ret);
  68. ApproxSizeCommand::Help(ret);
  69. CheckConsistencyCommand::Help(ret);
  70. ListFileRangeDeletesCommand::Help(ret);
  71. ret.append("\n\n");
  72. ret.append("Admin Commands:\n");
  73. WALDumperCommand::Help(ret);
  74. CompactorCommand::Help(ret);
  75. ReduceDBLevelsCommand::Help(ret);
  76. ChangeCompactionStyleCommand::Help(ret);
  77. DBDumperCommand::Help(ret);
  78. DBLoaderCommand::Help(ret);
  79. ManifestDumpCommand::Help(ret);
  80. FileChecksumDumpCommand::Help(ret);
  81. ListColumnFamiliesCommand::Help(ret);
  82. CreateColumnFamilyCommand::Help(ret);
  83. DropColumnFamilyCommand::Help(ret);
  84. DBFileDumperCommand::Help(ret);
  85. InternalDumpCommand::Help(ret);
  86. RepairCommand::Help(ret);
  87. BackupCommand::Help(ret);
  88. RestoreCommand::Help(ret);
  89. CheckPointCommand::Help(ret);
  90. WriteExternalSstFilesCommand::Help(ret);
  91. IngestExternalSstFilesCommand::Help(ret);
  92. fprintf(stderr, "%s\n", ret.c_str());
  93. }
  94. int LDBCommandRunner::RunCommand(
  95. int argc, char** argv, Options options, const LDBOptions& ldb_options,
  96. const std::vector<ColumnFamilyDescriptor>* column_families) {
  97. if (argc <= 2) {
  98. PrintHelp(ldb_options, argv[0]);
  99. return 1;
  100. }
  101. LDBCommand* cmdObj = LDBCommand::InitFromCmdLineArgs(
  102. argc, argv, options, ldb_options, column_families);
  103. if (cmdObj == nullptr) {
  104. fprintf(stderr, "Unknown command\n");
  105. PrintHelp(ldb_options, argv[0]);
  106. return 1;
  107. }
  108. if (!cmdObj->ValidateCmdLineOptions()) {
  109. return 1;
  110. }
  111. cmdObj->Run();
  112. LDBCommandExecuteResult ret = cmdObj->GetExecuteState();
  113. fprintf(stderr, "%s\n", ret.ToString().c_str());
  114. delete cmdObj;
  115. return ret.IsFailed() ? 1 : 0;
  116. }
  117. void LDBTool::Run(int argc, char** argv, Options options,
  118. const LDBOptions& ldb_options,
  119. const std::vector<ColumnFamilyDescriptor>* column_families) {
  120. int error_code = LDBCommandRunner::RunCommand(argc, argv, options,
  121. ldb_options, column_families);
  122. exit(error_code);
  123. }
  124. } // namespace ROCKSDB_NAMESPACE
  125. #endif // ROCKSDB_LITE