From 314352761fd2599fa8bb3afd602bf3c509a5c432 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Wed, 21 Apr 2021 20:42:02 -0700 Subject: [PATCH] Ignore comparator name mismatch in ldb manifest dump (#8216) Summary: RocksDB allows user-specified custom comparators which may not be known to `ldb`, a built-in tool for checking/mutating the database. Therefore, column family comparator names mismatch encountered during manifest dump should not prevent the dumping from proceeding. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8216 Test Plan: ``` make check ``` Also manually do the following ``` KEEP_DB=1 ./db_with_timestamp_basic_test ./ldb --db= manifest_dump --verbose ``` The ldb should succeed and print something like: ``` ... --------------- Column family "default" (ID 0) -------------- log number: 6 comparator: , but the comparator object is not available. ... ``` Reviewed By: ltamasi Differential Revision: D27927581 Pulled By: riversand963 fbshipit-source-id: f610b2c842187d17f575362070209ee6b74ec6d4 --- db/version_edit_handler.cc | 20 ++++++++++++++++---- db/version_edit_handler.h | 5 ++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/db/version_edit_handler.cc b/db/version_edit_handler.cc index 4f7f685b6..807cac9d0 100644 --- a/db/version_edit_handler.cc +++ b/db/version_edit_handler.cc @@ -553,9 +553,13 @@ Status VersionEditHandler::ExtractInfoFromVersionEdit(ColumnFamilyData* cfd, } if (edit.has_comparator_ && edit.comparator_ != cfd->user_comparator()->Name()) { - s = Status::InvalidArgument( - cfd->user_comparator()->Name(), - "does not match existing comparator " + edit.comparator_); + if (!cf_to_cmp_names_) { + s = Status::InvalidArgument( + cfd->user_comparator()->Name(), + "does not match existing comparator " + edit.comparator_); + } else { + cf_to_cmp_names_->emplace(cfd->GetID(), edit.comparator_); + } } if (edit.HasFullHistoryTsLow()) { const std::string& new_ts = edit.GetFullHistoryTsLow(); @@ -889,13 +893,21 @@ void DumpManifestHandler::CheckIterationResult(const log::Reader& reader, fprintf(stdout, "%s\n", s->ToString().c_str()); return; } + assert(cf_to_cmp_names_); for (auto* cfd : *(version_set_->column_family_set_)) { fprintf(stdout, "--------------- Column family \"%s\" (ID %" PRIu32 ") --------------\n", cfd->GetName().c_str(), cfd->GetID()); fprintf(stdout, "log number: %" PRIu64 "\n", cfd->GetLogNumber()); - fprintf(stdout, "comparator: %s\n", cfd->user_comparator()->Name()); + auto it = cf_to_cmp_names_->find(cfd->GetID()); + if (it != cf_to_cmp_names_->end()) { + fprintf(stdout, + "comparator: <%s>, but the comparator object is not available.\n", + it->second.c_str()); + } else { + fprintf(stdout, "comparator: %s\n", cfd->user_comparator()->Name()); + } assert(cfd->current()); fprintf(stdout, "%s \n", cfd->current()->DebugString(hex_).c_str()); } diff --git a/db/version_edit_handler.h b/db/version_edit_handler.h index da7219ad6..3fd16f413 100644 --- a/db/version_edit_handler.h +++ b/db/version_edit_handler.h @@ -188,6 +188,7 @@ class VersionEditHandler : public VersionEditHandlerBase { std::shared_ptr io_tracer_; bool skip_load_table_files_; bool initialized_; + std::unique_ptr> cf_to_cmp_names_; private: Status ExtractInfoFromVersionEdit(ColumnFamilyData* cfd, @@ -275,7 +276,9 @@ class DumpManifestHandler : public VersionEditHandler { verbose_(verbose), hex_(hex), json_(json), - count_(0) {} + count_(0) { + cf_to_cmp_names_.reset(new std::unordered_map()); + } ~DumpManifestHandler() override {} -- GitLab