From 473e829784c8b22f3f59cb01fd6bc319f20d3bec Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 29 Jul 2014 18:37:00 -0700 Subject: [PATCH] Fix ldb dump_manifest Summary: We now reads table properties in VersionSet::LogAndApply(), which requires options.db_paths to be set. But since ldb_cmd directly creates VersionSet without initialization db_paths, causing a seg fault. This patch fix it by initializing db_paths. log_and_apply_bench still shows segfault, because table cache is nullptr in VersionSet created. Test Plan: Run ldb dump_manifest which used to fail. Reviewers: yhchiang, ljin, igor Reviewed By: igor Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D20751 --- db/log_and_apply_bench.cc | 5 +++++ util/ldb_cmd.cc | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/db/log_and_apply_bench.cc b/db/log_and_apply_bench.cc index dbb459c30..a5aa95017 100644 --- a/db/log_and_apply_bench.cc +++ b/db/log_and_apply_bench.cc @@ -42,6 +42,11 @@ void BM_LogAndApply(int iters, int num_base_files) { Options options; EnvOptions sopt; + // Notice we are using the default options not through SanitizeOptions(). + // We might want to initialize some options manually if needed. + options.db_paths.emplace_back(dbname, 0); + // The parameter of table cache is passed in as null, so any file I/O + // operation is likely to fail. vset = new VersionSet(dbname, &options, sopt, nullptr); std::vector dummy; dummy.push_back(ColumnFamilyDescriptor()); diff --git a/util/ldb_cmd.cc b/util/ldb_cmd.cc index 8b92820de..b6e108ccc 100644 --- a/util/ldb_cmd.cc +++ b/util/ldb_cmd.cc @@ -556,6 +556,10 @@ void ManifestDumpCommand::DoCommand() { std::shared_ptr tc(NewLRUCache( options.max_open_files - 10, options.table_cache_numshardbits, options.table_cache_remove_scan_count_limit)); + // Notice we are using the default options not through SanitizeOptions(), + // if VersionSet::DumpManifest() depends on any option done by + // SanitizeOptions(), we need to initialize it manually. + options.db_paths.emplace_back("dummy", 0); VersionSet* versions = new VersionSet(dbname, &options, sopt, tc.get()); Status s = versions->DumpManifest(options, file, verbose_, is_key_hex_); if (!s.ok()) {