diff --git a/caching/cache_check.cc b/caching/cache_check.cc index 2cbd0e4..b660e01 100644 --- a/caching/cache_check.cc +++ b/caching/cache_check.cc @@ -87,11 +87,35 @@ namespace { using reporter_base::get_error; }; - class mapping_reporter : public reporter_base { + class mapping_reporter : public mapping_array_damage::damage_visitor, reporter_base { public: mapping_reporter(nested_output &o) : reporter_base(o) { } + + virtual void visit(mapping_array_damage::missing_mappings const &d) { + out() << "missing mappings:" << end_message(); + { + nested_output::nest _ = push(); + out() << d.get_desc() << end_message(); + } + + mplus_error(FATAL); + } + + virtual void visit(mapping_array_damage::invalid_mapping const &d) { + out() << "invalid mapping:" << end_message(); + { + nested_output::nest _ = push(); + out() << d.get_desc() + << " [cblock = " << d.cblock_ + << ", oblock = " << d.m_.oblock_ + << ", flags = " << d.m_.flags_ + << "]" << end_message(); + } + + mplus_error(FATAL); + } }; class hint_reporter : public reporter_base { diff --git a/caching/mapping_array.cc b/caching/mapping_array.cc index 1477431..d2a7e48 100644 --- a/caching/mapping_array.cc +++ b/caching/mapping_array.cc @@ -28,12 +28,10 @@ mapping_traits::pack(value_type const &value, disk_type &disk) //---------------------------------------------------------------- -missing_mappings::missing_mappings(run const &keys, - std::string const &desc) - : keys_(keys), - desc_(desc) +missing_mappings::missing_mappings(std::string const &desc, run const &keys) + : damage(desc), + keys_(keys) { - } void @@ -42,6 +40,20 @@ missing_mappings::visit(damage_visitor &v) const v.visit(*this); } +invalid_mapping::invalid_mapping(std::string const &desc, + block_address cblock, mapping const &m) + : damage(desc), + cblock_(cblock), + m_(m) +{ +} + +void +invalid_mapping::visit(damage_visitor &v) const +{ + v.visit(*this); +} + namespace { struct no_op_visitor { virtual void visit(uint32_t index, @@ -56,7 +68,7 @@ namespace { } virtual void visit(array_detail::damage const &d) { - v_.visit(missing_mappings(d.lost_keys_, d.desc_)); + v_.visit(missing_mappings(d.desc_, d.lost_keys_)); } private: diff --git a/caching/mapping_array.h b/caching/mapping_array.h index fde0c28..29f9390 100644 --- a/caching/mapping_array.h +++ b/caching/mapping_array.h @@ -28,17 +28,36 @@ namespace caching { namespace mapping_array_damage { class damage_visitor; - struct damage { + class damage { + public: + damage(std::string const &desc) + : desc_(desc) { + } + virtual ~damage() {} virtual void visit(damage_visitor &v) const = 0; + + std::string get_desc() const { + return desc_; + } + + private: + std::string desc_; }; struct missing_mappings : public damage { - missing_mappings(run const &keys, std::string const &desc); + missing_mappings(std::string const &desc, run const &keys); virtual void visit(damage_visitor &v) const; run keys_; - std::string desc_; + }; + + struct invalid_mapping : public damage { + invalid_mapping(std::string const &desc, block_address cblock, mapping const &m); + virtual void visit(damage_visitor &v) const; + + block_address cblock_; + mapping m_; }; class damage_visitor { @@ -50,6 +69,7 @@ namespace caching { } virtual void visit(missing_mappings const &d) = 0; + virtual void visit(invalid_mapping const &d) = 0; }; }