mirror of
https://github.com/google/leveldb.git
synced 2024-12-05 06:59:06 +08:00
36a5f8ed7f
- Replace raw slice comparison with a call to user comparator. Added test for custom comparators. - Fix end of namespace comments. - Fixed bug in picking inputs for a level-0 compaction. When finding overlapping files, the covered range may expand as files are added to the input set. We now correctly expand the range when this happens instead of continuing to use the old range. For example, suppose L0 contains files with the following ranges: F1: a .. d F2: c .. g F3: f .. j and the initial compaction target is F3. We used to search for range f..j which yielded {F2,F3}. However we now expand the range as soon as another file is added. In this case, when F2 is added, we expand the range to c..j and restart the search. That picks up file F1 as well. This change fixes a bug related to deleted keys showing up incorrectly after a compaction as described in Issue 44. (Sync with upstream @25072954)
108 lines
2.9 KiB
C++
108 lines
2.9 KiB
C++
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
#ifndef STORAGE_LEVELDB_DB_VERSION_EDIT_H_
|
|
#define STORAGE_LEVELDB_DB_VERSION_EDIT_H_
|
|
|
|
#include <set>
|
|
#include <utility>
|
|
#include <vector>
|
|
#include "db/dbformat.h"
|
|
|
|
namespace leveldb {
|
|
|
|
class VersionSet;
|
|
|
|
struct FileMetaData {
|
|
int refs;
|
|
int allowed_seeks; // Seeks allowed until compaction
|
|
uint64_t number;
|
|
uint64_t file_size; // File size in bytes
|
|
InternalKey smallest; // Smallest internal key served by table
|
|
InternalKey largest; // Largest internal key served by table
|
|
|
|
FileMetaData() : refs(0), allowed_seeks(1 << 30), file_size(0) { }
|
|
};
|
|
|
|
class VersionEdit {
|
|
public:
|
|
VersionEdit() { Clear(); }
|
|
~VersionEdit() { }
|
|
|
|
void Clear();
|
|
|
|
void SetComparatorName(const Slice& name) {
|
|
has_comparator_ = true;
|
|
comparator_ = name.ToString();
|
|
}
|
|
void SetLogNumber(uint64_t num) {
|
|
has_log_number_ = true;
|
|
log_number_ = num;
|
|
}
|
|
void SetPrevLogNumber(uint64_t num) {
|
|
has_prev_log_number_ = true;
|
|
prev_log_number_ = num;
|
|
}
|
|
void SetNextFile(uint64_t num) {
|
|
has_next_file_number_ = true;
|
|
next_file_number_ = num;
|
|
}
|
|
void SetLastSequence(SequenceNumber seq) {
|
|
has_last_sequence_ = true;
|
|
last_sequence_ = seq;
|
|
}
|
|
void SetCompactPointer(int level, const InternalKey& key) {
|
|
compact_pointers_.push_back(std::make_pair(level, key));
|
|
}
|
|
|
|
// Add the specified file at the specified number.
|
|
// REQUIRES: This version has not been saved (see VersionSet::SaveTo)
|
|
// REQUIRES: "smallest" and "largest" are smallest and largest keys in file
|
|
void AddFile(int level, uint64_t file,
|
|
uint64_t file_size,
|
|
const InternalKey& smallest,
|
|
const InternalKey& largest) {
|
|
FileMetaData f;
|
|
f.number = file;
|
|
f.file_size = file_size;
|
|
f.smallest = smallest;
|
|
f.largest = largest;
|
|
new_files_.push_back(std::make_pair(level, f));
|
|
}
|
|
|
|
// Delete the specified "file" from the specified "level".
|
|
void DeleteFile(int level, uint64_t file) {
|
|
deleted_files_.insert(std::make_pair(level, file));
|
|
}
|
|
|
|
void EncodeTo(std::string* dst) const;
|
|
Status DecodeFrom(const Slice& src);
|
|
|
|
std::string DebugString() const;
|
|
|
|
private:
|
|
friend class VersionSet;
|
|
|
|
typedef std::set< std::pair<int, uint64_t> > DeletedFileSet;
|
|
|
|
std::string comparator_;
|
|
uint64_t log_number_;
|
|
uint64_t prev_log_number_;
|
|
uint64_t next_file_number_;
|
|
SequenceNumber last_sequence_;
|
|
bool has_comparator_;
|
|
bool has_log_number_;
|
|
bool has_prev_log_number_;
|
|
bool has_next_file_number_;
|
|
bool has_last_sequence_;
|
|
|
|
std::vector< std::pair<int, InternalKey> > compact_pointers_;
|
|
DeletedFileSet deleted_files_;
|
|
std::vector< std::pair<int, FileMetaData> > new_files_;
|
|
};
|
|
|
|
} // namespace leveldb
|
|
|
|
#endif // STORAGE_LEVELDB_DB_VERSION_EDIT_H_
|