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