From 98d0f6ec08290b3c0848ac2fdc9a2e319dc91186 Mon Sep 17 00:00:00 2001 From: huangmengbin <44433515+huangmengbin@users.noreply.github.com> Date: Wed, 19 Jul 2023 10:44:10 -0700 Subject: [PATCH] fix: VersionSet::DumpManifest (#11605) Summary: Fixes https://github.com/facebook/rocksdb/issues/11604 Pull Request resolved: https://github.com/facebook/rocksdb/pull/11605 Reviewed By: jowlyzhang Differential Revision: D47459254 Pulled By: ajkr fbshipit-source-id: 4420e443fbf4bd01ddaa2b47285fc4445bf36246 --- db/version_set.cc | 22 ++++++++++++++++------ db/version_set.h | 4 ++-- tools/ldb_cmd.cc | 13 ++++++++----- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/db/version_set.cc b/db/version_set.cc index 0bdc0304f..e95e98f79 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -6302,8 +6302,9 @@ Status VersionSet::GetLiveFilesChecksumInfo(FileChecksumList* checksum_list) { return s; } -Status VersionSet::DumpManifest(Options& options, std::string& dscname, - bool verbose, bool hex, bool json) { +Status VersionSet::DumpManifest( + Options& options, std::string& dscname, bool verbose, bool hex, bool json, + const std::vector& cf_descs) { assert(options.env); // TODO: plumb Env::IOActivity const ReadOptions read_options; @@ -6329,13 +6330,22 @@ Status VersionSet::DumpManifest(Options& options, std::string& dscname, std::move(file), dscname, db_options_->log_readahead_size, io_tracer_); } - std::vector cf_descs; + std::map cf_name_to_desc; + for (const auto& cf_desc : cf_descs) { + cf_name_to_desc[cf_desc.name] = &cf_desc; + } + std::vector final_cf_descs; for (const auto& cf : column_families) { - cf_descs.emplace_back(cf, options); + const auto iter = cf_name_to_desc.find(cf); + if (iter != cf_name_to_desc.cend()) { + final_cf_descs.push_back(*iter->second); + } else { + final_cf_descs.emplace_back(cf, options); + } } - DumpManifestHandler handler(cf_descs, this, io_tracer_, read_options, verbose, - hex, json); + DumpManifestHandler handler(final_cf_descs, this, io_tracer_, read_options, + verbose, hex, json); { VersionSet::LogReporter reporter; reporter.status = &s; diff --git a/db/version_set.h b/db/version_set.h index c3e48bb4e..e32d0ff11 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -1273,8 +1273,8 @@ class VersionSet { // printf contents (for debugging) Status DumpManifest(Options& options, std::string& manifestFileName, - bool verbose, bool hex = false, bool json = false); - + bool verbose, bool hex = false, bool json = false, + const std::vector& cf_descs = {}); const std::string& DbSessionId() const { return db_session_id_; } diff --git a/tools/ldb_cmd.cc b/tools/ldb_cmd.cc index f0119b31e..46dd36ccc 100644 --- a/tools/ldb_cmd.cc +++ b/tools/ldb_cmd.cc @@ -1310,7 +1310,8 @@ void DBLoaderCommand::DoCommand() { namespace { void DumpManifestFile(Options options, std::string file, bool verbose, bool hex, - bool json) { + bool json, + const std::vector& cf_descs) { EnvOptions sopt; std::string dbname("dummy"); std::shared_ptr tc(NewLRUCache(options.max_open_files - 10, @@ -1326,7 +1327,7 @@ void DumpManifestFile(Options options, std::string file, bool verbose, bool hex, VersionSet versions(dbname, &immutable_db_options, sopt, tc.get(), &wb, &wc, /*block_cache_tracer=*/nullptr, /*io_tracer=*/nullptr, /*db_id*/ "", /*db_session_id*/ ""); - Status s = versions.DumpManifest(options, file, verbose, hex, json); + Status s = versions.DumpManifest(options, file, verbose, hex, json, cf_descs); if (!s.ok()) { fprintf(stderr, "Error in processing file %s %s\n", file.c_str(), s.ToString().c_str()); @@ -1438,7 +1439,8 @@ void ManifestDumpCommand::DoCommand() { fprintf(stdout, "Processing Manifest file %s\n", manifestfile.c_str()); } - DumpManifestFile(options_, manifestfile, verbose_, is_key_hex_, json_); + DumpManifestFile(options_, manifestfile, verbose_, is_key_hex_, json_, + column_families_); if (verbose_) { fprintf(stdout, "Processing Manifest file %s done\n", manifestfile.c_str()); @@ -2046,7 +2048,7 @@ void DBDumperCommand::DoCommand() { break; case kDescriptorFile: DumpManifestFile(options_, path_, /* verbose_ */ false, is_key_hex_, - /* json_ */ false); + /* json_ */ false, column_families_); break; case kBlobFile: DumpBlobFile(path_, is_key_hex_, is_value_hex_, @@ -3706,7 +3708,8 @@ void DBFileDumperCommand::DoCommand() { manifest_filepath = NormalizePath(manifest_filepath); std::cout << manifest_filepath << std::endl; - DumpManifestFile(options_, manifest_filepath, false, false, false); + DumpManifestFile(options_, manifest_filepath, false, false, false, + column_families_); std::cout << std::endl; std::vector column_families;