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
main
haoyuhuang 5 years ago committed by Facebook Github Bot
parent dda474399a
commit 518cd1a62a
  1. 37
      db/version_set.cc
  2. 4
      db/version_set.h

@ -4041,10 +4041,15 @@ Status VersionSet::ExtractInfoFromVersionEdit(
return Status::OK(); 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_path != nullptr);
assert(manifest_file_number != nullptr);
std::string fname; std::string fname;
Status s = ReadFileToString(env_, CurrentFileName(dbname_), &fname); Status s = ReadFileToString(env, CurrentFileName(dbname), &fname);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
@ -4054,12 +4059,12 @@ Status VersionSet::GetCurrentManifestPath(std::string* manifest_path) {
// remove the trailing '\n' // remove the trailing '\n'
fname.resize(fname.size() - 1); fname.resize(fname.size() - 1);
FileType type; 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) { if (!parse_ok || type != kDescriptorFile) {
return Status::Corruption("CURRENT file corrupted"); return Status::Corruption("CURRENT file corrupted");
} }
*manifest_path = dbname_; *manifest_path = dbname;
if (dbname_.back() != '/') { if (dbname.back() != '/') {
manifest_path->push_back('/'); manifest_path->push_back('/');
} }
*manifest_path += fname; *manifest_path += fname;
@ -4080,7 +4085,8 @@ Status VersionSet::Recover(
// Read "CURRENT" file, which contains a pointer to the current manifest file // Read "CURRENT" file, which contains a pointer to the current manifest file
std::string manifest_path; std::string manifest_path;
Status s = GetCurrentManifestPath(&manifest_path); Status s = GetCurrentManifestPath(dbname_, env_, &manifest_path,
&manifest_file_number_);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
@ -4321,26 +4327,22 @@ Status VersionSet::ListColumnFamilies(std::vector<std::string>* column_families,
// so we're fine using the defaults // so we're fine using the defaults
EnvOptions soptions; EnvOptions soptions;
// Read "CURRENT" file, which contains a pointer to the current manifest file // Read "CURRENT" file, which contains a pointer to the current manifest file
std::string current; std::string manifest_path;
Status s = ReadFileToString(env, CurrentFileName(dbname), &current); uint64_t manifest_file_number;
Status s = GetCurrentManifestPath(dbname, env, &manifest_path,
&manifest_file_number);
if (!s.ok()) { if (!s.ok()) {
return s; 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<SequentialFileReader> file_reader; std::unique_ptr<SequentialFileReader> file_reader;
{ {
std::unique_ptr<SequentialFile> file; std::unique_ptr<SequentialFile> file;
s = env->NewSequentialFile(dscname, &file, soptions); s = env->NewSequentialFile(manifest_path, &file, soptions);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
file_reader.reset(new SequentialFileReader(std::move(file), dscname)); file_reader.reset(new SequentialFileReader(std::move(file), manifest_path));
} }
std::map<uint32_t, std::string> column_family_names; std::map<uint32_t, std::string> column_family_names;
@ -5510,7 +5512,8 @@ Status ReactiveVersionSet::MaybeSwitchManifest(
Status s; Status s;
do { do {
std::string manifest_path; std::string manifest_path;
s = GetCurrentManifestPath(&manifest_path); s = GetCurrentManifestPath(dbname_, env_, &manifest_path,
&manifest_file_number_);
std::unique_ptr<SequentialFile> manifest_file; std::unique_ptr<SequentialFile> manifest_file;
if (s.ok()) { if (s.ok()) {
if (nullptr == manifest_reader->get() || if (nullptr == manifest_reader->get() ||

@ -807,7 +807,9 @@ class VersionSet {
bool new_descriptor_log = false, bool new_descriptor_log = false,
const ColumnFamilyOptions* new_cf_options = nullptr); 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. // Recover the last saved descriptor from persistent storage.
// If read_only == true, Recover() will not complain if some column families // If read_only == true, Recover() will not complain if some column families

Loading…
Cancel
Save