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
This commit is contained in:
huangmengbin 2023-07-19 10:44:10 -07:00 committed by Facebook GitHub Bot
parent 8a7b9888d4
commit 98d0f6ec08
3 changed files with 26 additions and 13 deletions

View File

@ -6302,8 +6302,9 @@ Status VersionSet::GetLiveFilesChecksumInfo(FileChecksumList* checksum_list) {
return s; return s;
} }
Status VersionSet::DumpManifest(Options& options, std::string& dscname, Status VersionSet::DumpManifest(
bool verbose, bool hex, bool json) { Options& options, std::string& dscname, bool verbose, bool hex, bool json,
const std::vector<ColumnFamilyDescriptor>& cf_descs) {
assert(options.env); assert(options.env);
// TODO: plumb Env::IOActivity // TODO: plumb Env::IOActivity
const ReadOptions read_options; 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::move(file), dscname, db_options_->log_readahead_size, io_tracer_);
} }
std::vector<ColumnFamilyDescriptor> cf_descs; std::map<std::string, const ColumnFamilyDescriptor*> cf_name_to_desc;
for (const auto& cf_desc : cf_descs) {
cf_name_to_desc[cf_desc.name] = &cf_desc;
}
std::vector<ColumnFamilyDescriptor> final_cf_descs;
for (const auto& cf : column_families) { 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, DumpManifestHandler handler(final_cf_descs, this, io_tracer_, read_options,
hex, json); verbose, hex, json);
{ {
VersionSet::LogReporter reporter; VersionSet::LogReporter reporter;
reporter.status = &s; reporter.status = &s;

View File

@ -1273,8 +1273,8 @@ class VersionSet {
// printf contents (for debugging) // printf contents (for debugging)
Status DumpManifest(Options& options, std::string& manifestFileName, 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<ColumnFamilyDescriptor>& cf_descs = {});
const std::string& DbSessionId() const { return db_session_id_; } const std::string& DbSessionId() const { return db_session_id_; }

View File

@ -1310,7 +1310,8 @@ void DBLoaderCommand::DoCommand() {
namespace { namespace {
void DumpManifestFile(Options options, std::string file, bool verbose, bool hex, void DumpManifestFile(Options options, std::string file, bool verbose, bool hex,
bool json) { bool json,
const std::vector<ColumnFamilyDescriptor>& cf_descs) {
EnvOptions sopt; EnvOptions sopt;
std::string dbname("dummy"); std::string dbname("dummy");
std::shared_ptr<Cache> tc(NewLRUCache(options.max_open_files - 10, std::shared_ptr<Cache> 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, VersionSet versions(dbname, &immutable_db_options, sopt, tc.get(), &wb, &wc,
/*block_cache_tracer=*/nullptr, /*io_tracer=*/nullptr, /*block_cache_tracer=*/nullptr, /*io_tracer=*/nullptr,
/*db_id*/ "", /*db_session_id*/ ""); /*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()) { if (!s.ok()) {
fprintf(stderr, "Error in processing file %s %s\n", file.c_str(), fprintf(stderr, "Error in processing file %s %s\n", file.c_str(),
s.ToString().c_str()); s.ToString().c_str());
@ -1438,7 +1439,8 @@ void ManifestDumpCommand::DoCommand() {
fprintf(stdout, "Processing Manifest file %s\n", manifestfile.c_str()); 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_) { if (verbose_) {
fprintf(stdout, "Processing Manifest file %s done\n", manifestfile.c_str()); fprintf(stdout, "Processing Manifest file %s done\n", manifestfile.c_str());
@ -2046,7 +2048,7 @@ void DBDumperCommand::DoCommand() {
break; break;
case kDescriptorFile: case kDescriptorFile:
DumpManifestFile(options_, path_, /* verbose_ */ false, is_key_hex_, DumpManifestFile(options_, path_, /* verbose_ */ false, is_key_hex_,
/* json_ */ false); /* json_ */ false, column_families_);
break; break;
case kBlobFile: case kBlobFile:
DumpBlobFile(path_, is_key_hex_, is_value_hex_, DumpBlobFile(path_, is_key_hex_, is_value_hex_,
@ -3706,7 +3708,8 @@ void DBFileDumperCommand::DoCommand() {
manifest_filepath = NormalizePath(manifest_filepath); manifest_filepath = NormalizePath(manifest_filepath);
std::cout << manifest_filepath << std::endl; 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::cout << std::endl;
std::vector<ColumnFamilyMetaData> column_families; std::vector<ColumnFamilyMetaData> column_families;