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-15 05:29:12 +05:30
#include "era/era_detail.h"
#include "persistent-data/data-structures/btree.h"
//----------------------------------------------------------------
2014-01-15 05:29:12 +05:30
namespace era {
namespace writeset_tree_detail {
2014-01-15 05:29:12 +05:30
class damage_visitor;
2014-01-15 05:29:12 +05:30
class damage {
public:
damage(std::string const &desc)
: desc_(desc) {
}
2014-01-15 05:29:12 +05:30
virtual ~damage() {}
virtual void visit(damage_visitor &v) const = 0;
2014-01-15 05:29:12 +05:30
std::string const &get_desc() const {
return desc_;
}
2014-01-15 05:29:12 +05:30
private:
std::string desc_;
};
2014-01-15 05:29:12 +05:30
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-15 05:29:12 +05:30
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-15 05:29:12 +05:30
virtual void visit(damage_visitor &v) const;
2014-01-15 05:29:12 +05:30
uint32_t era_;
run<uint32_t> missing_bits_;
};
2014-01-15 05:29:12 +05:30
class damage_visitor {
public:
typedef std::shared_ptr<damage_visitor> ptr;
2014-01-15 05:29:12 +05:30
virtual ~damage_visitor() {}
2014-01-15 05:29:12 +05:30
void visit(damage const &d) {
d.visit(*this);
}
2014-01-15 05:29:12 +05:30
virtual void visit(missing_eras const &d) = 0;
virtual void visit(damaged_writeset const &d) = 0;
2014-01-15 05:29:12 +05:30
};
class writeset_visitor {
2014-01-15 05:29:12 +05:30
public:
typedef std::shared_ptr<writeset_visitor> ptr;
virtual ~writeset_visitor() {}
2014-01-23 06:16:03 +05:30
virtual void writeset_begin(uint32_t era, uint32_t nr_bits) = 0;
2014-01-23 06:16:03 +05:30
virtual void bit(uint32_t index, bool value) = 0;
virtual void writeset_end() = 0;
2014-01-15 05:29:12 +05:30
};
}
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-15 05:29:12 +05:30
}
2014-01-15 05:29:12 +05:30
//----------------------------------------------------------------
#endif