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.
5 #ifndef STORAGE_LEVELDB_DB_VERSION_EDIT_H_
6 #define STORAGE_LEVELDB_DB_VERSION_EDIT_H_
11 #include "db/dbformat.h"
19 int allowed_seeks; // Seeks allowed until compaction
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
25 FileMetaData() : refs(0), allowed_seeks(1 << 30), file_size(0) { }
30 VersionEdit() { Clear(); }
35 void SetComparatorName(const Slice& name) {
36 has_comparator_ = true;
37 comparator_ = name.ToString();
39 void SetLogNumber(uint64_t num) {
40 has_log_number_ = true;
43 void SetPrevLogNumber(uint64_t num) {
44 has_prev_log_number_ = true;
45 prev_log_number_ = num;
47 void SetNextFile(uint64_t num) {
48 has_next_file_number_ = true;
49 next_file_number_ = num;
51 void SetLastSequence(SequenceNumber seq) {
52 has_last_sequence_ = true;
55 void SetCompactPointer(int level, const InternalKey& key) {
56 compact_pointers_.push_back(std::make_pair(level, key));
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 void AddFile(int level, uint64_t file,
64 const InternalKey& smallest,
65 const InternalKey& largest) {
68 f.file_size = file_size;
69 f.smallest = smallest;
71 new_files_.push_back(std::make_pair(level, f));
74 // Delete the specified "file" from the specified "level".
75 void DeleteFile(int level, uint64_t file) {
76 deleted_files_.insert(std::make_pair(level, file));
79 void EncodeTo(std::string* dst) const;
80 Status DecodeFrom(const Slice& src);
82 std::string DebugString() const;
85 friend class VersionSet;
87 typedef std::set< std::pair<int, uint64_t> > DeletedFileSet;
89 std::string comparator_;
91 uint64_t prev_log_number_;
92 uint64_t next_file_number_;
93 SequenceNumber last_sequence_;
96 bool has_prev_log_number_;
97 bool has_next_file_number_;
98 bool has_last_sequence_;
100 std::vector< std::pair<int, InternalKey> > compact_pointers_;
101 DeletedFileSet deleted_files_;
102 std::vector< std::pair<int, FileMetaData> > new_files_;
105 } // namespace leveldb
107 #endif // STORAGE_LEVELDB_DB_VERSION_EDIT_H_