作者: 韩晨旭 10225101440 李畅 10225102463
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.9 KiB

  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 DeleteFile(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_