10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.3 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
4 years ago
  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. smallest_deadtime(UINT64_MAX),largest_deadtime(UINT64_MAX) {}
  15. int refs;
  16. int allowed_seeks; // Seeks allowed until compaction
  17. uint64_t number;
  18. uint64_t file_size; // File size in bytes
  19. InternalKey smallest; // Smallest internal key served by table
  20. InternalKey largest; // Largest internal key served by table
  21. //在FileMetaData中,使用Uint64MAX作为没有生存期的标志(表示生存期无限长)
  22. uint64_t smallest_deadtime; //smallest deadtime
  23. uint64_t largest_deadtime; //largest deadtime
  24. };
  25. class VersionEdit {
  26. public:
  27. VersionEdit() { Clear(); }
  28. ~VersionEdit() = default;
  29. void Clear();
  30. void SetComparatorName(const Slice& name) {
  31. has_comparator_ = true;
  32. comparator_ = name.ToString();
  33. }
  34. void SetLogNumber(uint64_t num) {
  35. has_log_number_ = true;
  36. log_number_ = num;
  37. }
  38. void SetPrevLogNumber(uint64_t num) {
  39. has_prev_log_number_ = true;
  40. prev_log_number_ = num;
  41. }
  42. void SetNextFile(uint64_t num) {
  43. has_next_file_number_ = true;
  44. next_file_number_ = num;
  45. }
  46. void SetLastSequence(SequenceNumber seq) {
  47. has_last_sequence_ = true;
  48. last_sequence_ = seq;
  49. }
  50. void SetCompactPointer(int level, const InternalKey& key) {
  51. compact_pointers_.push_back(std::make_pair(level, key));
  52. }
  53. // Add the specified file at the specified number.
  54. // REQUIRES: This version has not been saved (see VersionSet::SaveTo)
  55. // REQUIRES: "smallest" and "largest" are smallest and largest keys in file
  56. void AddFile(int level, uint64_t file, uint64_t file_size,
  57. const InternalKey& smallest, const InternalKey& largest,
  58. uint64_t smallest_deadtime = UINT64_MAX, uint64_t largest_deadtime = UINT64_MAX) {
  59. FileMetaData f;
  60. f.number = file;
  61. f.file_size = file_size;
  62. f.smallest = smallest;
  63. f.largest = largest;
  64. f.smallest_deadtime = smallest_deadtime;
  65. f.largest_deadtime = largest_deadtime;
  66. new_files_.push_back(std::make_pair(level, f));
  67. }
  68. // Delete the specified "file" from the specified "level".
  69. void RemoveFile(int level, uint64_t file) {
  70. deleted_files_.insert(std::make_pair(level, file));
  71. }
  72. void EncodeTo(std::string* dst) const;
  73. Status DecodeFrom(const Slice& src);
  74. std::string DebugString() const;
  75. private:
  76. friend class VersionSet;
  77. typedef std::set<std::pair<int, uint64_t>> DeletedFileSet;
  78. std::string comparator_;
  79. uint64_t log_number_;
  80. uint64_t prev_log_number_;
  81. uint64_t next_file_number_;
  82. SequenceNumber last_sequence_;
  83. bool has_comparator_;
  84. bool has_log_number_;
  85. bool has_prev_log_number_;
  86. bool has_next_file_number_;
  87. bool has_last_sequence_;
  88. std::vector<std::pair<int, InternalKey>> compact_pointers_;
  89. DeletedFileSet deleted_files_;
  90. std::vector<std::pair<int, FileMetaData>> new_files_;
  91. };
  92. } // namespace leveldb
  93. #endif // STORAGE_LEVELDB_DB_VERSION_EDIT_H_