2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00: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 21:59:46 +00:00
|
|
|
//
|
2014-04-15 18:29:02 +00:00
|
|
|
#include "rocksdb/ldb_tool.h"
|
2022-10-25 21:29:41 +00:00
|
|
|
|
2016-05-06 23:09:09 +00:00
|
|
|
#include "rocksdb/utilities/ldb_cmd.h"
|
|
|
|
#include "tools/ldb_cmd_impl.h"
|
2013-04-12 03:21:49 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2013-04-12 03:21:49 +00:00
|
|
|
|
2023-12-01 19:15:17 +00:00
|
|
|
LDBOptions::LDBOptions() = default;
|
2014-06-20 06:54:13 +00:00
|
|
|
|
2017-03-22 00:22:10 +00:00
|
|
|
void LDBCommandRunner::PrintHelp(const LDBOptions& ldb_options,
|
2020-06-09 17:01:12 +00:00
|
|
|
const char* /*exec_name*/, bool to_stderr) {
|
2016-05-11 20:08:45 +00:00
|
|
|
std::string ret;
|
|
|
|
|
2017-03-22 00:22:10 +00:00
|
|
|
ret.append(ldb_options.print_help_header);
|
2016-05-11 20:08:45 +00:00
|
|
|
ret.append("\n\n");
|
|
|
|
ret.append("commands MUST specify --" + LDBCommand::ARG_DB +
|
|
|
|
"=<full_path_to_db_directory> when necessary\n");
|
|
|
|
ret.append("\n");
|
2022-02-17 01:06:33 +00:00
|
|
|
ret.append("commands can optionally specify\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_ENV_URI + "=<uri_of_environment> or --" +
|
|
|
|
LDBCommand::ARG_FS_URI + "=<uri_of_filesystem> if necessary");
|
|
|
|
ret.append("\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_SECONDARY_PATH +
|
|
|
|
"=<secondary_path> to open DB as secondary instance. Operations "
|
|
|
|
"not supported in secondary instance will fail.\n\n");
|
2016-05-11 20:08:45 +00: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 19:36:01 +00:00
|
|
|
ret.append(
|
|
|
|
" --" + LDBCommand::ARG_CF_NAME +
|
|
|
|
"=<string> : name of the column family to operate on. default: default "
|
|
|
|
"column family\n");
|
2016-05-11 20:08:45 +00: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 17:16:13 +00:00
|
|
|
ret.append(" --" + LDBCommand::ARG_TRY_LOAD_OPTIONS +
|
2022-05-04 15:49:46 +00:00
|
|
|
" : Try to load option file from DB. Default to true if " +
|
|
|
|
LDBCommand::ARG_DB +
|
|
|
|
" is specified and not creating a new DB and not open as TTL DB. "
|
|
|
|
"Can be set to false explicitly.\n");
|
2020-05-08 21:12:18 +00:00
|
|
|
ret.append(" --" + LDBCommand::ARG_DISABLE_CONSISTENCY_CHECKS +
|
|
|
|
" : Set options.force_consistency_checks = false.\n");
|
2017-06-13 23:55:08 +00:00
|
|
|
ret.append(" --" + LDBCommand::ARG_IGNORE_UNKNOWN_OPTIONS +
|
|
|
|
" : Ignore unknown options when loading option file.\n");
|
2016-05-11 20:08:45 +00: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 19:15:22 +00:00
|
|
|
"=<int,e.g.:16384>\n");
|
2016-05-11 20:08:45 +00: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");
|
2022-02-26 07:13:11 +00:00
|
|
|
ret.append(" --" + LDBCommand::ARG_ENABLE_BLOB_FILES +
|
|
|
|
" : Enable key-value separation using BlobDB\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_MIN_BLOB_SIZE + "=<int,e.g.:2097152>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_BLOB_FILE_SIZE + "=<int,e.g.:2097152>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_BLOB_COMPRESSION_TYPE +
|
|
|
|
"=<no|snappy|zlib|bzip2|lz4|lz4hc|xpress|zstd>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_ENABLE_BLOB_GARBAGE_COLLECTION +
|
|
|
|
" : Enable blob garbage collection\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_BLOB_GARBAGE_COLLECTION_AGE_CUTOFF +
|
|
|
|
"=<double,e.g.:0.25>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_BLOB_GARBAGE_COLLECTION_FORCE_THRESHOLD +
|
|
|
|
"=<double,e.g.:0.25>\n");
|
|
|
|
ret.append(" --" + LDBCommand::ARG_BLOB_COMPACTION_READAHEAD_SIZE +
|
|
|
|
"=<int,e.g.:2097152>\n");
|
2016-05-11 20:08:45 +00:00
|
|
|
|
|
|
|
ret.append("\n\n");
|
|
|
|
ret.append("Data Access Commands:\n");
|
|
|
|
PutCommand::Help(ret);
|
|
|
|
GetCommand::Help(ret);
|
2024-02-06 04:11:35 +00:00
|
|
|
MultiGetCommand::Help(ret);
|
2016-05-11 20:08:45 +00:00
|
|
|
BatchPutCommand::Help(ret);
|
|
|
|
ScanCommand::Help(ret);
|
|
|
|
DeleteCommand::Help(ret);
|
2023-05-31 21:24:54 +00:00
|
|
|
SingleDeleteCommand::Help(ret);
|
2016-11-15 23:49:15 +00:00
|
|
|
DeleteRangeCommand::Help(ret);
|
2016-05-11 20:08:45 +00:00
|
|
|
DBQuerierCommand::Help(ret);
|
|
|
|
ApproxSizeCommand::Help(ret);
|
|
|
|
CheckConsistencyCommand::Help(ret);
|
2019-08-15 23:59:42 +00:00
|
|
|
ListFileRangeDeletesCommand::Help(ret);
|
2016-05-11 20:08:45 +00: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);
|
2022-03-18 23:35:51 +00:00
|
|
|
UpdateManifestCommand::Help(ret);
|
2020-02-10 23:42:46 +00:00
|
|
|
FileChecksumDumpCommand::Help(ret);
|
2020-12-19 15:59:08 +00:00
|
|
|
GetPropertyCommand::Help(ret);
|
2016-05-11 20:08:45 +00:00
|
|
|
ListColumnFamiliesCommand::Help(ret);
|
2019-06-27 18:08:45 +00:00
|
|
|
CreateColumnFamilyCommand::Help(ret);
|
|
|
|
DropColumnFamilyCommand::Help(ret);
|
2016-05-11 20:08:45 +00:00
|
|
|
DBFileDumperCommand::Help(ret);
|
|
|
|
InternalDumpCommand::Help(ret);
|
Add list live files metadata (#8446)
Summary:
Add an argument to ldb to dump live file names, column families, and levels, `list_live_files_metadata`. The output shows all active SST file names, sorted first by column family and then by level. For each level the SST files are sorted alphabetically.
Typically, the output looks like this:
```
./ldb --db=/tmp/test_db list_live_files_metadata
Live SST Files:
===== Column Family: default =====
---------- level 0 ----------
/tmp/test_db/000069.sst
---------- level 1 ----------
/tmp/test_db/000064.sst
/tmp/test_db/000065.sst
/tmp/test_db/000066.sst
/tmp/test_db/000071.sst
---------- level 2 ----------
/tmp/test_db/000038.sst
/tmp/test_db/000039.sst
/tmp/test_db/000052.sst
/tmp/test_db/000067.sst
/tmp/test_db/000070.sst
------------------------------
```
Second, a flag was added `--sort_by_filename`, to change the layout of the output. When this flag is added to the command, the output shows all active SST files sorted by name, in front of which the LSM level and the column family are mentioned. With the same example, the following command would return:
```
./ldb --db=/tmp/test_db list_live_files_metadata --sort_by_filename
Live SST Files:
/tmp/test_db/000038.sst : level 2, column family 'default'
/tmp/test_db/000039.sst : level 2, column family 'default'
/tmp/test_db/000052.sst : level 2, column family 'default'
/tmp/test_db/000064.sst : level 1, column family 'default'
/tmp/test_db/000065.sst : level 1, column family 'default'
/tmp/test_db/000066.sst : level 1, column family 'default'
/tmp/test_db/000067.sst : level 2, column family 'default'
/tmp/test_db/000069.sst : level 0, column family 'default'
/tmp/test_db/000070.sst : level 2, column family 'default'
/tmp/test_db/000071.sst : level 1, column family 'default'
------------------------------
```
Thus, the user can either request to show the files by levels, or sorted by filenames.
This PR includes a simple Python unit test that makes sure the file name and level printed out by this new feature matches the one found with an existing feature, `dump_live_file`.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8446
Reviewed By: akankshamahajan15
Differential Revision: D29320080
Pulled By: bjlemaire
fbshipit-source-id: 01fb7b5637c59010d74c80730a28d815994e7009
2021-06-23 02:06:44 +00:00
|
|
|
DBLiveFilesMetadataDumperCommand::Help(ret);
|
2016-05-11 20:08:45 +00:00
|
|
|
RepairCommand::Help(ret);
|
2016-07-14 21:09:31 +00:00
|
|
|
BackupCommand::Help(ret);
|
2016-07-26 18:13:26 +00:00
|
|
|
RestoreCommand::Help(ret);
|
2017-03-21 18:49:08 +00:00
|
|
|
CheckPointCommand::Help(ret);
|
2018-08-09 21:18:59 +00:00
|
|
|
WriteExternalSstFilesCommand::Help(ret);
|
|
|
|
IngestExternalSstFilesCommand::Help(ret);
|
2020-09-03 23:53:14 +00:00
|
|
|
UnsafeRemoveSstFileCommand::Help(ret);
|
2016-05-11 20:08:45 +00:00
|
|
|
|
2020-06-09 17:01:12 +00:00
|
|
|
fprintf(to_stderr ? stderr : stdout, "%s\n", ret.c_str());
|
2016-05-11 20:08:45 +00:00
|
|
|
}
|
2013-04-12 03:21:49 +00:00
|
|
|
|
2019-08-15 23:59:42 +00:00
|
|
|
int LDBCommandRunner::RunCommand(
|
2020-06-09 17:01:12 +00:00
|
|
|
int argc, char const* const* argv, Options options,
|
|
|
|
const LDBOptions& ldb_options,
|
2016-05-11 20:08:45 +00:00
|
|
|
const std::vector<ColumnFamilyDescriptor>* column_families) {
|
|
|
|
if (argc <= 2) {
|
2020-07-09 17:18:52 +00:00
|
|
|
if (argc <= 1) {
|
|
|
|
PrintHelp(ldb_options, argv[0], /*to_stderr*/ true);
|
|
|
|
return 1;
|
|
|
|
} else if (std::string(argv[1]) == "--version") {
|
2020-06-09 17:01:12 +00:00
|
|
|
printf("ldb from RocksDB %d.%d.%d\n", ROCKSDB_MAJOR, ROCKSDB_MINOR,
|
|
|
|
ROCKSDB_PATCH);
|
|
|
|
return 0;
|
|
|
|
} else if (std::string(argv[1]) == "--help") {
|
|
|
|
PrintHelp(ldb_options, argv[0], /*to_stderr*/ false);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
PrintHelp(ldb_options, argv[0], /*to_stderr*/ true);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-04-12 03:21:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 20:08:45 +00:00
|
|
|
LDBCommand* cmdObj = LDBCommand::InitFromCmdLineArgs(
|
|
|
|
argc, argv, options, ldb_options, column_families);
|
|
|
|
if (cmdObj == nullptr) {
|
|
|
|
fprintf(stderr, "Unknown command\n");
|
2020-06-09 17:01:12 +00:00
|
|
|
PrintHelp(ldb_options, argv[0], /*to_stderr*/ true);
|
2019-08-15 23:59:42 +00:00
|
|
|
return 1;
|
2016-05-11 20:08:45 +00:00
|
|
|
}
|
2013-04-12 03:21:49 +00:00
|
|
|
|
2016-05-11 20:08:45 +00:00
|
|
|
if (!cmdObj->ValidateCmdLineOptions()) {
|
2019-08-15 23:59:42 +00:00
|
|
|
return 1;
|
2013-04-12 03:21:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 20:08:45 +00:00
|
|
|
cmdObj->Run();
|
|
|
|
LDBCommandExecuteResult ret = cmdObj->GetExecuteState();
|
2020-06-01 19:13:36 +00:00
|
|
|
if (!ret.ToString().empty()) {
|
|
|
|
fprintf(stderr, "%s\n", ret.ToString().c_str());
|
|
|
|
}
|
2016-05-11 20:08:45 +00:00
|
|
|
delete cmdObj;
|
|
|
|
|
2019-08-15 23:59:42 +00:00
|
|
|
return ret.IsFailed() ? 1 : 0;
|
2016-05-11 20:08:45 +00:00
|
|
|
}
|
2013-04-12 03:21:49 +00:00
|
|
|
|
2014-06-20 06:54:13 +00:00
|
|
|
void LDBTool::Run(int argc, char** argv, Options options,
|
2016-01-22 23:46:32 +00:00
|
|
|
const LDBOptions& ldb_options,
|
|
|
|
const std::vector<ColumnFamilyDescriptor>* column_families) {
|
2019-08-15 23:59:42 +00:00
|
|
|
int error_code = LDBCommandRunner::RunCommand(argc, argv, options,
|
|
|
|
ldb_options, column_families);
|
|
|
|
exit(error_code);
|
2013-04-12 03:21:49 +00:00
|
|
|
}
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|