manifest_dump: Add --hex=1 option

Summary: Without this option, manifest_dump does not print binary keys for files in a human-readable way.

Test Plan:
./manifest_dump --hex=1 --verbose=0 --file=/data/users/zshao/fdb_comparison/leveldb/fbobj.apprequest-0_0_original/MANIFEST-000002
manifest_file_number 589 next_file_number 590 last_sequence 2311567 log_number 543  prev_log_number 0
--- level 0 --- version# 0 ---
 532:1300357['0000455BABE20000' @ 2183973 : 1 .. 'FFFCA5D7ADE20000' @ 2184254 : 1]
 536:1308170['000198C75CE30000' @ 2203313 : 1 .. 'FFFCF94A79E30000' @ 2206463 : 1]
 542:1321644['0002931AA5E50000' @ 2267055 : 1 .. 'FFF77B31C5E50000' @ 2270754 : 1]
 544:1286390['000410A309E60000' @ 2278592 : 1 .. 'FFFE470A73E60000' @ 2289221 : 1]
 538:1298778['0006BCF4D8E30000' @ 2217050 : 1 .. 'FFFD77DAF7E30000' @ 2220489 : 1]
 540:1282353['00090D5356E40000' @ 2231156 : 1 .. 'FFFFF4625CE40000' @ 2231969 : 1]
--- level 1 --- version# 0 ---
 510:2112325['000007F9C2D40000' @ 1782099 : 1 .. '146F5B67B8D80000' @ 1905458 : 1]
 511:2121742['146F8A3023D60000' @ 1824388 : 1 .. '28BC8FBB9CD40000' @ 1777993 : 1]
 512:801631['28BCD396F1DE0000' @ 2080191 : 1 .. '3082DBE9ADDB0000' @ 1989927 : 1]

Reviewers: dhruba, sheki, emayanke

Reviewed By: dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D7425
main
Zheng Shao 12 years ago
parent 806d4d9346
commit c28097538a
  1. 8
      db/dbformat.cc
  2. 4
      db/dbformat.h
  3. 10
      db/version_set.cc
  4. 4
      db/version_set.h
  5. 14
      include/leveldb/slice.h
  6. 6
      tools/manifest_dump.cc

@ -20,22 +20,22 @@ void AppendInternalKey(std::string* result, const ParsedInternalKey& key) {
PutFixed64(result, PackSequenceAndType(key.sequence, key.type));
}
std::string ParsedInternalKey::DebugString() const {
std::string ParsedInternalKey::DebugString(bool hex) const {
char buf[50];
snprintf(buf, sizeof(buf), "' @ %llu : %d",
(unsigned long long) sequence,
int(type));
std::string result = "'";
result += user_key.ToString();
result += user_key.ToString(hex);
result += buf;
return result;
}
std::string InternalKey::DebugString() const {
std::string InternalKey::DebugString(bool hex) const {
std::string result;
ParsedInternalKey parsed;
if (ParseInternalKey(rep_, &parsed)) {
result = parsed.DebugString();
result = parsed.DebugString(hex);
} else {
result = "(bad)";
result.append(EscapeString(rep_));

@ -47,7 +47,7 @@ struct ParsedInternalKey {
ParsedInternalKey() { } // Intentionally left uninitialized (for speed)
ParsedInternalKey(const Slice& u, const SequenceNumber& seq, ValueType t)
: user_key(u), sequence(seq), type(t) { }
std::string DebugString() const;
std::string DebugString(bool hex = false) const;
};
// Return the length of the encoding of "key".
@ -137,7 +137,7 @@ class InternalKey {
void Clear() { rep_.clear(); }
std::string DebugString() const;
std::string DebugString(bool hex = false) const;
};
inline int InternalKeyComparator::Compare(

@ -612,7 +612,7 @@ void Version::ExtendOverlappingInputs(
}
}
std::string Version::DebugString() const {
std::string Version::DebugString(bool hex) const {
std::string r;
for (int level = 0; level < vset_->NumberLevels(); level++) {
// E.g.,
@ -631,9 +631,9 @@ std::string Version::DebugString() const {
r.push_back(':');
AppendNumberTo(&r, files[i]->file_size);
r.append("[");
r.append(files[i]->smallest.DebugString());
r.append(files[i]->smallest.DebugString(hex));
r.append(" .. ");
r.append(files[i]->largest.DebugString());
r.append(files[i]->largest.DebugString(hex));
r.append("]\n");
}
}
@ -1233,7 +1233,7 @@ Status VersionSet::Recover() {
}
Status VersionSet::DumpManifest(Options& options, std::string& dscname,
bool verbose) {
bool verbose, bool hex) {
struct LogReporter : public log::Reader::Reporter {
Status* status;
virtual void Corruption(size_t bytes, const Status& s) {
@ -1347,7 +1347,7 @@ Status VersionSet::DumpManifest(Options& options, std::string& dscname,
printf("manifest_file_number %ld next_file_number %ld last_sequence %ld log_number %ld prev_log_number %ld\n",
manifest_file_number_, next_file_number_,
last_sequence, log_number, prev_log_number);
printf("%s \n", v->DebugString().c_str());
printf("%s \n", v->DebugString(hex).c_str());
}
return s;

@ -123,7 +123,7 @@ class Version {
int NumFiles(int level) const { return files_[level].size(); }
// Return a human readable string that describes this version's contents.
std::string DebugString() const;
std::string DebugString(bool hex = false) const;
// Returns the version nuber of this version
uint64_t GetVersionNumber() {
@ -334,7 +334,7 @@ class VersionSet {
// printf contents (for debugging)
Status DumpManifest(Options& options, std::string& manifestFileName,
bool verbose);
bool verbose, bool hex = false);
// Return a human-readable short (single-line) summary of the data size
// of files per level. Uses *scratch as backing store.

@ -63,7 +63,19 @@ class Slice {
}
// Return a string that contains the copy of the referenced data.
std::string ToString() const { return std::string(data_, size_); }
std::string ToString(bool hex = false) const {
if (hex) {
std::string result;
char buf[10];
for (size_t i = 0; i < size_; i++) {
snprintf(buf, 10, "%02X", (unsigned char)data_[i]);
result += buf;
}
return result;
} else {
return std::string(data_, size_);
}
}
// Three-way comparison. Returns value:
// < 0 iff "*this" < "b",

@ -19,6 +19,7 @@
#include "util/logging.h"
static int verbose = 0;
static int hex = 0;
using namespace leveldb;
@ -40,6 +41,9 @@ int main(int argc, char** argv) {
} else if (sscanf(argv[i], "--verbose=%ld%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
verbose = n;
} else if (sscanf(argv[i], "--hex=%ld%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
hex = n;
}
}
if (!foundfile) {
@ -60,7 +64,7 @@ int main(int argc, char** argv) {
VersionSet* versions = new VersionSet(dbname, &options,
tc, cmp);
Status s = versions->DumpManifest(options, file, verbose);
Status s = versions->DumpManifest(options, file, verbose, hex);
if (!s.ok()) {
printf("Error in processing file %s %s\n", manifestfile.c_str(),
s.ToString().c_str());

Loading…
Cancel
Save