[RocksDB] Improve manifest dump to print internal keys in hex for version edits.

Summary: Currently, VersionEdit::DebugString always display internal keys in the original ascii format. This could cause manifest dump to be truncated if internal keys contain special charactors (like null). Also added an option --input_key_hex for ldb idump to indicate that the passed in user keys are in hex.

Test Plan: run ldb manifest_dump

Reviewers: dhruba, emayanke

CC: leveldb

Differential Revision: https://reviews.facebook.net/D12111
main
Haobo Xu 11 years ago
parent 58a0ae06dc
commit 3a3b1c3e6c
  1. 8
      db/version_edit.cc
  2. 2
      db/version_edit.h
  3. 2
      db/version_set.cc
  4. 13
      util/ldb_cmd.cc
  5. 2
      util/ldb_cmd.h

@ -218,7 +218,7 @@ Status VersionEdit::DecodeFrom(const Slice& src) {
return result;
}
std::string VersionEdit::DebugString() const {
std::string VersionEdit::DebugString(bool hex_key) const {
std::string r;
r.append("VersionEdit {");
if (has_comparator_) {
@ -245,7 +245,7 @@ std::string VersionEdit::DebugString() const {
r.append("\n CompactPointer: ");
AppendNumberTo(&r, compact_pointers_[i].first);
r.append(" ");
r.append(compact_pointers_[i].second.DebugString());
r.append(compact_pointers_[i].second.DebugString(hex_key));
}
for (DeletedFileSet::const_iterator iter = deleted_files_.begin();
iter != deleted_files_.end();
@ -264,9 +264,9 @@ std::string VersionEdit::DebugString() const {
r.append(" ");
AppendNumberTo(&r, f.file_size);
r.append(" ");
r.append(f.smallest.DebugString());
r.append(f.smallest.DebugString(hex_key));
r.append(" .. ");
r.append(f.largest.DebugString());
r.append(f.largest.DebugString(hex_key));
}
r.append("\n}\n");
return r;

@ -89,7 +89,7 @@ class VersionEdit {
void EncodeTo(std::string* dst) const;
Status DecodeFrom(const Slice& src);
std::string DebugString() const;
std::string DebugString(bool hex_key = false) const;
private:
friend class VersionSet;

@ -1496,7 +1496,7 @@ Status VersionSet::DumpManifest(Options& options, std::string& dscname,
// Write out each individual edit
if (verbose) {
printf("*************************Edit[%d] = %s\n",
count, edit.DebugString().c_str());
count, edit.DebugString(hex).c_str());
}
count++;

@ -578,6 +578,7 @@ void PrintBucketCounts(const vector<uint64_t>& bucket_counts, int ttl_start,
const string InternalDumpCommand::ARG_COUNT_ONLY = "count_only";
const string InternalDumpCommand::ARG_STATS = "stats";
const string InternalDumpCommand::ARG_INPUT_KEY_HEX = "input_key_hex";
InternalDumpCommand::InternalDumpCommand(const vector<string>& params,
const map<string, string>& options,
@ -585,12 +586,14 @@ InternalDumpCommand::InternalDumpCommand(const vector<string>& params,
LDBCommand(options, flags, true,
BuildCmdLineOptions({ ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX,
ARG_FROM, ARG_TO, ARG_MAX_KEYS,
ARG_COUNT_ONLY, ARG_STATS})),
ARG_COUNT_ONLY, ARG_STATS,
ARG_INPUT_KEY_HEX})),
has_from_(false),
has_to_(false),
max_keys_(-1),
count_only_(false),
print_stats_(false) {
print_stats_(false),
is_input_key_hex_(false) {
has_from_ = ParseStringOption(options, ARG_FROM, &from_);
has_to_ = ParseStringOption(options, ARG_TO, &to_);
@ -599,8 +602,9 @@ InternalDumpCommand::InternalDumpCommand(const vector<string>& params,
print_stats_ = IsFlagPresent(flags, ARG_STATS);
count_only_ = IsFlagPresent(flags, ARG_COUNT_ONLY);
is_input_key_hex_ = IsFlagPresent(flags, ARG_INPUT_KEY_HEX);
if (is_key_hex_) {
if (is_input_key_hex_) {
if (has_from_) {
from_ = HexToString(from_);
}
@ -614,6 +618,7 @@ void InternalDumpCommand::Help(string& ret) {
ret.append(" ");
ret.append(InternalDumpCommand::Name());
ret.append(HelpRangeCmdArgs());
ret.append(" [--" + ARG_INPUT_KEY_HEX + "]");
ret.append(" [--" + ARG_MAX_KEYS + "=<N>]");
ret.append(" [--" + ARG_COUNT_ONLY + "]");
ret.append(" [--" + ARG_STATS + "]");
@ -674,7 +679,7 @@ void InternalDumpCommand::DoCommand() {
if (!count_only_) {
string key = ikey.DebugString(is_key_hex_);
string value = iter->value().ToString(is_value_hex_);
fprintf(stdout, "%s => %s\n", key.data(), value.data());
std::cout << key << " => " << value << "\n";
}
// Terminate if maximum number of keys have been dumped

@ -424,9 +424,11 @@ private:
int max_keys_;
bool count_only_;
bool print_stats_;
bool is_input_key_hex_;
static const string ARG_COUNT_ONLY;
static const string ARG_STATS;
static const string ARG_INPUT_KEY_HEX;
};
class DBLoaderCommand: public LDBCommand {

Loading…
Cancel
Save