Support --hex flag in ldb file_checksum_dump
(#7820)
Summary: Prior to this PR it prints the raw bytes which can include non-printable characters. This PR adds the option to print in hex instead. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7820 Test Plan: try it out ``` $ ./ldb file_checksum_dump --hex --db=/tmp/rocksdbtest-9383//db_basic_test_12281129388755189514/ 16, FileChecksumCrc32c, 0xC789D948 ``` Reviewed By: jay-zhuang Differential Revision: D25738072 Pulled By: ajkr fbshipit-source-id: 8cf2856877971756c0495cfa63a9a1281c414dc7
This commit is contained in:
parent
0bad2b4308
commit
b8c01ed38a
@ -1221,7 +1221,8 @@ FileChecksumDumpCommand::FileChecksumDumpCommand(
|
||||
const std::vector<std::string>& /*params*/,
|
||||
const std::map<std::string, std::string>& options,
|
||||
const std::vector<std::string>& flags)
|
||||
: LDBCommand(options, flags, false, BuildCmdLineOptions({ARG_PATH})),
|
||||
: LDBCommand(options, flags, false,
|
||||
BuildCmdLineOptions({ARG_PATH, ARG_HEX})),
|
||||
path_("") {
|
||||
std::map<std::string, std::string>::const_iterator itr =
|
||||
options.find(ARG_PATH);
|
||||
@ -1231,6 +1232,7 @@ FileChecksumDumpCommand::FileChecksumDumpCommand(
|
||||
exec_state_ = LDBCommandExecuteResult::Failed("--path: missing pathname");
|
||||
}
|
||||
}
|
||||
is_checksum_hex_ = IsFlagPresent(flags, ARG_HEX);
|
||||
}
|
||||
|
||||
void FileChecksumDumpCommand::DoCommand() {
|
||||
@ -1253,8 +1255,14 @@ void FileChecksumDumpCommand::DoCommand() {
|
||||
assert(i < file_numbers.size());
|
||||
assert(i < checksums.size());
|
||||
assert(i < checksum_func_names.size());
|
||||
std::string checksum;
|
||||
if (is_checksum_hex_) {
|
||||
checksum = StringToHex(checksums[i]);
|
||||
} else {
|
||||
checksum = std::move(checksums[i]);
|
||||
}
|
||||
fprintf(stdout, "%" PRId64 ", %s, %s\n", file_numbers[i],
|
||||
checksum_func_names[i].c_str(), checksums[i].c_str());
|
||||
checksum_func_names[i].c_str(), checksum.c_str());
|
||||
}
|
||||
}
|
||||
fprintf(stdout, "Print SST file checksum information finished \n");
|
||||
|
@ -186,6 +186,7 @@ class FileChecksumDumpCommand : public LDBCommand {
|
||||
|
||||
private:
|
||||
std::string path_;
|
||||
bool is_checksum_hex_;
|
||||
|
||||
static const std::string ARG_PATH;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user