manifest_ops.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  2. //
  3. // This source code is licensed under both the GPLv2 (found in the
  4. // COPYING file in the root directory) and Apache 2.0 License
  5. // (found in the LICENSE.Apache file in the root directory).
  6. #include "db/manifest_ops.h"
  7. #include "file/filename.h"
  8. namespace ROCKSDB_NAMESPACE {
  9. Status GetCurrentManifestPath(const std::string& dbname, FileSystem* fs,
  10. bool is_retry, std::string* manifest_path,
  11. uint64_t* manifest_file_number) {
  12. assert(fs != nullptr);
  13. assert(manifest_path != nullptr);
  14. assert(manifest_file_number != nullptr);
  15. IOOptions opts;
  16. std::string fname;
  17. if (is_retry) {
  18. opts.verify_and_reconstruct_read = true;
  19. }
  20. Status s = ReadFileToString(fs, CurrentFileName(dbname), opts, &fname);
  21. if (!s.ok()) {
  22. return s;
  23. }
  24. if (fname.empty() || fname.back() != '\n') {
  25. return Status::Corruption("CURRENT file does not end with newline");
  26. }
  27. // remove the trailing '\n'
  28. fname.resize(fname.size() - 1);
  29. FileType type;
  30. bool parse_ok = ParseFileName(fname, manifest_file_number, &type);
  31. if (!parse_ok || type != kDescriptorFile) {
  32. return Status::Corruption("CURRENT file corrupted");
  33. }
  34. *manifest_path = dbname;
  35. if (dbname.back() != '/') {
  36. manifest_path->push_back('/');
  37. }
  38. manifest_path->append(fname);
  39. return Status::OK();
  40. }
  41. } // namespace ROCKSDB_NAMESPACE