2013-10-16 21:59:46 +00: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 22:37:00 +00: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 05:32:05 +00:00
|
|
|
#pragma once
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/types.h"
|
|
|
|
#include "rocksdb/write_batch.h"
|
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/options.h"
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
namespace rocksdb {
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2011-07-15 00:20:57 +00:00
|
|
|
class MemTable;
|
|
|
|
|
2014-01-28 19:05:04 +00:00
|
|
|
class ColumnFamilyMemTables {
|
|
|
|
public:
|
2014-02-06 00:02:48 +00:00
|
|
|
virtual ~ColumnFamilyMemTables() {}
|
|
|
|
virtual bool Seek(uint32_t column_family_id) = 0;
|
|
|
|
// returns true if the update to memtable should be ignored
|
|
|
|
// (useful when recovering from log whose updates have already
|
|
|
|
// been processed)
|
|
|
|
virtual uint64_t GetLogNumber() const = 0;
|
|
|
|
virtual MemTable* GetMemTable() const = 0;
|
|
|
|
virtual const Options* GetFullOptions() const = 0;
|
2014-02-11 01:04:44 +00:00
|
|
|
virtual ColumnFamilyHandle* GetColumnFamilyHandle() = 0;
|
2014-02-06 00:02:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ColumnFamilyMemTablesDefault : public ColumnFamilyMemTables {
|
|
|
|
public:
|
|
|
|
ColumnFamilyMemTablesDefault(MemTable* mem, const Options* options)
|
|
|
|
: ok_(false), mem_(mem), options_(options) {}
|
|
|
|
|
|
|
|
bool Seek(uint32_t column_family_id) override {
|
|
|
|
ok_ = (column_family_id == 0);
|
|
|
|
return ok_;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t GetLogNumber() const override { return 0; }
|
|
|
|
|
|
|
|
MemTable* GetMemTable() const override {
|
|
|
|
assert(ok_);
|
|
|
|
return mem_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Options* GetFullOptions() const override {
|
|
|
|
assert(ok_);
|
|
|
|
return options_;
|
|
|
|
}
|
|
|
|
|
2014-02-11 01:04:44 +00:00
|
|
|
ColumnFamilyHandle* GetColumnFamilyHandle() override { return nullptr; }
|
2014-02-06 00:02:48 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool ok_;
|
|
|
|
MemTable* mem_;
|
|
|
|
const Options* const options_;
|
2014-01-28 19:05:04 +00:00
|
|
|
};
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
// WriteBatchInternal provides static methods for manipulating a
|
|
|
|
// WriteBatch that we don't want in the public WriteBatch interface.
|
|
|
|
class WriteBatchInternal {
|
|
|
|
public:
|
|
|
|
// Return the number of entries in the batch.
|
|
|
|
static int Count(const WriteBatch* batch);
|
|
|
|
|
|
|
|
// Set the count for the number of entries in the batch.
|
|
|
|
static void SetCount(WriteBatch* batch, int n);
|
|
|
|
|
|
|
|
// Return the seqeunce number for the start of this batch.
|
|
|
|
static SequenceNumber Sequence(const WriteBatch* batch);
|
|
|
|
|
|
|
|
// Store the specified number as the seqeunce number for the start of
|
|
|
|
// this batch.
|
|
|
|
static void SetSequence(WriteBatch* batch, SequenceNumber seq);
|
|
|
|
|
|
|
|
static Slice Contents(const WriteBatch* batch) {
|
|
|
|
return Slice(batch->rep_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t ByteSize(const WriteBatch* batch) {
|
|
|
|
return batch->rep_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetContents(WriteBatch* batch, const Slice& contents);
|
|
|
|
|
2013-07-12 23:56:52 +00:00
|
|
|
// Inserts batch entries into memtable
|
2014-02-06 00:02:48 +00:00
|
|
|
// If dont_filter_deletes is false AND options.filter_deletes is true,
|
|
|
|
// then --> Drops deletes in batch if db->KeyMayExist returns false
|
2014-03-03 22:30:36 +00:00
|
|
|
// If recovery == true, this means InsertInto is executed on a recovery
|
|
|
|
// code-path. WriteBatch referencing a dropped column family can be
|
|
|
|
// found on a recovery code-path and should be ignored (recovery should not
|
|
|
|
// fail). Additionally, the memtable will be updated only if
|
2014-02-06 00:02:48 +00:00
|
|
|
// memtables->GetLogNumber() >= log_number
|
2014-03-03 22:30:36 +00:00
|
|
|
// However, if recovery == false, any WriteBatch referencing
|
|
|
|
// non-existing column family will return a failure. Also, log_number is
|
|
|
|
// ignored in that case
|
2014-01-28 19:05:04 +00:00
|
|
|
static Status InsertInto(const WriteBatch* batch,
|
|
|
|
ColumnFamilyMemTables* memtables,
|
2014-03-03 22:30:36 +00:00
|
|
|
bool recovery = false, uint64_t log_number = 0,
|
|
|
|
DB* db = nullptr,
|
2014-02-06 00:02:48 +00:00
|
|
|
const bool dont_filter_deletes = true);
|
2014-01-28 19:05:04 +00:00
|
|
|
|
2012-03-09 00:23:21 +00:00
|
|
|
static void Append(WriteBatch* dst, const WriteBatch* src);
|
2011-03-18 22:37:00 +00:00
|
|
|
};
|
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
} // namespace rocksdb
|