From 3bd150c442f16fbaefd8763b797b4c933c8efe61 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Tue, 22 Mar 2022 20:29:01 -0700 Subject: [PATCH] Print information about all column families when using ldb (#9719) Summary: Before this PR, the following command prints only the default column family's information in the end: ``` ldb --db=. --hex manifest_dump --verbose ``` We should print all column families instead. Pull Request resolved: https://github.com/facebook/rocksdb/pull/9719 Test Plan: `make check` makes sure nothing breaks. Generate a DB, use the above command to verify all column families are printed. Reviewed By: akankshamahajan15 Differential Revision: D34992453 Pulled By: riversand963 fbshipit-source-id: de1d38c4539cd89f74e1a6240ad7a6e2416bf198 --- db/version_set.cc | 42 ++++++++++++++++++++++++++++-------------- db/version_set.h | 3 +++ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/db/version_set.cc b/db/version_set.cc index daf1d9145..134c1f88a 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -5126,9 +5126,6 @@ Status VersionSet::TryRecoverFromOneManifest( Status VersionSet::ListColumnFamilies(std::vector* column_families, const std::string& dbname, FileSystem* fs) { - // these are just for performance reasons, not correctness, - // so we're fine using the defaults - FileOptions soptions; // Read "CURRENT" file, which contains a pointer to the current manifest file std::string manifest_path; uint64_t manifest_file_number; @@ -5137,16 +5134,24 @@ Status VersionSet::ListColumnFamilies(std::vector* column_families, if (!s.ok()) { return s; } + return ListColumnFamiliesFromManifest(manifest_path, fs, column_families); +} +Status VersionSet::ListColumnFamiliesFromManifest( + const std::string& manifest_path, FileSystem* fs, + std::vector* column_families) { std::unique_ptr file_reader; + Status s; { std::unique_ptr file; - s = fs->NewSequentialFile(manifest_path, soptions, &file, nullptr); + // these are just for performance reasons, not correctness, + // so we're fine using the defaults + s = fs->NewSequentialFile(manifest_path, FileOptions(), &file, nullptr); if (!s.ok()) { return s; - } - file_reader.reset(new SequentialFileReader(std::move(file), manifest_path, - nullptr /*IOTracer*/)); + } + file_reader = std::make_unique( + std::move(file), manifest_path, /*io_tracer=*/nullptr); } VersionSet::LogReporter reporter; @@ -5336,9 +5341,16 @@ Status VersionSet::GetLiveFilesChecksumInfo(FileChecksumList* checksum_list) { Status VersionSet::DumpManifest(Options& options, std::string& dscname, bool verbose, bool hex, bool json) { + assert(options.env); + std::vector column_families; + Status s = ListColumnFamiliesFromManifest( + dscname, options.env->GetFileSystem().get(), &column_families); + if (!s.ok()) { + return s; + } + // Open the specified manifest file. std::unique_ptr file_reader; - Status s; { std::unique_ptr file; const std::shared_ptr& fs = options.env->GetFileSystem(); @@ -5349,14 +5361,16 @@ Status VersionSet::DumpManifest(Options& options, std::string& dscname, if (!s.ok()) { return s; } - file_reader.reset(new SequentialFileReader( - std::move(file), dscname, db_options_->log_readahead_size, io_tracer_)); + file_reader = std::make_unique( + std::move(file), dscname, db_options_->log_readahead_size, io_tracer_); + } + + std::vector cf_descs; + for (const auto& cf : column_families) { + cf_descs.emplace_back(cf, options); } - std::vector column_families( - 1, ColumnFamilyDescriptor(kDefaultColumnFamilyName, options)); - DumpManifestHandler handler(column_families, this, io_tracer_, verbose, hex, - json); + DumpManifestHandler handler(cf_descs, this, io_tracer_, verbose, hex, json); { VersionSet::LogReporter reporter; reporter.status = &s; diff --git a/db/version_set.h b/db/version_set.h index 38e6616cf..0c5e97334 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -1090,6 +1090,9 @@ class VersionSet { // column_families. static Status ListColumnFamilies(std::vector* column_families, const std::string& dbname, FileSystem* fs); + static Status ListColumnFamiliesFromManifest( + const std::string& manifest_path, FileSystem* fs, + std::vector* column_families); #ifndef ROCKSDB_LITE // Try to reduce the number of levels. This call is valid when