2013-10-16 23:59:46 +02:00
|
|
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
2011-03-18 23:37:00 +01:00
|
|
|
// 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.
|
|
|
|
|
2013-10-05 07:32:05 +02:00
|
|
|
#pragma once
|
2011-03-18 23:37:00 +01:00
|
|
|
#include <set>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2014-01-30 00:26:43 +01:00
|
|
|
#include <string>
|
2011-03-18 23:37:00 +01:00
|
|
|
#include "db/dbformat.h"
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
class VersionSet;
|
|
|
|
|
|
|
|
struct FileMetaData {
|
|
|
|
int refs;
|
2011-06-22 04:36:45 +02:00
|
|
|
int allowed_seeks; // Seeks allowed until compaction
|
2011-03-18 23:37:00 +01:00
|
|
|
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
|
2012-10-19 23:00:53 +02:00
|
|
|
bool being_compacted; // Is this file undergoing compaction?
|
2013-06-14 07:09:08 +02:00
|
|
|
SequenceNumber smallest_seqno;// The smallest seqno in this file
|
|
|
|
SequenceNumber largest_seqno; // The largest seqno in this file
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2012-10-19 23:00:53 +02:00
|
|
|
FileMetaData() : refs(0), allowed_seeks(1 << 30), file_size(0),
|
2013-12-12 02:46:26 +01:00
|
|
|
being_compacted(false) {}
|
2011-03-18 23:37:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class VersionEdit {
|
|
|
|
public:
|
2014-01-15 00:27:09 +01:00
|
|
|
VersionEdit() { Clear(); }
|
2011-03-18 23:37:00 +01:00
|
|
|
~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;
|
|
|
|
}
|
2011-04-12 21:38:58 +02:00
|
|
|
void SetPrevLogNumber(uint64_t num) {
|
|
|
|
has_prev_log_number_ = true;
|
|
|
|
prev_log_number_ = num;
|
|
|
|
}
|
2011-03-18 23:37:00 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
2013-06-14 07:09:08 +02:00
|
|
|
const InternalKey& largest,
|
|
|
|
const SequenceNumber& smallest_seqno,
|
|
|
|
const SequenceNumber& largest_seqno) {
|
2011-03-18 23:37:00 +01:00
|
|
|
FileMetaData f;
|
|
|
|
f.number = file;
|
|
|
|
f.file_size = file_size;
|
|
|
|
f.smallest = smallest;
|
|
|
|
f.largest = largest;
|
2013-06-14 07:09:08 +02:00
|
|
|
f.smallest_seqno = smallest_seqno;
|
|
|
|
f.largest_seqno = largest_seqno;
|
|
|
|
assert(smallest_seqno <= largest_seqno);
|
2011-03-18 23:37:00 +01:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2013-06-11 23:23:58 +02:00
|
|
|
// Number of edits
|
|
|
|
int NumEntries() {
|
|
|
|
return new_files_.size() + deleted_files_.size();
|
|
|
|
}
|
|
|
|
|
2013-12-12 02:46:26 +01:00
|
|
|
void SetColumnFamily(uint32_t column_family_id) {
|
|
|
|
column_family_ = column_family_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set column family ID by calling SetColumnFamily()
|
|
|
|
void AddColumnFamily(const std::string& name) {
|
|
|
|
assert(!is_column_family_drop_);
|
|
|
|
assert(!is_column_family_add_);
|
|
|
|
assert(NumEntries() == 0);
|
|
|
|
is_column_family_add_ = true;
|
|
|
|
column_family_name_ = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set column family ID by calling SetColumnFamily()
|
|
|
|
void DropColumnFamily() {
|
|
|
|
assert(!is_column_family_drop_);
|
|
|
|
assert(!is_column_family_add_);
|
|
|
|
assert(NumEntries() == 0);
|
|
|
|
is_column_family_drop_ = true;
|
|
|
|
}
|
|
|
|
|
2011-03-18 23:37:00 +01:00
|
|
|
void EncodeTo(std::string* dst) const;
|
|
|
|
Status DecodeFrom(const Slice& src);
|
|
|
|
|
2013-08-09 00:51:16 +02:00
|
|
|
std::string DebugString(bool hex_key = false) const;
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class VersionSet;
|
|
|
|
|
|
|
|
typedef std::set< std::pair<int, uint64_t> > DeletedFileSet;
|
|
|
|
|
2013-01-24 19:54:26 +01:00
|
|
|
bool GetLevel(Slice* input, int* level, const char** msg);
|
2012-06-23 04:30:03 +02:00
|
|
|
|
2014-01-15 00:27:09 +01:00
|
|
|
int max_level_;
|
2011-03-18 23:37:00 +01:00
|
|
|
std::string comparator_;
|
|
|
|
uint64_t log_number_;
|
2011-04-12 21:38:58 +02:00
|
|
|
uint64_t prev_log_number_;
|
2011-03-18 23:37:00 +01:00
|
|
|
uint64_t next_file_number_;
|
|
|
|
SequenceNumber last_sequence_;
|
|
|
|
bool has_comparator_;
|
|
|
|
bool has_log_number_;
|
2011-04-12 21:38:58 +02:00
|
|
|
bool has_prev_log_number_;
|
2011-03-18 23:37:00 +01:00
|
|
|
bool has_next_file_number_;
|
|
|
|
bool has_last_sequence_;
|
|
|
|
|
|
|
|
DeletedFileSet deleted_files_;
|
|
|
|
std::vector< std::pair<int, FileMetaData> > new_files_;
|
2013-12-12 02:46:26 +01:00
|
|
|
|
|
|
|
// Each version edit record should have column_family_id set
|
|
|
|
// If it's not set, it is default (0)
|
|
|
|
uint32_t column_family_;
|
|
|
|
// a version edit can be either column_family add or
|
|
|
|
// column_family drop. If it's column family add,
|
|
|
|
// it also includes column family name.
|
|
|
|
bool is_column_family_drop_;
|
|
|
|
bool is_column_family_add_;
|
|
|
|
std::string column_family_name_;
|
2011-03-18 23:37:00 +01:00
|
|
|
};
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
} // namespace rocksdb
|