小组成员:10215300402-朱维清 & 10222140408 谷杰
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

106 строки
2.8 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. int refs;
  14. uint64_t number;
  15. uint64_t file_size; // File size in bytes
  16. InternalKey smallest; // Smallest internal key served by table
  17. InternalKey largest; // Largest internal key served by table
  18. FileMetaData() : refs(0), file_size(0) { }
  19. };
  20. class VersionEdit {
  21. public:
  22. VersionEdit() { Clear(); }
  23. ~VersionEdit() { }
  24. void Clear();
  25. void SetComparatorName(const Slice& name) {
  26. has_comparator_ = true;
  27. comparator_ = name.ToString();
  28. }
  29. void SetLogNumber(uint64_t num) {
  30. has_log_number_ = true;
  31. log_number_ = num;
  32. }
  33. void SetPrevLogNumber(uint64_t num) {
  34. has_prev_log_number_ = true;
  35. prev_log_number_ = num;
  36. }
  37. void SetNextFile(uint64_t num) {
  38. has_next_file_number_ = true;
  39. next_file_number_ = num;
  40. }
  41. void SetLastSequence(SequenceNumber seq) {
  42. has_last_sequence_ = true;
  43. last_sequence_ = seq;
  44. }
  45. void SetCompactPointer(int level, const InternalKey& key) {
  46. compact_pointers_.push_back(std::make_pair(level, key));
  47. }
  48. // Add the specified file at the specified number.
  49. // REQUIRES: This version has not been saved (see VersionSet::SaveTo)
  50. // REQUIRES: "smallest" and "largest" are smallest and largest keys in file
  51. void AddFile(int level, uint64_t file,
  52. uint64_t file_size,
  53. const InternalKey& smallest,
  54. const InternalKey& largest) {
  55. FileMetaData f;
  56. f.number = file;
  57. f.file_size = file_size;
  58. f.smallest = smallest;
  59. f.largest = largest;
  60. new_files_.push_back(std::make_pair(level, f));
  61. }
  62. // Delete the specified "file" from the specified "level".
  63. void DeleteFile(int level, uint64_t file) {
  64. deleted_files_.insert(std::make_pair(level, file));
  65. }
  66. void EncodeTo(std::string* dst) const;
  67. Status DecodeFrom(const Slice& src);
  68. std::string DebugString() const;
  69. private:
  70. friend class VersionSet;
  71. typedef std::set< std::pair<int, uint64_t> > DeletedFileSet;
  72. std::string comparator_;
  73. uint64_t log_number_;
  74. uint64_t prev_log_number_;
  75. uint64_t next_file_number_;
  76. SequenceNumber last_sequence_;
  77. bool has_comparator_;
  78. bool has_log_number_;
  79. bool has_prev_log_number_;
  80. bool has_next_file_number_;
  81. bool has_last_sequence_;
  82. std::vector< std::pair<int, InternalKey> > compact_pointers_;
  83. DeletedFileSet deleted_files_;
  84. std::vector< std::pair<int, FileMetaData> > new_files_;
  85. };
  86. }
  87. #endif // STORAGE_LEVELDB_DB_VERSION_EDIT_H_