[ldb] Export LDBCommandRunner

Summary:
The implementation remains where it is. Only the
header is exported. This is so that a customized
ldb tool can print help along with its own
extra commands

Test Plan: make ldb

Reviewers: sdong, IslamAbdelRahman

Reviewed By: IslamAbdelRahman

Subscribers: andrewkr, dhruba

Differential Revision: https://reviews.facebook.net/D57255
main
Arun Sharma 9 years ago
parent c1af07ce84
commit 49815e3841
  1. 9
      include/rocksdb/utilities/ldb_cmd.h
  2. 188
      tools/ldb_tool.cc

@ -230,6 +230,15 @@ class LDBCommand {
const std::vector<std::string>& flags); const std::vector<std::string>& flags);
}; };
class LDBCommandRunner {
public:
static void PrintHelp(const char* exec_name);
static void RunCommand(
int argc, char** argv, Options options, const LDBOptions& ldb_options,
const std::vector<ColumnFamilyDescriptor>* column_families);
};
} // namespace rocksdb } // namespace rocksdb
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE

@ -12,108 +12,104 @@ namespace rocksdb {
LDBOptions::LDBOptions() {} LDBOptions::LDBOptions() {}
class LDBCommandRunner { void LDBCommandRunner::PrintHelp(const char* exec_name) {
public: std::string ret;
static void PrintHelp(const char* exec_name) { ret.append("ldb - LevelDB Tool");
std::string ret; ret.append("\n\n");
ret.append("commands MUST specify --" + LDBCommand::ARG_DB +
ret.append("ldb - LevelDB Tool"); "=<full_path_to_db_directory> when necessary\n");
ret.append("\n\n"); ret.append("\n");
ret.append("commands MUST specify --" + LDBCommand::ARG_DB + ret.append(
"=<full_path_to_db_directory> when necessary\n"); "The following optional parameters control if keys/values are "
ret.append("\n"); "input/output as hex or as plain strings:\n");
ret.append("The following optional parameters control if keys/values are " ret.append(" --" + LDBCommand::ARG_KEY_HEX +
"input/output as hex or as plain strings:\n"); " : Keys are input/output as hex\n");
ret.append(" --" + LDBCommand::ARG_KEY_HEX + ret.append(" --" + LDBCommand::ARG_VALUE_HEX +
" : Keys are input/output as hex\n"); " : Values are input/output as hex\n");
ret.append(" --" + LDBCommand::ARG_VALUE_HEX + ret.append(" --" + LDBCommand::ARG_HEX +
" : Values are input/output as hex\n"); " : Both keys and values are input/output as hex\n");
ret.append(" --" + LDBCommand::ARG_HEX + ret.append(
" : Both keys and values are input/output as hex\n"); " --" + LDBCommand::ARG_CF_NAME +
ret.append( " : name of the column family to operate on. default: default column "
" --" + LDBCommand::ARG_CF_NAME + "family\n");
" : name of the column family to operate on. default: default column " ret.append("\n");
"family\n");
ret.append("\n"); ret.append(
"The following optional parameters control the database "
ret.append("The following optional parameters control the database " "internals:\n");
"internals:\n"); ret.append(" --" + LDBCommand::ARG_TTL +
ret.append(" --" + LDBCommand::ARG_TTL + " with 'put','get','scan','dump','query','batchput'"
" with 'put','get','scan','dump','query','batchput'" " : DB supports ttl and value is internally timestamp-suffixed\n");
" : DB supports ttl and value is internally timestamp-suffixed\n"); ret.append(" --" + LDBCommand::ARG_BLOOM_BITS + "=<int,e.g.:14>\n");
ret.append(" --" + LDBCommand::ARG_BLOOM_BITS + "=<int,e.g.:14>\n"); ret.append(" --" + LDBCommand::ARG_FIX_PREFIX_LEN + "=<int,e.g.:14>\n");
ret.append(" --" + LDBCommand::ARG_FIX_PREFIX_LEN + "=<int,e.g.:14>\n"); ret.append(" --" + LDBCommand::ARG_COMPRESSION_TYPE +
ret.append(" --" + LDBCommand::ARG_COMPRESSION_TYPE + "=<no|snappy|zlib|bzip2|lz4|lz4hc|xpress|zstd>\n");
"=<no|snappy|zlib|bzip2|lz4|lz4hc|xpress|zstd>\n"); ret.append(" --" + LDBCommand::ARG_COMPRESSION_MAX_DICT_BYTES +
ret.append(" --" + LDBCommand::ARG_COMPRESSION_MAX_DICT_BYTES + "=<int,e.g.:14>\n");
"=<int,e.g.:14>\n"); ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE + "=<block_size_in_bytes>\n");
ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE + ret.append(" --" + LDBCommand::ARG_AUTO_COMPACTION + "=<true|false>\n");
"=<block_size_in_bytes>\n"); ret.append(" --" + LDBCommand::ARG_DB_WRITE_BUFFER_SIZE +
ret.append(" --" + LDBCommand::ARG_AUTO_COMPACTION + "=<true|false>\n"); "=<int,e.g.:16777216>\n");
ret.append(" --" + LDBCommand::ARG_DB_WRITE_BUFFER_SIZE + ret.append(" --" + LDBCommand::ARG_WRITE_BUFFER_SIZE +
"=<int,e.g.:16777216>\n"); "=<int,e.g.:4194304>\n");
ret.append(" --" + LDBCommand::ARG_WRITE_BUFFER_SIZE + ret.append(" --" + LDBCommand::ARG_FILE_SIZE + "=<int,e.g.:2097152>\n");
"=<int,e.g.:4194304>\n");
ret.append(" --" + LDBCommand::ARG_FILE_SIZE + "=<int,e.g.:2097152>\n"); ret.append("\n\n");
ret.append("Data Access Commands:\n");
ret.append("\n\n"); PutCommand::Help(ret);
ret.append("Data Access Commands:\n"); GetCommand::Help(ret);
PutCommand::Help(ret); BatchPutCommand::Help(ret);
GetCommand::Help(ret); ScanCommand::Help(ret);
BatchPutCommand::Help(ret); DeleteCommand::Help(ret);
ScanCommand::Help(ret); DBQuerierCommand::Help(ret);
DeleteCommand::Help(ret); ApproxSizeCommand::Help(ret);
DBQuerierCommand::Help(ret); CheckConsistencyCommand::Help(ret);
ApproxSizeCommand::Help(ret);
CheckConsistencyCommand::Help(ret); ret.append("\n\n");
ret.append("Admin Commands:\n");
ret.append("\n\n"); WALDumperCommand::Help(ret);
ret.append("Admin Commands:\n"); CompactorCommand::Help(ret);
WALDumperCommand::Help(ret); ReduceDBLevelsCommand::Help(ret);
CompactorCommand::Help(ret); ChangeCompactionStyleCommand::Help(ret);
ReduceDBLevelsCommand::Help(ret); DBDumperCommand::Help(ret);
ChangeCompactionStyleCommand::Help(ret); DBLoaderCommand::Help(ret);
DBDumperCommand::Help(ret); ManifestDumpCommand::Help(ret);
DBLoaderCommand::Help(ret); ListColumnFamiliesCommand::Help(ret);
ManifestDumpCommand::Help(ret); DBFileDumperCommand::Help(ret);
ListColumnFamiliesCommand::Help(ret); InternalDumpCommand::Help(ret);
DBFileDumperCommand::Help(ret); RepairCommand::Help(ret);
InternalDumpCommand::Help(ret);
RepairCommand::Help(ret); fprintf(stderr, "%s\n", ret.c_str());
}
fprintf(stderr, "%s\n", ret.c_str()); void LDBCommandRunner::RunCommand(
int argc, char** argv, Options options, const LDBOptions& ldb_options,
const std::vector<ColumnFamilyDescriptor>* column_families) {
if (argc <= 2) {
PrintHelp(argv[0]);
exit(1);
} }
static void RunCommand( LDBCommand* cmdObj = LDBCommand::InitFromCmdLineArgs(
int argc, char** argv, Options options, const LDBOptions& ldb_options, argc, argv, options, ldb_options, column_families);
const std::vector<ColumnFamilyDescriptor>* column_families) { if (cmdObj == nullptr) {
if (argc <= 2) { fprintf(stderr, "Unknown command\n");
PrintHelp(argv[0]); PrintHelp(argv[0]);
exit(1); exit(1);
} }
LDBCommand* cmdObj = LDBCommand::InitFromCmdLineArgs(
argc, argv, options, ldb_options, column_families);
if (cmdObj == nullptr) {
fprintf(stderr, "Unknown command\n");
PrintHelp(argv[0]);
exit(1);
}
if (!cmdObj->ValidateCmdLineOptions()) {
exit(1);
}
cmdObj->Run();
LDBCommandExecuteResult ret = cmdObj->GetExecuteState();
fprintf(stderr, "%s\n", ret.ToString().c_str());
delete cmdObj;
exit(ret.IsFailed()); if (!cmdObj->ValidateCmdLineOptions()) {
exit(1);
} }
}; cmdObj->Run();
LDBCommandExecuteResult ret = cmdObj->GetExecuteState();
fprintf(stderr, "%s\n", ret.ToString().c_str());
delete cmdObj;
exit(ret.IsFailed());
}
void LDBTool::Run(int argc, char** argv, Options options, void LDBTool::Run(int argc, char** argv, Options options,
const LDBOptions& ldb_options, const LDBOptions& ldb_options,

Loading…
Cancel
Save