提供基本的ttl测试用例
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.

107 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. int refs;
  14. int allowed_seeks; // Seeks allowed until compaction
  15. uint64_t number;
  16. uint64_t file_size; // File size in bytes
  17. InternalKey smallest; // Smallest internal key served by table
  18. InternalKey largest; // Largest internal key served by table
  19. FileMetaData() : refs(0), allowed_seeks(1 << 30), file_size(0) { }
  20. };
  21. class VersionEdit {
  22. public:
  23. VersionEdit() { Clear(); }
  24. ~VersionEdit() { }
  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,
  53. uint64_t file_size,
  54. const InternalKey& smallest,
  55. const InternalKey& largest) {
  56. FileMetaData f;
  57. f.number = file;
  58. f.file_size = file_size;
  59. f.smallest = smallest;
  60. f.largest = largest;
  61. new_files_.push_back(std::make_pair(level, f));
  62. }
  63. // Delete the specified "file" from the specified "level".
  64. void DeleteFile(int level, uint64_t file) {
  65. deleted_files_.insert(std::make_pair(level, file));
  66. }
  67. void EncodeTo(std::string* dst) const;
  68. Status DecodeFrom(const Slice& src);
  69. std::string DebugString() const;
  70. private:
  71. friend class VersionSet;
  72. typedef std::set< std::pair<int, uint64_t> > DeletedFileSet;
  73. std::string comparator_;
  74. uint64_t log_number_;
  75. uint64_t prev_log_number_;
  76. uint64_t next_file_number_;
  77. SequenceNumber last_sequence_;
  78. bool has_comparator_;
  79. bool has_log_number_;
  80. bool has_prev_log_number_;
  81. bool has_next_file_number_;
  82. bool has_last_sequence_;
  83. std::vector< std::pair<int, InternalKey> > compact_pointers_;
  84. DeletedFileSet deleted_files_;
  85. std::vector< std::pair<int, FileMetaData> > new_files_;
  86. };
  87. } // namespace leveldb
  88. #endif // STORAGE_LEVELDB_DB_VERSION_EDIT_H_