2013-10-16 21:59:46 +00:00
|
|
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
2014-04-15 20:39:26 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
2014-04-15 18:29:02 +00:00
|
|
|
#include "rocksdb/ldb_tool.h"
|
|
|
|
#include "util/ldb_cmd.h"
|
2013-04-12 03:21:49 +00:00
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
namespace rocksdb {
|
2013-04-12 03:21:49 +00:00
|
|
|
|
|
|
|
class LDBCommandRunner {
|
|
|
|
public:
|
|
|
|
|
|
|
|
static void PrintHelp(const char* exec_name) {
|
|
|
|
string ret;
|
|
|
|
|
|
|
|
ret.append("ldb - LevelDB Tool");
|
|
|
|
ret.append("\n\n");
|
|
|
|
ret.append("commands MUST specify --" + LDBCommand::ARG_DB +
|
|
|
|
"=<full_path_to_db_directory> when necessary\n");
|
|
|
|
ret.append("\n");
|
|
|
|
ret.append("The following optional parameters control if keys/values are "
|
|
|
|
"input/output as hex or as plain strings:\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_KEY_HEX +
|
|
|
|
" : Keys are input/output as hex\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_VALUE_HEX +
|
|
|
|
" : Values are input/output as hex\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_HEX +
|
|
|
|
" : Both keys and values are input/output as hex\n");
|
|
|
|
ret.append("\n");
|
|
|
|
|
|
|
|
ret.append("The following optional parameters control the database "
|
|
|
|
"internals:\n");
|
2013-06-19 02:57:54 +00:00
|
|
|
ret.append(" --" + LDBCommand::ARG_TTL +
|
|
|
|
" with 'put','get','scan','dump','query','batchput'"
|
|
|
|
" : DB supports ttl and value is internally timestamp-suffixed\n");
|
2013-04-12 03:21:49 +00:00
|
|
|
ret.append(" --" + LDBCommand::ARG_BLOOM_BITS + "=<int,e.g.:14>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_COMPRESSION_TYPE +
|
|
|
|
"=<no|snappy|zlib|bzip2>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE +
|
|
|
|
"=<block_size_in_bytes>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_AUTO_COMPACTION + "=<true|false>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_WRITE_BUFFER_SIZE +
|
|
|
|
"=<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");
|
|
|
|
PutCommand::Help(ret);
|
|
|
|
GetCommand::Help(ret);
|
|
|
|
BatchPutCommand::Help(ret);
|
|
|
|
ScanCommand::Help(ret);
|
|
|
|
DeleteCommand::Help(ret);
|
|
|
|
DBQuerierCommand::Help(ret);
|
|
|
|
ApproxSizeCommand::Help(ret);
|
2014-03-20 20:42:45 +00:00
|
|
|
CheckConsistencyCommand::Help(ret);
|
2013-04-12 03:21:49 +00:00
|
|
|
|
|
|
|
ret.append("\n\n");
|
|
|
|
ret.append("Admin Commands:\n");
|
|
|
|
WALDumperCommand::Help(ret);
|
|
|
|
CompactorCommand::Help(ret);
|
|
|
|
ReduceDBLevelsCommand::Help(ret);
|
2013-09-04 20:13:08 +00:00
|
|
|
ChangeCompactionStyleCommand::Help(ret);
|
2013-04-12 03:21:49 +00:00
|
|
|
DBDumperCommand::Help(ret);
|
|
|
|
DBLoaderCommand::Help(ret);
|
|
|
|
ManifestDumpCommand::Help(ret);
|
2014-02-28 00:18:23 +00:00
|
|
|
ListColumnFamiliesCommand::Help(ret);
|
2013-06-20 23:02:36 +00:00
|
|
|
InternalDumpCommand::Help(ret);
|
2013-04-12 03:21:49 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "%s\n", ret.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RunCommand(int argc, char** argv, Options options) {
|
|
|
|
if (argc <= 2) {
|
|
|
|
PrintHelp(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
LDBCommand* cmdObj = LDBCommand::InitFromCmdLineArgs(argc, argv, options);
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void LDBTool::Run(int argc, char** argv, Options options) {
|
|
|
|
LDBCommandRunner::RunCommand(argc, argv, options);
|
|
|
|
}
|
2013-10-04 04:49:15 +00:00
|
|
|
} // namespace rocksdb
|
2013-04-12 03:21:49 +00:00
|
|
|
|
2014-04-15 20:39:26 +00:00
|
|
|
#endif // ROCKSDB_LITE
|