Sanitise btree_detail::node_location
This commit is contained in:
@ -26,6 +26,7 @@
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
@ -266,9 +267,36 @@ namespace persistent_data {
|
||||
|
||||
// Used when visiting the nodes that make up a btree.
|
||||
struct node_location {
|
||||
unsigned level;
|
||||
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
|
||||
std::deque<uint64_t> path;
|
||||
|
||||
// in this sub tree
|
||||
unsigned depth;
|
||||
bool sub_root;
|
||||
|
||||
// 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.
|
||||
boost::optional<uint64_t> key;
|
||||
};
|
||||
}
|
||||
|
@ -746,11 +746,6 @@ btree<Levels, ValueTraits>::visit_depth_first(visitor &v) const
|
||||
{
|
||||
node_location loc;
|
||||
|
||||
loc.level = 0;
|
||||
loc.depth = 0;
|
||||
loc.sub_root = true;
|
||||
loc.key = boost::optional<uint64_t>();
|
||||
|
||||
walk_tree(v, loc, root_);
|
||||
v.visit_complete();
|
||||
}
|
||||
@ -785,29 +780,28 @@ btree<Levels, ValueTraits>::walk_tree_internal(visitor &v,
|
||||
|
||||
read_ref blk = tm_->read_lock(b, validator_);
|
||||
internal_node o = to_node<uint64_traits>(blk);
|
||||
|
||||
// FIXME: use a switch statement
|
||||
if (o.get_type() == INTERNAL) {
|
||||
if (v.visit_internal(loc, o))
|
||||
for (unsigned i = 0; i < o.get_nr_entries(); i++) {
|
||||
node_location loc2(loc);
|
||||
|
||||
loc2.depth = loc.depth + 1;
|
||||
loc2.sub_root = false;
|
||||
loc2.key = boost::optional<uint64_t>(o.key_at(i));
|
||||
loc2.inc_depth();
|
||||
loc2.key = o.key_at(i);
|
||||
|
||||
walk_tree(v, loc2, o.value_at(i));
|
||||
}
|
||||
|
||||
} else if (loc.level < Levels - 1) {
|
||||
} else if (loc.path.size() < Levels - 1) {
|
||||
if (v.visit_internal_leaf(loc, o))
|
||||
for (unsigned i = 0; i < o.get_nr_entries(); i++) {
|
||||
node_location loc2(loc);
|
||||
|
||||
loc2.level = loc.level + 1;
|
||||
loc2.depth = loc.depth + 1;
|
||||
loc2.sub_root = true;
|
||||
loc2.key = boost::optional<uint64_t>(o.key_at(i));
|
||||
loc2.push_key(o.key_at(i));
|
||||
loc2.key = optional<uint64_t>();
|
||||
|
||||
walk_tree(v, loc, o.value_at(i));
|
||||
walk_tree(v, loc2, o.value_at(i));
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -95,11 +95,11 @@ namespace persistent_data {
|
||||
if (!already_visited(n) &&
|
||||
check_block_nr(n) &&
|
||||
check_max_entries(n) &&
|
||||
check_nr_entries(n, loc.sub_root) &&
|
||||
check_nr_entries(n, loc.is_sub_root()) &&
|
||||
check_ordered_keys(n) &&
|
||||
check_parent_key(loc.sub_root ? optional<uint64_t>() : loc.key, n)) {
|
||||
if (loc.sub_root)
|
||||
new_root(loc.level);
|
||||
check_parent_key(loc.is_sub_root() ? optional<uint64_t>() : loc.key, n)) {
|
||||
if (loc.is_sub_root())
|
||||
new_root(loc.level());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -113,13 +113,13 @@ namespace persistent_data {
|
||||
if (!already_visited(n) &&
|
||||
check_block_nr(n) &&
|
||||
check_max_entries(n) &&
|
||||
check_nr_entries(n, loc.sub_root) &&
|
||||
check_nr_entries(n, loc.is_sub_root()) &&
|
||||
check_ordered_keys(n) &&
|
||||
check_parent_key(loc.sub_root ? optional<uint64_t>() : loc.key, n)) {
|
||||
if (loc.sub_root)
|
||||
new_root(loc.level);
|
||||
check_parent_key(loc.is_sub_root() ? optional<uint64_t>() : loc.key, n)) {
|
||||
if (loc.is_sub_root())
|
||||
new_root(loc.level());
|
||||
|
||||
return check_leaf_key(loc.level, n);
|
||||
return check_leaf_key(loc.level(), n);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -38,6 +38,8 @@ namespace persistent_data {
|
||||
return out;
|
||||
}
|
||||
|
||||
// Tracks damage in a single level btree. Use multiple
|
||||
// trackers if you have a multilayer tree.
|
||||
class damage_tracker {
|
||||
public:
|
||||
damage_tracker()
|
||||
@ -190,11 +192,11 @@ namespace persistent_data {
|
||||
if (!already_visited(n) &&
|
||||
check_block_nr(n) &&
|
||||
check_max_entries(n) &&
|
||||
check_nr_entries(n, loc.sub_root) &&
|
||||
check_nr_entries(n, loc.is_sub_root()) &&
|
||||
check_ordered_keys(n) &&
|
||||
check_parent_key(loc.sub_root ? optional<uint64_t>() : loc.key, n)) {
|
||||
if (loc.sub_root)
|
||||
new_root(loc.level);
|
||||
check_parent_key(loc.is_sub_root() ? optional<uint64_t>() : loc.key, n)) {
|
||||
if (loc.is_sub_root())
|
||||
new_root(loc.level());
|
||||
|
||||
good_internal(n.key_at(0));
|
||||
return true;
|
||||
@ -209,13 +211,13 @@ namespace persistent_data {
|
||||
if (!already_visited(n) &&
|
||||
check_block_nr(n) &&
|
||||
check_max_entries(n) &&
|
||||
check_nr_entries(n, loc.sub_root) &&
|
||||
check_nr_entries(n, loc.is_sub_root()) &&
|
||||
check_ordered_keys(n) &&
|
||||
check_parent_key(loc.sub_root ? optional<uint64_t>() : loc.key, n)) {
|
||||
if (loc.sub_root)
|
||||
new_root(loc.level);
|
||||
check_parent_key(loc.is_sub_root() ? optional<uint64_t>() : loc.key, n)) {
|
||||
if (loc.is_sub_root())
|
||||
new_root(loc.level());
|
||||
|
||||
bool r = check_leaf_key(loc.level, n);
|
||||
bool r = check_leaf_key(loc.level(), n);
|
||||
if (r && n.get_nr_entries() > 0)
|
||||
good_leaf(n.key_at(0), n.key_at(n.get_nr_entries() - 1) + 1);
|
||||
|
||||
@ -291,7 +293,7 @@ namespace persistent_data {
|
||||
block_address min = n.get_max_entries() / 3;
|
||||
if (!is_root && (n.get_nr_entries() < min)) {
|
||||
ostringstream out;
|
||||
out << "too few entries in btree: "
|
||||
out << "too few entries in btree_node: "
|
||||
<< n.get_nr_entries()
|
||||
<< ", expected at least "
|
||||
<< min
|
||||
|
Reference in New Issue
Block a user