[btree] visitor now passed as a reference rather than shared_ptr

This commit is contained in:
Joe Thornber 2013-05-02 12:31:33 +01:00
parent 5913de5e38
commit a828cde96d
7 changed files with 23 additions and 24 deletions

View File

@ -334,7 +334,7 @@ namespace persistent_data {
};
// Walks the tree in depth first order
void visit_depth_first(typename visitor::ptr visitor) const;
void visit_depth_first(visitor &visitor) const;
private:
template <typename ValueTraits2, typename Search>
@ -362,7 +362,7 @@ namespace persistent_data {
uint64_t key,
int *index);
void walk_tree(typename visitor::ptr visitor,
void walk_tree(visitor &visitor,
btree_detail::node_location const &loc,
block_address b) const;

View File

@ -742,7 +742,7 @@ insert_location(btree_detail::shadow_spine &spine,
template <unsigned Levels, typename ValueTraits>
void
btree<Levels, ValueTraits>::visit_depth_first(typename visitor::ptr visitor) const
btree<Levels, ValueTraits>::visit_depth_first(visitor &v) const
{
node_location loc;
@ -751,13 +751,13 @@ btree<Levels, ValueTraits>::visit_depth_first(typename visitor::ptr visitor) con
loc.sub_root = true;
loc.key = boost::optional<uint64_t>();
walk_tree(visitor, loc, root_);
visitor->visit_complete();
walk_tree(v, loc, root_);
v.visit_complete();
}
template <unsigned Levels, typename ValueTraits>
void
btree<Levels, ValueTraits>::walk_tree(typename visitor::ptr visitor,
btree<Levels, ValueTraits>::walk_tree(visitor &v,
node_location const &loc,
block_address b) const
{
@ -766,7 +766,7 @@ btree<Levels, ValueTraits>::walk_tree(typename visitor::ptr visitor,
read_ref blk = tm_->read_lock(b);
internal_node o = to_node<uint64_traits>(blk);
if (o.get_type() == INTERNAL) {
if (visitor->visit_internal(loc, o))
if (v.visit_internal(loc, o))
for (unsigned i = 0; i < o.get_nr_entries(); i++) {
node_location loc2(loc);
@ -774,11 +774,11 @@ btree<Levels, ValueTraits>::walk_tree(typename visitor::ptr visitor,
loc2.sub_root = false;
loc2.key = boost::optional<uint64_t>(o.key_at(i));
walk_tree(visitor, loc2, o.value_at(i));
walk_tree(v, loc2, o.value_at(i));
}
} else if (loc.level < Levels - 1) {
if (visitor->visit_internal_leaf(loc, o))
if (v.visit_internal_leaf(loc, o))
for (unsigned i = 0; i < o.get_nr_entries(); i++) {
node_location loc2(loc);
@ -787,12 +787,12 @@ btree<Levels, ValueTraits>::walk_tree(typename visitor::ptr visitor,
loc2.sub_root = true;
loc2.key = boost::optional<uint64_t>(o.key_at(i));
walk_tree(visitor, loc, o.value_at(i));
walk_tree(v, loc, o.value_at(i));
}
} else {
leaf_node ov = to_node<ValueTraits>(blk);
visitor->visit_leaf(loc, ov);
v.visit_leaf(loc, ov);
}
}

View File

@ -360,7 +360,7 @@ namespace {
}
virtual void check(block_counter &counter) const {
ref_count_checker::ptr v(new ref_count_checker(counter));
ref_count_checker v(counter);
ref_counts_.visit_depth_first(v);
block_address nr_entries = div_up<block_address>(get_nr_blocks(), ENTRIES_PER_BLOCK);
@ -584,9 +584,9 @@ namespace {
}
virtual void check(block_counter &counter, block_address nr_index_entries) const {
bitmap_tree_validator::ptr v(new bitmap_tree_validator(counter));
bitmap_tree_validator v(counter);
bitmaps_.visit_depth_first(v);
v->check_all_index_entries_present(nr_index_entries);
v.check_all_index_entries_present(nr_index_entries);
}
private:

View File

@ -75,7 +75,7 @@ damage_list_ptr
device_checker::check()
{
block_counter counter;
device_visitor::ptr v(new device_visitor(counter));
device_visitor v(counter);
transaction_manager::ptr tm(open_core_tm(bm_));
detail_tree::ptr details(new detail_tree(tm, root_,
device_details_traits::ref_counter()));

View File

@ -198,13 +198,12 @@ thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair)
md->data_sm_->get_nr_blocks(),
md_snap);
details_extractor::ptr de(new details_extractor);
details_extractor de;
md->details_->visit_depth_first(de);
if (de->corruption() && !repair)
if (de.corruption() && !repair)
throw runtime_error("corruption in device details tree");
map<uint64_t, device_details> const &devs = de->get_devices();
map<uint64_t, device_details> const &devs = de.get_devices();
map<uint64_t, device_details>::const_iterator it, end = devs.end();
for (it = devs.begin(); it != end; ++it) {
@ -217,10 +216,10 @@ thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair)
dd.creation_time_,
dd.snapshotted_time_);
mappings_extractor::ptr me(new mappings_extractor(dev_id, e, md->metadata_sm_, md->data_sm_));
mappings_extractor me(dev_id, e, md->metadata_sm_, md->data_sm_);
md->mappings_->visit_depth_first(me);
if (me->corruption() && !repair) {
if (me.corruption() && !repair) {
ostringstream out;
out << "corruption in mappings for device " << dev_id;
throw runtime_error(out.str());

View File

@ -91,7 +91,7 @@ namespace {
void check_constraints(btree<1, uint64_traits>::ptr tree) {
typedef btree<1, uint64_traits> tree_type;
tree_type::visitor::ptr v(new constraint_visitor);
constraint_visitor v;
tree->visit_depth_first(v);
}
}

View File

@ -355,12 +355,12 @@ TEST_F(DeviceCheckerTests, damaging_some_btree_nodes_results_in_the_correct_devi
b.build();
devices_visitor::ptr scanner(new devices_visitor);
devices_visitor scanner;
transaction_manager::ptr tm = open_temporary_tm(bm_);
detail_tree::ptr devices(new detail_tree(tm, devices_root(),
device_details_traits::ref_counter()));
devices->visit_depth_first(scanner);
devices_visitor::node_info n = scanner->random_node();
devices_visitor::node_info n = scanner.random_node();
zero_block(n.b);
damage_list_ptr damage = mk_checker()->check();