[Log dumper broken when merge operator is in log]

Summary: $title

Test Plan:
on my dev box

Revert Plan: OK

Task ID: #

Reviewers: emayanke, dhruba, haobo

Reviewed By: haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D14451
main
Vamsi Ponnekanti 11 years ago
parent 97aa401e2f
commit fa88cbc71e
  1. 58
      util/ldb_cmd.cc

@ -1226,25 +1226,41 @@ void ChangeCompactionStyleCommand::DoCommand() {
class InMemoryHandler : public WriteBatch::Handler { class InMemoryHandler : public WriteBatch::Handler {
public: public:
InMemoryHandler(stringstream& row, bool print_values) : Handler(),row_(row) {
print_values_ = print_values;
}
virtual void Put(const Slice& key, const Slice& value) { void commonPutMerge(const Slice& key, const Slice& value) {
putMap_[key.ToString()] = value.ToString(); string k = LDBCommand::StringToHex(key.ToString());
if (print_values_) {
string v = LDBCommand::StringToHex(value.ToString());
row_ << k << " : ";
row_ << v << " ";
} else {
row_ << k << " ";
} }
virtual void Delete(const Slice& key) {
deleteList_.push_back(key.ToString(true));
} }
virtual ~InMemoryHandler() { };
map<string, string> PutMap() { virtual void Put(const Slice& key, const Slice& value) {
return putMap_; row_ << "PUT : ";
commonPutMerge(key, value);
} }
vector<string> DeleteList() {
return deleteList_; virtual void Merge(const Slice& key, const Slice& value) {
row_ << "MERGE : ";
commonPutMerge(key, value);
} }
virtual void Delete(const Slice& key) {
row_ <<",DELETE : ";
row_ << LDBCommand::StringToHex(key.ToString()) << " ";
}
virtual ~InMemoryHandler() { };
private: private:
map<string, string> putMap_; stringstream & row_;
vector<string> deleteList_; bool print_values_;
}; };
const string WALDumperCommand::ARG_WAL_FILE = "walfile"; const string WALDumperCommand::ARG_WAL_FILE = "walfile";
@ -1322,26 +1338,8 @@ void WALDumperCommand::DoCommand() {
row<<WriteBatchInternal::Count(&batch)<<","; row<<WriteBatchInternal::Count(&batch)<<",";
row<<WriteBatchInternal::ByteSize(&batch)<<","; row<<WriteBatchInternal::ByteSize(&batch)<<",";
row<<reader.LastRecordOffset()<<","; row<<reader.LastRecordOffset()<<",";
InMemoryHandler handler; InMemoryHandler handler(row, print_values_);
batch.Iterate(&handler); batch.Iterate(&handler);
row << "PUT : ";
if (print_values_) {
for (auto& kv : handler.PutMap()) {
string k = StringToHex(kv.first);
string v = StringToHex(kv.second);
row << k << " : ";
row << v << " ";
}
}
else {
for(auto& kv : handler.PutMap()) {
row << StringToHex(kv.first) << " ";
}
}
row<<",DELETE : ";
for(string& s : handler.DeleteList()) {
row << StringToHex(s) << " ";
}
row<<"\n"; row<<"\n";
} }
cout<<row.str(); cout<<row.str();

Loading…
Cancel
Save