2011-12-16 00:04:31 +05:30
|
|
|
// Copyright (C) 2011 Red Hat, Inc. All rights reserved.
|
2011-12-06 19:23:05 +05:30
|
|
|
//
|
2011-12-06 19:13:56 +05:30
|
|
|
// This file is part of the thin-provisioning-tools source.
|
|
|
|
//
|
|
|
|
// thin-provisioning-tools is free software: you can redistribute it
|
|
|
|
// and/or modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation, either version 3 of
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// thin-provisioning-tools is distributed in the hope that it will be
|
|
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with thin-provisioning-tools. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
2011-06-23 19:17:08 +05:30
|
|
|
#ifndef BTREE_H
|
|
|
|
#define BTREE_H
|
|
|
|
|
2013-11-19 15:53:35 +05:30
|
|
|
#include "base/endian_utils.h"
|
2013-01-12 00:56:51 +05:30
|
|
|
#include "persistent-data/transaction_manager.h"
|
2013-03-13 18:28:05 +05:30
|
|
|
#include "persistent-data/data-structures/ref_counter.h"
|
2015-08-11 16:28:07 +05:30
|
|
|
#include "persistent-data/data-structures/btree_disk_structures.h"
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <boost/optional.hpp>
|
|
|
|
#include <list>
|
2013-05-15 18:07:30 +05:30
|
|
|
#include <deque>
|
2011-07-15 19:51:28 +05:30
|
|
|
|
2011-06-23 19:17:08 +05:30
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace persistent_data {
|
2013-06-20 18:57:40 +05:30
|
|
|
class block_ref_counter : public ref_counter<block_address> {
|
|
|
|
public:
|
|
|
|
block_ref_counter(space_map::ptr sm);
|
|
|
|
|
|
|
|
virtual void set(block_address const &v, uint32_t rc);
|
|
|
|
virtual void inc(block_address const &v);
|
|
|
|
virtual void dec(block_address const &v);
|
|
|
|
|
|
|
|
private:
|
|
|
|
space_map::ptr sm_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct block_traits {
|
|
|
|
typedef base::le64 disk_type;
|
|
|
|
typedef block_address value_type;
|
|
|
|
typedef block_ref_counter ref_counter;
|
|
|
|
|
|
|
|
static void unpack(disk_type const &disk, value_type &value) {
|
|
|
|
value = base::to_cpu<uint64_t>(disk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pack(value_type const &value, disk_type &disk) {
|
|
|
|
disk = base::to_disk<base::le64>(value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
namespace btree_detail {
|
|
|
|
using namespace base;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
// Class that acts as an interface over the raw little endian btree
|
|
|
|
// node data.
|
2011-08-31 17:18:41 +05:30
|
|
|
template <typename ValueTraits>
|
2011-07-15 19:51:28 +05:30
|
|
|
class node_ref {
|
|
|
|
public:
|
2011-08-22 18:44:10 +05:30
|
|
|
explicit node_ref(block_address b, disk_node *raw);
|
|
|
|
|
2011-09-16 14:36:37 +05:30
|
|
|
uint32_t get_checksum() const;
|
|
|
|
|
2011-08-22 18:44:10 +05:30
|
|
|
block_address get_location() const {
|
|
|
|
return location_;
|
|
|
|
}
|
2011-07-15 19:51:28 +05:30
|
|
|
|
2011-08-23 16:25:37 +05:30
|
|
|
block_address get_block_nr() const;
|
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
node_type get_type() const;
|
|
|
|
void set_type(node_type t);
|
|
|
|
|
|
|
|
unsigned get_nr_entries() const;
|
|
|
|
void set_nr_entries(unsigned n);
|
|
|
|
|
|
|
|
unsigned get_max_entries() const;
|
|
|
|
void set_max_entries(unsigned n);
|
2011-07-22 20:39:56 +05:30
|
|
|
|
|
|
|
// FIXME: remove this, and get the constructor to do it.
|
2011-07-15 19:51:28 +05:30
|
|
|
void set_max_entries(); // calculates the max for you.
|
|
|
|
|
2011-08-23 16:25:37 +05:30
|
|
|
size_t get_value_size() const;
|
2011-11-01 17:01:03 +05:30
|
|
|
void set_value_size(size_t);
|
2011-08-23 16:25:37 +05:30
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
uint64_t key_at(unsigned i) const;
|
|
|
|
void set_key(unsigned i, uint64_t k);
|
|
|
|
|
|
|
|
typename ValueTraits::value_type value_at(unsigned i) const;
|
|
|
|
void set_value(unsigned i,
|
|
|
|
typename ValueTraits::value_type const &v);
|
|
|
|
|
|
|
|
// Increments the nr_entries field
|
|
|
|
void insert_at(unsigned i,
|
|
|
|
uint64_t key,
|
|
|
|
typename ValueTraits::value_type const &v);
|
|
|
|
|
|
|
|
// Does not increment nr_entries
|
|
|
|
void overwrite_at(unsigned i,
|
|
|
|
uint64_t key,
|
|
|
|
typename ValueTraits::value_type const &v);
|
|
|
|
|
2020-06-04 14:01:24 +05:30
|
|
|
// Decrements the nr_entries field
|
|
|
|
void delete_at(unsigned i);
|
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
// Copies entries from another node, appends them
|
|
|
|
// to the back of this node. Adjusts nr_entries.
|
|
|
|
void copy_entries(node_ref const &rhs,
|
|
|
|
unsigned begin,
|
|
|
|
unsigned end);
|
|
|
|
|
2020-06-04 14:01:24 +05:30
|
|
|
// Moves entries between the sibling node,
|
|
|
|
// and maintains the key ordering.
|
|
|
|
// The nr_entreis of both nodes are adjusted.
|
|
|
|
void move_entries(node_ref &rhs,
|
|
|
|
int count);
|
|
|
|
|
|
|
|
// Copies entries from the beginning of rhs to the end of lhs,
|
|
|
|
// or copies entries from the end of lhs to the beginning of rhs.
|
|
|
|
// The nr_entries is not adjusted.
|
|
|
|
void copy_entries_to_left(node_ref const &rhs, unsigned count);
|
|
|
|
void copy_entries_to_right(node_ref &rhs, unsigned count) const;
|
|
|
|
|
|
|
|
// Shifts entries to left or right.
|
|
|
|
// The nr_entries is not adjusted.
|
|
|
|
void shift_entries_left(unsigned shift);
|
|
|
|
void shift_entries_right(unsigned shift);
|
|
|
|
|
|
|
|
unsigned merge_threshold() const;
|
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
// Various searches
|
|
|
|
int bsearch(uint64_t key, int want_hi) const;
|
2013-06-25 18:18:02 +05:30
|
|
|
boost::optional<unsigned> exact_search(uint64_t key) const;
|
2011-07-15 19:51:28 +05:30
|
|
|
int lower_bound(uint64_t key) const;
|
|
|
|
|
2011-07-22 20:39:56 +05:30
|
|
|
template <typename RefCounter>
|
|
|
|
void inc_children(RefCounter &rc);
|
|
|
|
|
2020-06-02 09:17:38 +05:30
|
|
|
template <typename RefCounter>
|
|
|
|
void dec_children(RefCounter &rc);
|
|
|
|
|
2011-09-16 14:36:37 +05:30
|
|
|
disk_node *raw() {
|
|
|
|
return raw_;
|
|
|
|
}
|
|
|
|
|
|
|
|
disk_node const *raw() const {
|
2011-07-22 20:39:56 +05:30
|
|
|
return raw_;
|
|
|
|
}
|
|
|
|
|
2015-05-26 16:36:34 +05:30
|
|
|
bool value_sizes_match() const;
|
|
|
|
std::string value_mismatch_string() const;
|
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
private:
|
|
|
|
static unsigned calc_max_entries(void);
|
2014-06-06 19:35:41 +05:30
|
|
|
void check_fits_within_block() const;
|
2011-07-15 19:51:28 +05:30
|
|
|
|
|
|
|
void *key_ptr(unsigned i) const;
|
|
|
|
void *value_ptr(unsigned i) const;
|
|
|
|
|
2011-08-22 18:44:10 +05:30
|
|
|
block_address location_;
|
2011-07-15 19:51:28 +05:30
|
|
|
disk_node *raw_;
|
2014-06-06 19:35:41 +05:30
|
|
|
|
|
|
|
mutable bool checked_; // flag indicating we've checked the data fits in the block
|
2011-07-15 19:51:28 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
//
|
2011-08-31 17:18:41 +05:30
|
|
|
template <typename ValueTraits>
|
|
|
|
node_ref<ValueTraits>
|
2020-04-30 19:00:01 +05:30
|
|
|
to_node(typename block_manager::read_ref &b)
|
2011-07-15 19:51:28 +05:30
|
|
|
{
|
|
|
|
// FIXME: this should return a const read_ref somehow.
|
2011-08-31 17:18:41 +05:30
|
|
|
return node_ref<ValueTraits>(
|
2011-08-22 18:44:10 +05:30
|
|
|
b.get_location(),
|
2011-07-15 19:51:28 +05:30
|
|
|
reinterpret_cast<disk_node *>(
|
2014-07-25 19:16:51 +05:30
|
|
|
const_cast<void *>(b.data())));
|
2011-07-15 19:51:28 +05:30
|
|
|
}
|
|
|
|
|
2011-08-31 17:18:41 +05:30
|
|
|
template <typename ValueTraits>
|
|
|
|
node_ref<ValueTraits>
|
2020-04-30 19:00:01 +05:30
|
|
|
to_node(typename block_manager::write_ref &b)
|
2011-07-15 19:51:28 +05:30
|
|
|
{
|
2011-08-31 17:18:41 +05:30
|
|
|
return node_ref<ValueTraits>(
|
2011-08-22 18:44:10 +05:30
|
|
|
b.get_location(),
|
2014-07-25 19:16:51 +05:30
|
|
|
reinterpret_cast<disk_node *>(b.data()));
|
2011-07-15 19:51:28 +05:30
|
|
|
}
|
|
|
|
|
2013-06-25 18:18:02 +05:30
|
|
|
class ro_spine : private boost::noncopyable {
|
2011-07-15 19:51:28 +05:30
|
|
|
public:
|
2014-08-26 15:44:49 +05:30
|
|
|
ro_spine(transaction_manager &tm,
|
2014-07-25 19:16:51 +05:30
|
|
|
bcache::validator::ptr v)
|
2013-04-26 18:45:20 +05:30
|
|
|
: tm_(tm),
|
|
|
|
validator_(v) {
|
2011-07-15 19:51:28 +05:30
|
|
|
}
|
|
|
|
|
2011-11-03 20:14:00 +05:30
|
|
|
void step(block_address b);
|
2011-07-15 19:51:28 +05:30
|
|
|
|
|
|
|
template <typename ValueTraits>
|
2011-08-31 17:18:41 +05:30
|
|
|
node_ref<ValueTraits> get_node() {
|
|
|
|
return to_node<ValueTraits>(spine_.back());
|
2011-07-15 19:51:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-08-26 15:44:49 +05:30
|
|
|
transaction_manager &tm_;
|
2014-07-25 19:16:51 +05:30
|
|
|
bcache::validator::ptr validator_;
|
2020-04-30 19:00:01 +05:30
|
|
|
std::list<block_manager::read_ref> spine_;
|
2011-07-15 19:51:28 +05:30
|
|
|
};
|
|
|
|
|
2013-06-25 18:18:02 +05:30
|
|
|
class shadow_spine : private boost::noncopyable {
|
2011-07-15 19:51:28 +05:30
|
|
|
public:
|
2011-09-01 15:12:57 +05:30
|
|
|
typedef transaction_manager::read_ref read_ref;
|
|
|
|
typedef transaction_manager::write_ref write_ref;
|
2013-08-15 20:56:17 +05:30
|
|
|
typedef boost::optional<block_address> maybe_block;
|
2011-08-24 18:57:45 +05:30
|
|
|
|
2014-08-26 15:44:49 +05:30
|
|
|
shadow_spine(transaction_manager &tm,
|
2014-07-25 19:16:51 +05:30
|
|
|
bcache::validator::ptr v)
|
2013-04-26 18:45:20 +05:30
|
|
|
|
|
|
|
: tm_(tm),
|
|
|
|
validator_(v) {
|
2011-07-15 19:51:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// true if the children of the shadow need incrementing
|
2011-11-03 20:14:00 +05:30
|
|
|
bool step(block_address b);
|
2011-09-01 15:12:57 +05:30
|
|
|
void step(transaction_manager::write_ref b) {
|
2011-07-15 19:51:28 +05:30
|
|
|
spine_.push_back(b);
|
|
|
|
if (spine_.size() == 1)
|
|
|
|
root_ = spine_.front().get_location();
|
|
|
|
else if (spine_.size() > 2)
|
|
|
|
spine_.pop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pop() {
|
|
|
|
spine_.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ValueTraits>
|
2011-08-31 17:18:41 +05:30
|
|
|
node_ref<ValueTraits> get_node() {
|
|
|
|
return to_node<ValueTraits>(spine_.back());
|
2011-07-15 19:51:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
block_address get_block() const {
|
|
|
|
return spine_.back().get_location();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_parent() const {
|
|
|
|
return spine_.size() > 1;
|
|
|
|
}
|
|
|
|
|
2013-06-20 18:57:40 +05:30
|
|
|
node_ref<block_traits> get_parent() {
|
2011-07-15 19:51:28 +05:30
|
|
|
if (spine_.size() < 2)
|
|
|
|
throw std::runtime_error("no parent");
|
|
|
|
|
2013-06-20 18:57:40 +05:30
|
|
|
return to_node<block_traits>(spine_.front());
|
2011-07-15 19:51:28 +05:30
|
|
|
}
|
|
|
|
|
2011-07-22 20:39:56 +05:30
|
|
|
block_address get_parent_location() const {
|
|
|
|
return spine_.front().get_location();
|
|
|
|
}
|
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
block_address get_root() const {
|
2013-08-15 20:56:17 +05:30
|
|
|
if (root_)
|
|
|
|
return *root_;
|
|
|
|
|
|
|
|
throw std::runtime_error("shadow spine has no root");
|
2011-07-15 19:51:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-08-26 15:44:49 +05:30
|
|
|
transaction_manager &tm_;
|
2014-07-25 19:16:51 +05:30
|
|
|
bcache::validator::ptr validator_;
|
2020-04-30 19:00:01 +05:30
|
|
|
std::list<block_manager::write_ref> spine_;
|
2013-08-15 20:56:17 +05:30
|
|
|
maybe_block root_;
|
2011-07-15 19:51:28 +05:30
|
|
|
};
|
2013-05-01 20:46:23 +05:30
|
|
|
|
2020-06-04 14:01:24 +05:30
|
|
|
class shadow_child {
|
|
|
|
public:
|
|
|
|
shadow_child(block_manager::write_ref &wr, node_type type)
|
|
|
|
: wr_(wr), type_(type) {
|
|
|
|
}
|
|
|
|
|
|
|
|
node_type get_type() const {
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ValueTraits>
|
|
|
|
node_ref<ValueTraits> get_node() {
|
|
|
|
return to_node<ValueTraits>(wr_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
block_manager::write_ref wr_;
|
|
|
|
node_type type_;
|
|
|
|
};
|
|
|
|
|
2013-05-17 15:28:34 +05:30
|
|
|
// Used to keep a record of a nested btree's position.
|
|
|
|
typedef std::vector<uint64_t> btree_path;
|
|
|
|
|
2013-05-01 20:46:23 +05:30
|
|
|
// Used when visiting the nodes that make up a btree.
|
|
|
|
struct node_location {
|
2013-05-15 18:07:30 +05:30
|
|
|
node_location()
|
|
|
|
: depth(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void inc_depth() {
|
|
|
|
depth++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void push_key(uint64_t k) {
|
|
|
|
path.push_back(k);
|
|
|
|
depth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_sub_root() const {
|
|
|
|
return depth == 0; // && path.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned level() const {
|
|
|
|
return path.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keys used to access this sub tree
|
2013-05-17 15:28:34 +05:30
|
|
|
btree_path path;
|
2013-05-15 18:07:30 +05:30
|
|
|
|
|
|
|
// in this sub tree
|
2013-05-01 20:46:23 +05:30
|
|
|
unsigned depth;
|
2013-05-15 18:07:30 +05:30
|
|
|
|
|
|
|
// This is the key from the parent node to this
|
|
|
|
// node. If this node is a root then there will be
|
|
|
|
// no parent, and hence no key.
|
2013-05-01 20:46:23 +05:30
|
|
|
boost::optional<uint64_t> key;
|
|
|
|
};
|
2011-07-15 19:51:28 +05:30
|
|
|
}
|
|
|
|
|
2011-08-31 17:18:41 +05:30
|
|
|
template <unsigned Levels, typename ValueTraits>
|
2011-06-23 19:17:08 +05:30
|
|
|
class btree {
|
|
|
|
public:
|
2020-04-30 19:32:43 +05:30
|
|
|
typedef std::shared_ptr<btree<Levels, ValueTraits> > ptr;
|
2011-07-15 19:51:28 +05:30
|
|
|
|
2011-06-23 19:17:08 +05:30
|
|
|
typedef uint64_t key[Levels];
|
|
|
|
typedef typename ValueTraits::value_type value_type;
|
|
|
|
typedef boost::optional<value_type> maybe_value;
|
|
|
|
typedef boost::optional<std::pair<unsigned, value_type> > maybe_pair;
|
2020-04-30 19:00:01 +05:30
|
|
|
typedef typename block_manager::read_ref read_ref;
|
|
|
|
typedef typename block_manager::write_ref write_ref;
|
2011-08-31 17:18:41 +05:30
|
|
|
typedef typename btree_detail::node_ref<ValueTraits> leaf_node;
|
2013-06-20 18:57:40 +05:30
|
|
|
typedef typename btree_detail::node_ref<block_traits> internal_node;
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2014-08-26 15:44:49 +05:30
|
|
|
btree(transaction_manager &tm,
|
2011-07-22 20:39:56 +05:30
|
|
|
typename ValueTraits::ref_counter rc);
|
|
|
|
|
2014-08-26 15:44:49 +05:30
|
|
|
btree(transaction_manager &tm,
|
2011-07-22 20:39:56 +05:30
|
|
|
block_address root,
|
|
|
|
typename ValueTraits::ref_counter rc);
|
|
|
|
|
2011-06-23 19:17:08 +05:30
|
|
|
~btree();
|
|
|
|
|
|
|
|
maybe_value lookup(key const &key) const;
|
|
|
|
maybe_pair lookup_le(key const &key) const;
|
|
|
|
maybe_pair lookup_ge(key const &key) const;
|
|
|
|
|
2016-08-10 21:10:48 +05:30
|
|
|
bool insert(key const &key, typename ValueTraits::value_type const &value);
|
2011-06-23 19:17:08 +05:30
|
|
|
void remove(key const &key);
|
|
|
|
|
|
|
|
void set_root(block_address root);
|
|
|
|
block_address get_root() const;
|
|
|
|
|
|
|
|
ptr clone() const;
|
|
|
|
|
|
|
|
// free the on disk btree when the destructor is called
|
|
|
|
void destroy();
|
|
|
|
|
2011-08-22 16:25:55 +05:30
|
|
|
|
|
|
|
// Derive a class from this base class if you need to
|
|
|
|
// inspect the individual nodes that make up a btree.
|
|
|
|
class visitor {
|
|
|
|
public:
|
2020-04-30 19:32:43 +05:30
|
|
|
typedef std::shared_ptr<visitor> ptr;
|
2013-05-01 20:46:23 +05:30
|
|
|
typedef btree_detail::node_location node_location;
|
|
|
|
|
|
|
|
virtual ~visitor() {}
|
2011-08-22 16:25:55 +05:30
|
|
|
|
2011-08-26 15:43:13 +05:30
|
|
|
// The bool return values indicate whether the walk
|
|
|
|
// should be continued into sub trees of the node (true == continue).
|
2013-05-01 20:46:23 +05:30
|
|
|
virtual bool visit_internal(node_location const &l,
|
2011-09-02 15:56:42 +05:30
|
|
|
internal_node const &n) = 0;
|
2013-05-01 20:46:23 +05:30
|
|
|
virtual bool visit_internal_leaf(node_location const &l,
|
2011-09-02 15:56:42 +05:30
|
|
|
internal_node const &n) = 0;
|
2013-05-01 20:46:23 +05:30
|
|
|
virtual bool visit_leaf(node_location const &l,
|
2011-09-02 15:56:42 +05:30
|
|
|
leaf_node const &n) = 0;
|
2011-10-10 18:40:30 +05:30
|
|
|
|
|
|
|
virtual void visit_complete() {}
|
2013-05-07 19:52:13 +05:30
|
|
|
|
|
|
|
|
|
|
|
enum error_outcome {
|
|
|
|
EXCEPTION_HANDLED,
|
|
|
|
RETHROW_EXCEPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual error_outcome error_accessing_node(node_location const &l, block_address b,
|
|
|
|
std::string const &what) {
|
|
|
|
return RETHROW_EXCEPTION;
|
|
|
|
}
|
2011-08-22 16:25:55 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
// Walks the tree in depth first order
|
2013-05-02 17:01:33 +05:30
|
|
|
void visit_depth_first(visitor &visitor) const;
|
2011-08-22 16:25:55 +05:30
|
|
|
|
2011-06-23 19:17:08 +05:30
|
|
|
private:
|
2011-11-01 17:01:03 +05:30
|
|
|
template <typename ValueTraits2, typename Search>
|
2013-05-28 18:18:10 +05:30
|
|
|
boost::optional<typename ValueTraits2::value_type>
|
2011-11-01 17:01:03 +05:30
|
|
|
lookup_raw(btree_detail::ro_spine &spine, block_address block, uint64_t key) const;
|
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
template <typename ValueTraits2>
|
2011-08-31 17:18:41 +05:30
|
|
|
void split_node(btree_detail::shadow_spine &spine,
|
2011-07-15 19:51:28 +05:30
|
|
|
block_address parent_index,
|
|
|
|
uint64_t key,
|
|
|
|
bool top);
|
2011-06-27 15:15:30 +05:30
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
template <typename ValueTraits2>
|
2011-08-31 17:18:41 +05:30
|
|
|
void split_beneath(btree_detail::shadow_spine &spine, uint64_t key);
|
2011-06-27 15:15:30 +05:30
|
|
|
|
2011-07-15 19:51:28 +05:30
|
|
|
template <typename ValueTraits2>
|
2011-08-31 17:18:41 +05:30
|
|
|
void split_sibling(btree_detail::shadow_spine &spine,
|
2011-07-15 19:51:28 +05:30
|
|
|
block_address parent_index,
|
|
|
|
uint64_t key);
|
2011-06-27 15:15:30 +05:30
|
|
|
|
2013-06-19 21:50:12 +05:30
|
|
|
template <typename ValueTraits2, typename RC>
|
2011-07-15 19:51:28 +05:30
|
|
|
bool
|
2011-08-31 17:18:41 +05:30
|
|
|
insert_location(btree_detail::shadow_spine &spine,
|
2011-07-15 19:51:28 +05:30
|
|
|
block_address block,
|
|
|
|
uint64_t key,
|
2013-06-19 21:50:12 +05:30
|
|
|
int *index,
|
|
|
|
RC &leaf_rc);
|
2011-07-15 19:51:28 +05:30
|
|
|
|
2020-06-04 14:01:24 +05:30
|
|
|
template <typename ValueTraits2, typename RC>
|
|
|
|
bool
|
|
|
|
remove_location(btree_detail::shadow_spine &spine,
|
|
|
|
block_address block,
|
|
|
|
uint64_t key,
|
|
|
|
unsigned *index,
|
|
|
|
RC &leaf_rc);
|
|
|
|
|
2013-05-02 17:01:33 +05:30
|
|
|
void walk_tree(visitor &visitor,
|
2013-05-01 20:46:23 +05:30
|
|
|
btree_detail::node_location const &loc,
|
2011-08-25 20:57:58 +05:30
|
|
|
block_address b) const;
|
2011-08-22 16:25:55 +05:30
|
|
|
|
2013-05-07 19:52:13 +05:30
|
|
|
void walk_tree_internal(visitor &visitor,
|
|
|
|
btree_detail::node_location const &loc,
|
|
|
|
block_address b) const;
|
|
|
|
|
2013-06-20 16:47:16 +05:30
|
|
|
template <typename ValueTraits2, typename RefCounter>
|
|
|
|
void inc_children(btree_detail::shadow_spine &spine,
|
|
|
|
RefCounter &leaf_rc);
|
|
|
|
|
2020-06-04 14:01:24 +05:30
|
|
|
btree_detail::shadow_child
|
|
|
|
create_shadow_child(internal_node &parent,
|
|
|
|
unsigned index);
|
|
|
|
|
|
|
|
template <typename ValueTraits2>
|
|
|
|
bool rebalance_children(btree_detail::shadow_spine &spine,
|
|
|
|
uint64_t key);
|
|
|
|
|
|
|
|
template <typename ValueTraits2>
|
|
|
|
void rebalance2(btree_detail::shadow_spine &spine,
|
|
|
|
unsigned left_index);
|
|
|
|
|
|
|
|
template <typename ValueTraits2>
|
|
|
|
void rebalance3(btree_detail::shadow_spine &spine,
|
|
|
|
unsigned left_index);
|
|
|
|
|
|
|
|
template <typename ValueTraits2>
|
|
|
|
void
|
|
|
|
__rebalance2(internal_node &parent,
|
|
|
|
btree_detail::node_ref<ValueTraits2> &left,
|
|
|
|
btree_detail::node_ref<ValueTraits2> &right,
|
|
|
|
unsigned left_index);
|
|
|
|
|
|
|
|
template <typename ValueTraits2>
|
|
|
|
void
|
|
|
|
__rebalance3(internal_node &parent,
|
|
|
|
btree_detail::node_ref<ValueTraits2> &left,
|
|
|
|
btree_detail::node_ref<ValueTraits2> ¢er,
|
|
|
|
btree_detail::node_ref<ValueTraits2> &right,
|
|
|
|
unsigned left_index);
|
|
|
|
|
|
|
|
template <typename ValueTraits2>
|
|
|
|
void
|
|
|
|
delete_center_node(internal_node &parent,
|
|
|
|
btree_detail::node_ref<ValueTraits2> &left,
|
|
|
|
btree_detail::node_ref<ValueTraits2> ¢er,
|
|
|
|
btree_detail::node_ref<ValueTraits2> &right,
|
|
|
|
unsigned left_index);
|
|
|
|
|
|
|
|
template <typename ValueTraits2>
|
|
|
|
void
|
|
|
|
redistribute3(internal_node &parent,
|
|
|
|
btree_detail::node_ref<ValueTraits2> &left,
|
|
|
|
btree_detail::node_ref<ValueTraits2> ¢er,
|
|
|
|
btree_detail::node_ref<ValueTraits2> &right,
|
|
|
|
unsigned left_index);
|
|
|
|
|
2014-08-26 15:44:49 +05:30
|
|
|
transaction_manager &tm_;
|
2011-07-15 19:51:28 +05:30
|
|
|
bool destroy_;
|
|
|
|
block_address root_;
|
2013-06-20 18:57:40 +05:30
|
|
|
block_ref_counter internal_rc_;
|
2011-07-22 20:39:56 +05:30
|
|
|
typename ValueTraits::ref_counter rc_;
|
2014-07-25 19:16:51 +05:30
|
|
|
typename bcache::validator::ptr validator_;
|
2011-06-27 15:15:30 +05:30
|
|
|
};
|
2011-06-23 19:17:08 +05:30
|
|
|
};
|
|
|
|
|
2011-06-27 15:15:30 +05:30
|
|
|
#include "btree.tcc"
|
2020-06-04 14:01:24 +05:30
|
|
|
#include "btree-remove.tcc"
|
2011-06-27 15:15:30 +05:30
|
|
|
|
2011-06-23 19:17:08 +05:30
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|