/Users/deen/code/yugabyte-db/src/yb/rocksdb/tools/ldb_tool.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under the BSD-style license found in the |
3 | | // LICENSE file in the root directory of this source tree. An additional grant |
4 | | // of patent rights can be found in the PATENTS file in the same directory. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | #ifndef ROCKSDB_LITE |
21 | | #include "yb/rocksdb/ldb_tool.h" |
22 | | #include "yb/rocksdb/tools/ldb_cmd.h" |
23 | | |
24 | | #include "yb/util/flag_tags.h" |
25 | | |
26 | | DEFINE_test_flag(bool, exit_on_finish, true, "Exit the process on finishing."); |
27 | | |
28 | | namespace rocksdb { |
29 | | |
30 | 24 | LDBOptions::LDBOptions() {} |
31 | | |
32 | | class LDBCommandRunner { |
33 | | public: |
34 | | |
35 | 0 | static void PrintHelp(const char* exec_name) { |
36 | 0 | string ret; |
37 | |
|
38 | 0 | ret.append("ldb - LevelDB Tool"); |
39 | 0 | ret.append("\n\n"); |
40 | 0 | ret.append("commands MUST specify --" + LDBCommand::ARG_DB + |
41 | 0 | "=<full_path_to_db_directory> when necessary\n"); |
42 | 0 | ret.append("\n"); |
43 | 0 | ret.append("The following optional parameters control if keys/values are " |
44 | 0 | "input/output as hex or as plain strings:\n"); |
45 | 0 | ret.append(" --" + LDBCommand::ARG_KEY_HEX + |
46 | 0 | " : Keys are input/output as hex\n"); |
47 | 0 | ret.append(" --" + LDBCommand::ARG_VALUE_HEX + |
48 | 0 | " : Values are input/output as hex\n"); |
49 | 0 | ret.append(" --" + LDBCommand::ARG_HEX + |
50 | 0 | " : Both keys and values are input/output as hex\n"); |
51 | 0 | ret.append( |
52 | 0 | " --" + LDBCommand::ARG_CF_NAME + |
53 | 0 | " : name of the column family to operate on. default: default column " |
54 | 0 | "family\n"); |
55 | 0 | ret.append("\n"); |
56 | |
|
57 | 0 | ret.append("The following optional parameters control the database " |
58 | 0 | "internals:\n"); |
59 | 0 | ret.append(" --" + LDBCommand::ARG_TTL + |
60 | 0 | " with 'put','get','scan','dump','query','batchput'" |
61 | 0 | " : DB supports ttl and value is internally timestamp-suffixed\n"); |
62 | 0 | ret.append(" --" + LDBCommand::ARG_BLOOM_BITS + "=<int,e.g.:14>\n"); |
63 | 0 | ret.append(" --" + LDBCommand::ARG_FIX_PREFIX_LEN + "=<int,e.g.:14>\n"); |
64 | 0 | ret.append(" --" + LDBCommand::ARG_COMPRESSION_TYPE + |
65 | 0 | "=<no|snappy|zlib|bzip2>\n"); |
66 | 0 | ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE + |
67 | 0 | "=<block_size_in_bytes>\n"); |
68 | 0 | ret.append(" --" + LDBCommand::ARG_AUTO_COMPACTION + "=<true|false>\n"); |
69 | 0 | ret.append(" --" + LDBCommand::ARG_DB_WRITE_BUFFER_SIZE + |
70 | 0 | "=<int,e.g.:16777216>\n"); |
71 | 0 | ret.append(" --" + LDBCommand::ARG_WRITE_BUFFER_SIZE + |
72 | 0 | "=<int,e.g.:4194304>\n"); |
73 | 0 | ret.append(" --" + LDBCommand::ARG_FILE_SIZE + "=<int,e.g.:2097152>\n"); |
74 | |
|
75 | 0 | ret.append("\n\n"); |
76 | 0 | ret.append("Data Access Commands:\n"); |
77 | 0 | PutCommand::Help(ret); |
78 | 0 | GetCommand::Help(ret); |
79 | 0 | BatchPutCommand::Help(ret); |
80 | 0 | ScanCommand::Help(ret); |
81 | 0 | DeleteCommand::Help(ret); |
82 | 0 | DBQuerierCommand::Help(ret); |
83 | 0 | ApproxSizeCommand::Help(ret); |
84 | 0 | CheckConsistencyCommand::Help(ret); |
85 | |
|
86 | 0 | ret.append("\n\n"); |
87 | 0 | ret.append("Admin Commands:\n"); |
88 | 0 | WALDumperCommand::Help(ret); |
89 | 0 | CompactorCommand::Help(ret); |
90 | 0 | ReduceDBLevelsCommand::Help(ret); |
91 | 0 | ChangeCompactionStyleCommand::Help(ret); |
92 | 0 | DBDumperCommand::Help(ret); |
93 | 0 | DBLoaderCommand::Help(ret); |
94 | 0 | ManifestDumpCommand::Help(ret); |
95 | 0 | ListColumnFamiliesCommand::Help(ret); |
96 | 0 | DBFileDumperCommand::Help(ret); |
97 | 0 | InternalDumpCommand::Help(ret); |
98 | |
|
99 | 0 | fprintf(stderr, "%s\n", ret.c_str()); |
100 | 0 | } |
101 | | |
102 | | static void RunCommand( |
103 | | int argc, char** argv, Options options, const LDBOptions& ldb_options, |
104 | 4 | const std::vector<ColumnFamilyDescriptor>* column_families) { |
105 | 4 | if (argc <= 2) { |
106 | 0 | PrintHelp(argv[0]); |
107 | 0 | exit(1); |
108 | 0 | } |
109 | | |
110 | 4 | LDBCommand* cmdObj = LDBCommand::InitFromCmdLineArgs( |
111 | 4 | argc, argv, options, ldb_options, column_families); |
112 | 4 | if (cmdObj == nullptr) { |
113 | 0 | fprintf(stderr, "Unknown command\n"); |
114 | 0 | PrintHelp(argv[0]); |
115 | 0 | exit(1); |
116 | 0 | } |
117 | | |
118 | 4 | if (!cmdObj->ValidateCmdLineOptions()) { |
119 | 0 | exit(1); |
120 | 0 | } |
121 | | |
122 | 4 | cmdObj->Run(); |
123 | 4 | LDBCommandExecuteResult ret = cmdObj->GetExecuteState(); |
124 | 4 | fprintf(stderr, "%s\n", ret.ToString().c_str()); |
125 | 4 | delete cmdObj; |
126 | | |
127 | 4 | if (FLAGS_TEST_exit_on_finish) { |
128 | 0 | exit(ret.IsFailed()); |
129 | 0 | } |
130 | 4 | } |
131 | | |
132 | | }; |
133 | | |
134 | | void LDBTool::Run(int argc, char** argv, Options options, |
135 | | const LDBOptions& ldb_options, |
136 | 4 | const std::vector<ColumnFamilyDescriptor>* column_families) { |
137 | 4 | LDBCommandRunner::RunCommand(argc, argv, options, ldb_options, |
138 | 4 | column_families); |
139 | 4 | } |
140 | | } // namespace rocksdb |
141 | | |
142 | | #endif // ROCKSDB_LITE |