thin-provisioning-tools/era/writeset_tree.h

88 lines
2.0 KiB
C
Raw Normal View History

#ifndef ERA_WRITESET_TREE_H
#define ERA_WRITESET_TREE_H
2014-01-14 23:59:12 +00:00
#include "era/era_detail.h"
#include "persistent-data/data-structures/btree.h"
//----------------------------------------------------------------
2014-01-14 23:59:12 +00:00
namespace era {
namespace writeset_tree_detail {
2014-01-14 23:59:12 +00:00
class damage_visitor;
2014-01-14 23:59:12 +00:00
class damage {
public:
damage(std::string const &desc)
: desc_(desc) {
}
2014-01-14 23:59:12 +00:00
virtual ~damage() {}
virtual void visit(damage_visitor &v) const = 0;
2014-01-14 23:59:12 +00:00
std::string const &get_desc() const {
return desc_;
}
2014-01-14 23:59:12 +00:00
private:
std::string desc_;
};
2014-01-14 23:59:12 +00:00
struct missing_eras : public damage {
missing_eras(std::string const &desc, run<uint32_t> const &eras);
virtual void visit(damage_visitor &v) const;
2014-01-14 23:59:12 +00:00
run<uint32_t> eras_;
};
struct damaged_writeset : public damage {
damaged_writeset(std::string const &desc,
uint32_t era,
run<uint32_t> missing_bits);
2014-01-14 23:59:12 +00:00
virtual void visit(damage_visitor &v) const;
2014-01-14 23:59:12 +00:00
uint32_t era_;
run<uint32_t> missing_bits_;
};
2014-01-14 23:59:12 +00:00
class damage_visitor {
public:
typedef boost::shared_ptr<damage_visitor> ptr;
2014-01-14 23:59:12 +00:00
virtual ~damage_visitor() {}
2014-01-14 23:59:12 +00:00
void visit(damage const &d) {
d.visit(*this);
}
2014-01-14 23:59:12 +00:00
virtual void visit(missing_eras const &d) = 0;
virtual void visit(damaged_writeset const &d) = 0;
2014-01-14 23:59:12 +00:00
};
class writeset_visitor {
2014-01-14 23:59:12 +00:00
public:
typedef boost::shared_ptr<writeset_visitor> ptr;
virtual ~writeset_visitor() {}
2014-01-23 00:46:03 +00:00
virtual void writeset_begin(uint32_t era, uint32_t nr_bits) = 0;
2014-01-23 00:46:03 +00:00
virtual void bit(uint32_t index, bool value) = 0;
virtual void writeset_end() = 0;
2014-01-14 23:59:12 +00:00
};
}
typedef persistent_data::btree<1, era_detail_traits> writeset_tree;
void 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);
void check_writeset_tree(persistent_data::transaction_manager::ptr tm,
writeset_tree const &tree,
writeset_tree_detail::damage_visitor &dv);
2014-01-14 23:59:12 +00:00
}
2014-01-14 23:59:12 +00:00
//----------------------------------------------------------------
#endif