Summary: This change introduces a new, lightweight _experimental_ API that reconstructs the [file # -> file checksum -> file checksum function] 1-1-1 mapping directly from the `MANIFEST` file considered `CURRENT` in scope of specific DB instance at the time. The goal is to provide a cheap alternative to `DB::GetLiveFilesMetaData` that doesn't require opening the database, reconstructing version sets and/or accessing files that are _potentially_ in disaggregated storage. ### Housekeeping: 1. Moved the `GetCurrentManifestPath` out of `version_set` to a new `manifest_ops` file(s) dedicated to manifest related operations. 2. Introduced new `Env::IOActivity::kReadManifest` to better reflect the IO intent in offline file checksum retrieving function. Pull Request resolved: https://github.com/facebook/rocksdb/pull/13178 Test Plan: Added a unit test comparing the outcome of newly introduced API against the established `GetLiveFilesMetaData`: ```hcl ./db_test2 --gtest_filter="*GetFileChecksumsFromCurrentManifest_CRC32*" ``` Reviewed By: pdillinger Differential Revision: D66711910 Pulled By: mszeszko-meta fbshipit-source-id: 57091c550a14ac2e832bf7eea136dab5450e71bc
47 lines
1.4 KiB
C++
47 lines
1.4 KiB
C++
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
//
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#include "db/manifest_ops.h"
|
|
|
|
#include "file/filename.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
Status GetCurrentManifestPath(const std::string& dbname, FileSystem* fs,
|
|
bool is_retry, std::string* manifest_path,
|
|
uint64_t* manifest_file_number) {
|
|
assert(fs != nullptr);
|
|
assert(manifest_path != nullptr);
|
|
assert(manifest_file_number != nullptr);
|
|
|
|
IOOptions opts;
|
|
std::string fname;
|
|
if (is_retry) {
|
|
opts.verify_and_reconstruct_read = true;
|
|
}
|
|
Status s = ReadFileToString(fs, CurrentFileName(dbname), opts, &fname);
|
|
if (!s.ok()) {
|
|
return s;
|
|
}
|
|
if (fname.empty() || fname.back() != '\n') {
|
|
return Status::Corruption("CURRENT file does not end with newline");
|
|
}
|
|
// remove the trailing '\n'
|
|
fname.resize(fname.size() - 1);
|
|
FileType 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->push_back('/');
|
|
}
|
|
manifest_path->append(fname);
|
|
return Status::OK();
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|