[btree] allow visitors to trap node access failures such as checksum error.

This commit is contained in:
Joe Thornber 2013-05-07 15:22:13 +01:00
parent 8e0271b3bf
commit 44d0b1903f
2 changed files with 35 additions and 0 deletions

View File

@ -331,6 +331,17 @@ namespace persistent_data {
leaf_node const &n) = 0;
virtual void visit_complete() {}
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;
}
};
// Walks the tree in depth first order
@ -366,6 +377,10 @@ namespace persistent_data {
btree_detail::node_location const &loc,
block_address b) const;
void walk_tree_internal(visitor &visitor,
btree_detail::node_location const &loc,
block_address b) const;
typename persistent_data::transaction_manager::ptr tm_;
bool destroy_;
block_address root_;

View File

@ -760,6 +760,26 @@ void
btree<Levels, ValueTraits>::walk_tree(visitor &v,
node_location const &loc,
block_address b) const
{
try {
walk_tree_internal(v, loc, b);
} catch (std::runtime_error const &e) {
switch (v.error_accessing_node(loc, b, e.what())) {
case visitor::EXCEPTION_HANDLED:
break;
case visitor::RETHROW_EXCEPTION:
throw;
}
}
}
template <unsigned Levels, typename ValueTraits>
void
btree<Levels, ValueTraits>::walk_tree_internal(visitor &v,
node_location const &loc,
block_address b) const
{
using namespace btree_detail;