| 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 |
|
| |
| 5 |
|
| #ifndef STORAGE_LEVELDB_DB_VERSION_EDIT_H_ |
| 6 |
|
| #define STORAGE_LEVELDB_DB_VERSION_EDIT_H_ |
| 7 |
|
| |
| 8 |
|
| #include <set> |
| 9 |
|
| #include <utility> |
| 10 |
|
| #include <vector> |
| 11 |
|
| #include "db/dbformat.h" |
| 12 |
|
| |
| 13 |
|
| namespace leveldb { |
| 14 |
|
| |
| 15 |
|
| class VersionSet; |
| 16 |
|
| |
| 17 |
|
| struct FileMetaData { |
| 18 |
|
| int refs; |
| 19 |
|
| int allowed_seeks; // Seeks allowed until compaction |
| 20 |
|
| uint64_t number; |
| 21 |
|
| uint64_t file_size; // File size in bytes |
| 22 |
|
| InternalKey smallest; // Smallest internal key served by table |
| 23 |
|
| InternalKey largest; // Largest internal key served by table |
| 24 |
|
| |
| 25 |
6 |
| FileMetaData() : refs(0), allowed_seeks(1 << 30), file_size(0) { } |
| 26 |
|
| }; |
| 27 |
|
| |
| 28 |
|
| class VersionEdit { |
| 29 |
|
| public: |
| 30 |
13 |
▶ | VersionEdit() { Clear(); } |
Branch: 1 branch
| Branch | True | False | Total |
| VersionEdit() { Clear(); } |
13 |
0 |
13 |
|
| 31 |
13 |
| ~VersionEdit() { } |
| 32 |
|
| |
| 33 |
|
| void Clear(); |
| 34 |
|
| |
| 35 |
5 |
| void SetComparatorName(const Slice& name) { |
| 36 |
5 |
| has_comparator_ = true; |
| 37 |
5 |
▶ | comparator_ = name.ToString(); |
Branch: 1 branch
| Branch | True | False | Total |
| comparator_ = name.ToString(); |
5 |
0 |
5 |
|
| 38 |
5 |
| } |
| 39 |
5 |
| void SetLogNumber(uint64_t num) { |
| 40 |
5 |
| has_log_number_ = true; |
| 41 |
5 |
| log_number_ = num; |
| 42 |
5 |
| } |
| 43 |
3 |
| void SetPrevLogNumber(uint64_t num) { |
| 44 |
3 |
| has_prev_log_number_ = true; |
| 45 |
3 |
| prev_log_number_ = num; |
| 46 |
3 |
| } |
| 47 |
8 |
| void SetNextFile(uint64_t num) { |
| 48 |
8 |
| has_next_file_number_ = true; |
| 49 |
8 |
| next_file_number_ = num; |
| 50 |
8 |
| } |
| 51 |
5 |
| void SetLastSequence(SequenceNumber seq) { |
| 52 |
5 |
| has_last_sequence_ = true; |
| 53 |
5 |
| last_sequence_ = seq; |
| 54 |
5 |
| } |
| 55 |
|
| void SetCompactPointer(int level, const InternalKey& key) { |
| 56 |
|
| compact_pointers_.push_back(std::make_pair(level, key)); |
| 57 |
|
| } |
| 58 |
|
| |
| 59 |
|
| // Add the specified file at the specified number. |
| 60 |
|
| // REQUIRES: This version has not been saved (see VersionSet::SaveTo) |
| 61 |
|
| // REQUIRES: "smallest" and "largest" are smallest and largest keys in file |
| 62 |
1 |
| void AddFile(int level, uint64_t file, |
| 63 |
|
| uint64_t file_size, |
| 64 |
|
| const InternalKey& smallest, |
| 65 |
|
| const InternalKey& largest) { |
| 66 |
1 |
| FileMetaData f; |
| 67 |
1 |
| f.number = file; |
| 68 |
1 |
| f.file_size = file_size; |
| 69 |
1 |
▶ | f.smallest = smallest; |
Branch: 1 branch
| Branch | True | False | Total |
| f.smallest = smallest; |
1 |
0 |
1 |
|
| 70 |
1 |
▶ | f.largest = largest; |
Branch: 1 branch
| Branch | True | False | Total |
| f.largest = largest; |
1 |
0 |
1 |
|
| 71 |
1 |
▶ | new_files_.push_back(std::make_pair(level, f)); |
Branch: 2 branches
| Branch | True | False | Total |
| new_files_.push_back(std::make_pair(level, f)); |
1 |
0 |
1 |
| new_files_.push_back(std::make_pair(level, f)); |
1 |
0 |
1 |
|
| 72 |
1 |
| } |
| 73 |
|
| |
| 74 |
|
| // Delete the specified "file" from the specified "level". |
| 75 |
0 |
| void DeleteFile(int level, uint64_t file) { |
| 76 |
0 |
▶ | deleted_files_.insert(std::make_pair(level, file)); |
Branch: 2 branches
| Branch | True | False | Total |
| deleted_files_.insert(std::make_pair(level, file)); |
0 |
0 |
0 |
| deleted_files_.insert(std::make_pair(level, file)); |
0 |
0 |
0 |
|
| 77 |
0 |
| } |
| 78 |
|
| |
| 79 |
|
| void EncodeTo(std::string* dst) const; |
| 80 |
|
| Status DecodeFrom(const Slice& src); |
| 81 |
|
| |
| 82 |
|
| std::string DebugString() const; |
| 83 |
|
| |
| 84 |
|
| private: |
| 85 |
|
| friend class VersionSet; |
| 86 |
|
| |
| 87 |
|
| typedef std::set< std::pair<int, uint64_t> > DeletedFileSet; |
| 88 |
|
| |
| 89 |
|
| std::string comparator_; |
| 90 |
|
| uint64_t log_number_; |
| 91 |
|
| uint64_t prev_log_number_; |
| 92 |
|
| uint64_t next_file_number_; |
| 93 |
|
| SequenceNumber last_sequence_; |
| 94 |
|
| bool has_comparator_; |
| 95 |
|
| bool has_log_number_; |
| 96 |
|
| bool has_prev_log_number_; |
| 97 |
|
| bool has_next_file_number_; |
| 98 |
|
| bool has_last_sequence_; |
| 99 |
|
| |
| 100 |
|
| std::vector< std::pair<int, InternalKey> > compact_pointers_; |
| 101 |
|
| DeletedFileSet deleted_files_; |
| 102 |
|
| std::vector< std::pair<int, FileMetaData> > new_files_; |
| 103 |
|
| }; |
| 104 |
|
| |
| 105 |
|
| } |
| 106 |
|
| |
| 107 |
|
| #endif // STORAGE_LEVELDB_DB_VERSION_EDIT_H_ |