diff --git a/caching/cache_dump.cc b/caching/cache_dump.cc index edc44e5..18d36c6 100644 --- a/caching/cache_dump.cc +++ b/caching/cache_dump.cc @@ -11,8 +11,6 @@ using namespace std; using namespace caching; -using namespace caching::mapping_array_damage; -using namespace caching::superblock_damage; //---------------------------------------------------------------- @@ -30,6 +28,11 @@ namespace { return std::string(reinterpret_cast(data)); } + void raise_metadata_damage() { + throw std::runtime_error("metadata contains errors (run cache_check for details).\n" + "perhaps you wanted to run with --repair"); + } + //-------------------------------- class mapping_emitter : public mapping_visitor { @@ -48,27 +51,44 @@ namespace { }; struct ignore_mapping_damage : public mapping_array_damage::damage_visitor { - virtual void visit(missing_mappings const &d) { - } - - virtual void visit(invalid_mapping const &d) { - } + virtual void visit(mapping_array_damage::missing_mappings const &d) {} + virtual void visit(mapping_array_damage::invalid_mapping const &d) {} }; class fatal_mapping_damage : public mapping_array_damage::damage_visitor { public: - virtual void visit(missing_mappings const &d) { - raise(); + virtual void visit(mapping_array_damage::missing_mappings const &d) { + raise_metadata_damage(); } - virtual void visit(invalid_mapping const &d) { - raise(); + virtual void visit(mapping_array_damage::invalid_mapping const &d) { + raise_metadata_damage(); + } + }; + + //-------------------------------- + + class hint_emitter : public hint_visitor { + public: + hint_emitter(emitter::ptr e) + : e_(e) { + } + + virtual void visit(block_address cblock, std::vector const &data) { + e_->hint(cblock, data); } private: - static void raise() { - throw std::runtime_error("metadata contains errors (run cache_check for details).\n" - "perhaps you wanted to run with --repair"); + emitter::ptr e_; + }; + + struct ignore_hint_damage : public hint_array_damage::damage_visitor { + virtual void visit(hint_array_damage::missing_hints const &d) {} + }; + + class fatal_hint_damage : public hint_array_damage::damage_visitor { + virtual void visit(hint_array_damage::missing_hints const &d) { + raise_metadata_damage(); } }; @@ -92,20 +112,34 @@ namespace { e->begin_mappings(); { + namespace mad = mapping_array_damage; + mapping_emitter me(e); ignore_mapping_damage ignore; fatal_mapping_damage fatal; - mapping_array_damage::damage_visitor &dv = fs.repair_ ? - static_cast(ignore) : - static_cast(fatal); + mad::damage_visitor &dv = fs.repair_ ? + static_cast(ignore) : + static_cast(fatal); walk_mapping_array(*md->mappings_, me, dv); } e->end_mappings(); // walk hints + e->begin_hints(); + { + using namespace hint_array_damage; + hint_emitter he(e); + ignore_hint_damage ignore; + fatal_hint_damage fatal; + damage_visitor &dv = fs.repair_ ? + static_cast(ignore) : + static_cast(fatal); + md->hints_->walk(he, dv); + } + e->end_hints(); - // walk discards + // FIXME: walk discards e->end_superblock();