作者: 谢瑞阳 10225101483 徐翔宇 10225101535
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

106 linhas
2.9 KiB

Add Env::Remove{File,Dir} which obsolete Env::Delete{File,Dir}. The "DeleteFile" method name causes pain for Windows developers, because <windows.h> #defines a DeleteFile macro to DeleteFileW or DeleteFileA. Current code uses workarounds, like #undefining DeleteFile everywhere an Env is declared, implemented, or used. This CL removes the need for workarounds by renaming Env::DeleteFile to Env::RemoveFile. For consistency, Env::DeleteDir is also renamed to Env::RemoveDir. A few internal methods are also renamed for consistency. Software that supports Windows is expected to migrate any Env implementations and usage to Remove{File,Dir}, and never use the name Env::Delete{File,Dir} in its code. The renaming is done in a backwards-compatible way, at the risk of making it slightly more difficult to build a new correct Env implementation. The backwards compatibility is achieved using the following hacks: 1) Env::Remove{File,Dir} methods are added, with a default implementation that calls into Env::Delete{File,Dir}. This makes old Env implementations compatible with code that calls into the updated API. 2) The Env::Delete{File,Dir} methods are no longer pure virtuals. Instead, they gain a default implementation that calls into Env::Remove{File,Dir}. This makes updated Env implementations compatible with code that calls into the old API. The cost of this approach is that it's possible to write an Env without overriding either Rename{File,Dir} or Delete{File,Dir}, without getting a compiler warning. However, attempting to run the test suite will immediately fail with an infinite call stack ending in {Remove,Delete}{File,Dir}, making developers aware of the problem. PiperOrigin-RevId: 288710907
há 4 anos
  1. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. #ifndef STORAGE_LEVELDB_DB_VERSION_EDIT_H_
  5. #define STORAGE_LEVELDB_DB_VERSION_EDIT_H_
  6. #include <set>
  7. #include <utility>
  8. #include <vector>
  9. #include "db/dbformat.h"
  10. namespace leveldb {
  11. class VersionSet;
  12. struct FileMetaData {
  13. FileMetaData() : refs(0), allowed_seeks(1 << 30), file_size(0) {}
  14. int refs;
  15. int allowed_seeks; // Seeks allowed until compaction
  16. uint64_t number;
  17. uint64_t file_size; // File size in bytes
  18. InternalKey smallest; // Smallest internal key served by table
  19. InternalKey largest; // Largest internal key served by table
  20. };
  21. class VersionEdit {
  22. public:
  23. VersionEdit() { Clear(); }
  24. ~VersionEdit() = default;
  25. void Clear();
  26. void SetComparatorName(const Slice& name) {
  27. has_comparator_ = true;
  28. comparator_ = name.ToString();
  29. }
  30. void SetLogNumber(uint64_t num) {
  31. has_log_number_ = true;
  32. log_number_ = num;
  33. }
  34. void SetPrevLogNumber(uint64_t num) {
  35. has_prev_log_number_ = true;
  36. prev_log_number_ = num;
  37. }
  38. void SetNextFile(uint64_t num) {
  39. has_next_file_number_ = true;
  40. next_file_number_ = num;
  41. }
  42. void SetLastSequence(SequenceNumber seq) {
  43. has_last_sequence_ = true;
  44. last_sequence_ = seq;
  45. }
  46. void SetCompactPointer(int level, const InternalKey& key) {
  47. compact_pointers_.push_back(std::make_pair(level, key));
  48. }
  49. // Add the specified file at the specified number.
  50. // REQUIRES: This version has not been saved (see VersionSet::SaveTo)
  51. // REQUIRES: "smallest" and "largest" are smallest and largest keys in file
  52. void AddFile(int level, uint64_t file, uint64_t file_size,
  53. const InternalKey& smallest, const InternalKey& largest) {
  54. FileMetaData f;
  55. f.number = file;
  56. f.file_size = file_size;
  57. f.smallest = smallest;
  58. f.largest = largest;
  59. new_files_.push_back(std::make_pair(level, f));
  60. }
  61. // Delete the specified "file" from the specified "level".
  62. void RemoveFile(int level, uint64_t file) {
  63. deleted_files_.insert(std::make_pair(level, file));
  64. }
  65. void EncodeTo(std::string* dst) const;
  66. Status DecodeFrom(const Slice& src);
  67. std::string DebugString() const;
  68. private:
  69. friend class VersionSet;
  70. typedef std::set<std::pair<int, uint64_t>> DeletedFileSet;
  71. std::string comparator_;
  72. uint64_t log_number_;
  73. uint64_t prev_log_number_;
  74. uint64_t next_file_number_;
  75. SequenceNumber last_sequence_;
  76. bool has_comparator_;
  77. bool has_log_number_;
  78. bool has_prev_log_number_;
  79. bool has_next_file_number_;
  80. bool has_last_sequence_;
  81. std::vector<std::pair<int, InternalKey>> compact_pointers_;
  82. DeletedFileSet deleted_files_;
  83. std::vector<std::pair<int, FileMetaData>> new_files_;
  84. };
  85. } // namespace leveldb
  86. #endif // STORAGE_LEVELDB_DB_VERSION_EDIT_H_