From 518cd1a62aeaaa9584516fdcf81bbfafbd75f18c Mon Sep 17 00:00:00 2001 From: haoyuhuang Date: Wed, 22 May 2019 09:17:39 -0700 Subject: [PATCH] Use GetCurrentManifestPath to locate current MANIFEST file (#5331) Summary: In version_set.cc, there is a function GetCurrentManifestPath. The goal of this task is to refactor ListColumnFamilies function so that ListColumnFamilies calls GetCurrentManifestPath to search for MANIFEST. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5331 Differential Revision: D15444524 Pulled By: HaoyuHuang fbshipit-source-id: 1dcbd030bc0f2e835695741f450bba150f2f2903 --- db/version_set.cc | 37 ++++++++++++++++++++----------------- db/version_set.h | 4 +++- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/db/version_set.cc b/db/version_set.cc index 15b9d01fe..5723c6d92 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -4041,10 +4041,15 @@ Status VersionSet::ExtractInfoFromVersionEdit( return Status::OK(); } -Status VersionSet::GetCurrentManifestPath(std::string* manifest_path) { +Status VersionSet::GetCurrentManifestPath(const std::string& dbname, Env* env, + std::string* manifest_path, + uint64_t* manifest_file_number) { + assert(env != nullptr); assert(manifest_path != nullptr); + assert(manifest_file_number != nullptr); + std::string fname; - Status s = ReadFileToString(env_, CurrentFileName(dbname_), &fname); + Status s = ReadFileToString(env, CurrentFileName(dbname), &fname); if (!s.ok()) { return s; } @@ -4054,12 +4059,12 @@ Status VersionSet::GetCurrentManifestPath(std::string* manifest_path) { // remove the trailing '\n' fname.resize(fname.size() - 1); FileType type; - bool parse_ok = ParseFileName(fname, &manifest_file_number_, &type); + bool parse_ok = ParseFileName(fname, manifest_file_number, &type); if (!parse_ok || type != kDescriptorFile) { return Status::Corruption("CURRENT file corrupted"); } - *manifest_path = dbname_; - if (dbname_.back() != '/') { + *manifest_path = dbname; + if (dbname.back() != '/') { manifest_path->push_back('/'); } *manifest_path += fname; @@ -4080,7 +4085,8 @@ Status VersionSet::Recover( // Read "CURRENT" file, which contains a pointer to the current manifest file std::string manifest_path; - Status s = GetCurrentManifestPath(&manifest_path); + Status s = GetCurrentManifestPath(dbname_, env_, &manifest_path, + &manifest_file_number_); if (!s.ok()) { return s; } @@ -4321,26 +4327,22 @@ Status VersionSet::ListColumnFamilies(std::vector* column_families, // so we're fine using the defaults EnvOptions soptions; // Read "CURRENT" file, which contains a pointer to the current manifest file - std::string current; - Status s = ReadFileToString(env, CurrentFileName(dbname), ¤t); + std::string manifest_path; + uint64_t manifest_file_number; + Status s = GetCurrentManifestPath(dbname, env, &manifest_path, + &manifest_file_number); if (!s.ok()) { return s; } - if (current.empty() || current[current.size()-1] != '\n') { - return Status::Corruption("CURRENT file does not end with newline"); - } - current.resize(current.size() - 1); - - std::string dscname = dbname + "/" + current; std::unique_ptr file_reader; { std::unique_ptr file; - s = env->NewSequentialFile(dscname, &file, soptions); + s = env->NewSequentialFile(manifest_path, &file, soptions); if (!s.ok()) { return s; } - file_reader.reset(new SequentialFileReader(std::move(file), dscname)); + file_reader.reset(new SequentialFileReader(std::move(file), manifest_path)); } std::map column_family_names; @@ -5510,7 +5512,8 @@ Status ReactiveVersionSet::MaybeSwitchManifest( Status s; do { std::string manifest_path; - s = GetCurrentManifestPath(&manifest_path); + s = GetCurrentManifestPath(dbname_, env_, &manifest_path, + &manifest_file_number_); std::unique_ptr manifest_file; if (s.ok()) { if (nullptr == manifest_reader->get() || diff --git a/db/version_set.h b/db/version_set.h index d82c5b472..28ad0c2c2 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -807,7 +807,9 @@ class VersionSet { bool new_descriptor_log = false, const ColumnFamilyOptions* new_cf_options = nullptr); - Status GetCurrentManifestPath(std::string* manifest_filename); + static Status GetCurrentManifestPath(const std::string& dbname, Env* env, + std::string* manifest_filename, + uint64_t* manifest_file_number); // Recover the last saved descriptor from persistent storage. // If read_only == true, Recover() will not complain if some column families