Fix the output of `ldb dump_wal` for PutEntity records (#12677)

Summary:
Pull Request resolved: https://github.com/facebook/rocksdb/pull/12677

The patch contains two fixes related to printing `PutEntity` records with `ldb dump_wal`:
1) It adds the key to the printout (it was missing earlier).
2) It restores the formatting flags of the output stream after dumping the wide-column structure so that any `hex` flag that might have been set does not affect subsequent printing of e.g. sequence numbers.

Reviewed By: jaykorean, jowlyzhang

Differential Revision: D57591295

fbshipit-source-id: af4e3e219f0082ad39bbdfd26f8c5a57ebb898be
This commit is contained in:
Levi Tamasi 2024-05-20 17:04:14 -07:00 committed by Facebook GitHub Bot
parent b7520f4815
commit ef1d4955ba
2 changed files with 17 additions and 3 deletions

View File

@ -6,6 +6,7 @@
#include "db/wide/wide_columns_helper.h" #include "db/wide/wide_columns_helper.h"
#include <algorithm> #include <algorithm>
#include <ios>
#include "db/wide/wide_column_serialization.h" #include "db/wide/wide_column_serialization.h"
@ -15,6 +16,9 @@ void WideColumnsHelper::DumpWideColumns(const WideColumns& columns,
if (columns.empty()) { if (columns.empty()) {
return; return;
} }
const std::ios_base::fmtflags orig_flags = os.flags();
if (hex) { if (hex) {
os << std::hex; os << std::hex;
} }
@ -23,6 +27,8 @@ void WideColumnsHelper::DumpWideColumns(const WideColumns& columns,
for (++it; it != columns.end(); ++it) { for (++it; it != columns.end(); ++it) {
os << ' ' << *it; os << ' ' << *it;
} }
os.flags(orig_flags);
} }
Status WideColumnsHelper::DumpSliceAsWideColumns(const Slice& value, Status WideColumnsHelper::DumpSliceAsWideColumns(const Slice& value,

View File

@ -2666,11 +2666,19 @@ class InMemoryHandler : public WriteBatch::Handler {
Status PutEntityCF(uint32_t cf, const Slice& key, Status PutEntityCF(uint32_t cf, const Slice& key,
const Slice& value) override { const Slice& value) override {
row_ << "PUT_ENTITY(" << cf << ") : "; row_ << "PUT_ENTITY(" << cf
std::string k = LDBCommand::StringToHex(key.ToString()); << ") : " << LDBCommand::StringToHex(key.ToString());
if (print_values_) { if (print_values_) {
return WideColumnsHelper::DumpSliceAsWideColumns(value, row_, true); row_ << " : ";
const Status s =
WideColumnsHelper::DumpSliceAsWideColumns(value, row_, true);
if (!s.ok()) {
return s;
}
} }
row_ << ' ';
return Status::OK(); return Status::OK();
} }