2014-01-30 03:07:25 +05:30
|
|
|
#include "era/writeset_tree.h"
|
2014-01-15 05:29:12 +05:30
|
|
|
#include "persistent-data/data-structures/btree_damage_visitor.h"
|
|
|
|
#include "persistent-data/data-structures/bitset.h"
|
|
|
|
|
|
|
|
using namespace boost;
|
|
|
|
using namespace era;
|
2014-01-30 03:07:25 +05:30
|
|
|
using namespace writeset_tree_detail;
|
2014-01-15 05:29:12 +05:30
|
|
|
using namespace persistent_data;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
missing_eras::missing_eras(string const &desc,
|
|
|
|
run<uint32_t> const &eras)
|
|
|
|
: damage(desc),
|
|
|
|
eras_(eras)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
missing_eras::visit(damage_visitor &v) const {
|
|
|
|
v.visit(*this);
|
|
|
|
}
|
|
|
|
|
2014-01-30 03:07:25 +05:30
|
|
|
damaged_writeset::damaged_writeset(string const &desc,
|
|
|
|
uint32_t era,
|
|
|
|
run<uint32_t> missing_bits)
|
2014-01-15 05:29:12 +05:30
|
|
|
: damage(desc),
|
|
|
|
era_(era),
|
|
|
|
missing_bits_(missing_bits)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-30 03:07:25 +05:30
|
|
|
damaged_writeset::visit(damage_visitor &v) const
|
2014-01-15 05:29:12 +05:30
|
|
|
{
|
|
|
|
v.visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
2014-01-30 03:07:25 +05:30
|
|
|
class ll_writeset_visitor : public bitset_detail::bitset_visitor {
|
2014-01-15 05:29:12 +05:30
|
|
|
public:
|
|
|
|
typedef persistent_data::transaction_manager::ptr tm_ptr;
|
|
|
|
|
2014-01-30 03:07:25 +05:30
|
|
|
ll_writeset_visitor(tm_ptr tm,
|
|
|
|
writeset_tree_detail::writeset_visitor &writeset_v,
|
|
|
|
writeset_tree_detail::damage_visitor &dv)
|
2014-01-15 05:29:12 +05:30
|
|
|
: tm_(tm),
|
2014-06-26 19:59:33 +05:30
|
|
|
era_(0),
|
2014-01-30 03:07:25 +05:30
|
|
|
writeset_v_(writeset_v),
|
2014-01-15 05:29:12 +05:30
|
|
|
dv_(dv) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void visit(btree_path const &path, era_detail const &era) {
|
|
|
|
era_ = path[0];
|
2014-04-01 22:13:15 +05:30
|
|
|
persistent_data::bitset bs(tm_, era.writeset_root, era.nr_bits);
|
2014-01-30 03:07:25 +05:30
|
|
|
writeset_v_.writeset_begin(era_, era.nr_bits);
|
2014-01-15 05:29:12 +05:30
|
|
|
bs.walk_bitset(*this);
|
2014-01-30 03:07:25 +05:30
|
|
|
writeset_v_.writeset_end();
|
2014-01-15 05:29:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void visit(uint32_t index, bool value) {
|
2014-01-30 03:07:25 +05:30
|
|
|
writeset_v_.bit(index, value);
|
2014-01-15 05:29:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void visit(bitset_detail::missing_bits const &d) {
|
2014-01-30 03:07:25 +05:30
|
|
|
dv_.visit(writeset_tree_detail::damaged_writeset("missing bits", era_, d.keys_));
|
2014-01-15 05:29:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
tm_ptr tm_;
|
|
|
|
uint64_t era_;
|
2014-01-30 03:07:25 +05:30
|
|
|
writeset_tree_detail::writeset_visitor &writeset_v_;
|
|
|
|
writeset_tree_detail::damage_visitor &dv_;
|
2014-01-15 05:29:12 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
class ll_damage_visitor {
|
|
|
|
public:
|
|
|
|
ll_damage_visitor(damage_visitor &v)
|
|
|
|
: v_(v) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void visit(btree_path const &path,
|
|
|
|
btree_detail::damage const &d) {
|
|
|
|
v_.visit(missing_eras(d.desc_, to_uint32(d.lost_keys_)));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <typename T>
|
|
|
|
run<uint32_t> to_uint32(run<T> const &r) {
|
|
|
|
return run<uint32_t>(optional<uint32_t>(r.begin_),
|
|
|
|
optional<uint32_t>(r.end_));
|
|
|
|
}
|
|
|
|
|
|
|
|
damage_visitor &v_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-30 03:07:25 +05:30
|
|
|
era::walk_writeset_tree(persistent_data::transaction_manager::ptr tm,
|
|
|
|
writeset_tree const &tree,
|
|
|
|
writeset_tree_detail::writeset_visitor &writeset_v,
|
|
|
|
writeset_tree_detail::damage_visitor &dv)
|
2014-01-15 05:29:12 +05:30
|
|
|
{
|
2014-01-30 03:07:25 +05:30
|
|
|
ll_writeset_visitor ll_bv(tm, writeset_v, dv);
|
2014-01-15 05:29:12 +05:30
|
|
|
ll_damage_visitor ll_dv(dv);
|
|
|
|
btree_visit_values(tree, ll_bv, ll_dv);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2014-01-30 03:07:25 +05:30
|
|
|
class noop_writeset_visitor : public writeset_tree_detail::writeset_visitor {
|
2014-01-15 05:29:12 +05:30
|
|
|
public:
|
2014-01-30 03:07:25 +05:30
|
|
|
void writeset_begin(uint32_t era, uint32_t nr_bits) {
|
2014-01-23 06:16:03 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void bit(uint32_t index, bool value) {
|
|
|
|
}
|
|
|
|
|
2014-01-30 03:07:25 +05:30
|
|
|
void writeset_end() {
|
2014-01-15 05:29:12 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2014-01-30 03:07:25 +05:30
|
|
|
era::check_writeset_tree(persistent_data::transaction_manager::ptr tm,
|
|
|
|
writeset_tree const &tree,
|
|
|
|
writeset_tree_detail::damage_visitor &dv)
|
2014-01-15 05:29:12 +05:30
|
|
|
{
|
2014-01-30 03:07:25 +05:30
|
|
|
noop_writeset_visitor bv;
|
|
|
|
walk_writeset_tree(tm, tree, bv, dv);
|
2014-01-15 05:29:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|