2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2013-10-16 23:59:46 +02:00
|
|
|
//
|
2014-04-15 22:39:26 +02:00
|
|
|
#ifndef ROCKSDB_LITE
|
2014-04-15 20:29:02 +02:00
|
|
|
#include "rocksdb/ldb_tool.h"
|
2016-05-07 01:09:09 +02:00
|
|
|
#include "rocksdb/utilities/ldb_cmd.h"
|
|
|
|
#include "tools/ldb_cmd_impl.h"
|
2013-04-12 05:21:49 +02:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2013-04-12 05:21:49 +02:00
|
|
|
|
2015-11-20 07:26:37 +01:00
|
|
|
LDBOptions::LDBOptions() {}
|
2014-06-20 08:54:13 +02:00
|
|
|
|
2017-03-22 01:22:10 +01:00
|
|
|
void LDBCommandRunner::PrintHelp(const LDBOptions& ldb_options,
|
2018-03-05 22:08:17 +01:00
|
|
|
const char* /*exec_name*/) {
|
2016-05-11 22:08:45 +02:00
|
|
|
std::string ret;
|
|
|
|
|
2017-03-22 01:22:10 +01:00
|
|
|
ret.append(ldb_options.print_help_header);
|
2016-05-11 22:08:45 +02:00
|
|
|
ret.append("\n\n");
|
|
|
|
ret.append("commands MUST specify --" + LDBCommand::ARG_DB +
|
|
|
|
"=<full_path_to_db_directory> when necessary\n");
|
|
|
|
ret.append("\n");
|
2019-10-09 04:17:39 +02:00
|
|
|
ret.append("commands can optionally specify --" + LDBCommand::ARG_ENV_URI +
|
|
|
|
"=<uri_of_environment> if necessary\n\n");
|
2016-05-11 22:08:45 +02:00
|
|
|
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");
|
2017-02-07 20:36:01 +01:00
|
|
|
ret.append(
|
|
|
|
" --" + LDBCommand::ARG_CF_NAME +
|
|
|
|
"=<string> : name of the column family to operate on. default: default "
|
|
|
|
"column family\n");
|
2016-05-11 22:08:45 +02:00
|
|
|
ret.append(" --" + LDBCommand::ARG_TTL +
|
|
|
|
" with 'put','get','scan','dump','query','batchput'"
|
|
|
|
" : DB supports ttl and value is internally timestamp-suffixed\n");
|
2017-04-20 19:16:13 +02:00
|
|
|
ret.append(" --" + LDBCommand::ARG_TRY_LOAD_OPTIONS +
|
|
|
|
" : Try to load option file from DB.\n");
|
2020-05-08 23:12:18 +02:00
|
|
|
ret.append(" --" + LDBCommand::ARG_DISABLE_CONSISTENCY_CHECKS +
|
|
|
|
" : Set options.force_consistency_checks = false.\n");
|
2017-06-14 01:55:08 +02:00
|
|
|
ret.append(" --" + LDBCommand::ARG_IGNORE_UNKNOWN_OPTIONS +
|
|
|
|
" : Ignore unknown options when loading option file.\n");
|
2016-05-11 22:08:45 +02:00
|
|
|
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_COMPRESSION_TYPE +
|
|
|
|
"=<no|snappy|zlib|bzip2|lz4|lz4hc|xpress|zstd>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_COMPRESSION_MAX_DICT_BYTES +
|
2016-11-09 20:15:22 +01:00
|
|
|
"=<int,e.g.:16384>\n");
|
2016-05-11 22:08:45 +02:00
|
|
|
ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE + "=<block_size_in_bytes>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_AUTO_COMPACTION + "=<true|false>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_DB_WRITE_BUFFER_SIZE +
|
|
|
|
"=<int,e.g.:16777216>\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);
|
2016-11-16 00:49:15 +01:00
|
|
|
DeleteRangeCommand::Help(ret);
|
2016-05-11 22:08:45 +02:00
|
|
|
DBQuerierCommand::Help(ret);
|
|
|
|
ApproxSizeCommand::Help(ret);
|
|
|
|
CheckConsistencyCommand::Help(ret);
|
2019-08-16 01:59:42 +02:00
|
|
|
ListFileRangeDeletesCommand::Help(ret);
|
2016-05-11 22:08:45 +02:00
|
|
|
|
|
|
|
ret.append("\n\n");
|
|
|
|
ret.append("Admin Commands:\n");
|
|
|
|
WALDumperCommand::Help(ret);
|
|
|
|
CompactorCommand::Help(ret);
|
|
|
|
ReduceDBLevelsCommand::Help(ret);
|
|
|
|
ChangeCompactionStyleCommand::Help(ret);
|
|
|
|
DBDumperCommand::Help(ret);
|
|
|
|
DBLoaderCommand::Help(ret);
|
|
|
|
ManifestDumpCommand::Help(ret);
|
2020-02-11 00:42:46 +01:00
|
|
|
FileChecksumDumpCommand::Help(ret);
|
2016-05-11 22:08:45 +02:00
|
|
|
ListColumnFamiliesCommand::Help(ret);
|
2019-06-27 20:08:45 +02:00
|
|
|
CreateColumnFamilyCommand::Help(ret);
|
|
|
|
DropColumnFamilyCommand::Help(ret);
|
2016-05-11 22:08:45 +02:00
|
|
|
DBFileDumperCommand::Help(ret);
|
|
|
|
InternalDumpCommand::Help(ret);
|
|
|
|
RepairCommand::Help(ret);
|
2016-07-14 23:09:31 +02:00
|
|
|
BackupCommand::Help(ret);
|
2016-07-26 20:13:26 +02:00
|
|
|
RestoreCommand::Help(ret);
|
2017-03-21 19:49:08 +01:00
|
|
|
CheckPointCommand::Help(ret);
|
2018-08-09 23:18:59 +02:00
|
|
|
WriteExternalSstFilesCommand::Help(ret);
|
|
|
|
IngestExternalSstFilesCommand::Help(ret);
|
2016-05-11 22:08:45 +02:00
|
|
|
|
|
|
|
fprintf(stderr, "%s\n", ret.c_str());
|
|
|
|
}
|
2013-04-12 05:21:49 +02:00
|
|
|
|
2019-08-16 01:59:42 +02:00
|
|
|
int LDBCommandRunner::RunCommand(
|
2016-05-11 22:08:45 +02:00
|
|
|
int argc, char** argv, Options options, const LDBOptions& ldb_options,
|
|
|
|
const std::vector<ColumnFamilyDescriptor>* column_families) {
|
|
|
|
if (argc <= 2) {
|
2017-03-22 01:22:10 +01:00
|
|
|
PrintHelp(ldb_options, argv[0]);
|
2019-08-16 01:59:42 +02:00
|
|
|
return 1;
|
2013-04-12 05:21:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 22:08:45 +02:00
|
|
|
LDBCommand* cmdObj = LDBCommand::InitFromCmdLineArgs(
|
|
|
|
argc, argv, options, ldb_options, column_families);
|
|
|
|
if (cmdObj == nullptr) {
|
|
|
|
fprintf(stderr, "Unknown command\n");
|
2017-03-22 01:22:10 +01:00
|
|
|
PrintHelp(ldb_options, argv[0]);
|
2019-08-16 01:59:42 +02:00
|
|
|
return 1;
|
2016-05-11 22:08:45 +02:00
|
|
|
}
|
2013-04-12 05:21:49 +02:00
|
|
|
|
2016-05-11 22:08:45 +02:00
|
|
|
if (!cmdObj->ValidateCmdLineOptions()) {
|
2019-08-16 01:59:42 +02:00
|
|
|
return 1;
|
2013-04-12 05:21:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 22:08:45 +02:00
|
|
|
cmdObj->Run();
|
|
|
|
LDBCommandExecuteResult ret = cmdObj->GetExecuteState();
|
2020-06-01 21:13:36 +02:00
|
|
|
if (!ret.ToString().empty()) {
|
|
|
|
fprintf(stderr, "%s\n", ret.ToString().c_str());
|
|
|
|
}
|
2016-05-11 22:08:45 +02:00
|
|
|
delete cmdObj;
|
|
|
|
|
2019-08-16 01:59:42 +02:00
|
|
|
return ret.IsFailed() ? 1 : 0;
|
2016-05-11 22:08:45 +02:00
|
|
|
}
|
2013-04-12 05:21:49 +02:00
|
|
|
|
2014-06-20 08:54:13 +02:00
|
|
|
void LDBTool::Run(int argc, char** argv, Options options,
|
2016-01-23 00:46:32 +01:00
|
|
|
const LDBOptions& ldb_options,
|
|
|
|
const std::vector<ColumnFamilyDescriptor>* column_families) {
|
2019-08-16 01:59:42 +02:00
|
|
|
int error_code = LDBCommandRunner::RunCommand(argc, argv, options,
|
|
|
|
ldb_options, column_families);
|
|
|
|
exit(error_code);
|
2013-04-12 05:21:49 +02:00
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2013-04-12 05:21:49 +02:00
|
|
|
|
2014-04-15 22:39:26 +02:00
|
|
|
#endif // ROCKSDB_LITE
|