[cache_dump] hints are dumped, and respect --repair

This commit is contained in:
Joe Thornber 2013-10-09 09:48:20 +01:00
parent 19a1596591
commit 97f4f0b0bb

View File

@ -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<char const *>(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<unsigned char> 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<mapping_array_damage::damage_visitor &>(ignore) :
static_cast<mapping_array_damage::damage_visitor &>(fatal);
mad::damage_visitor &dv = fs.repair_ ?
static_cast<mad::damage_visitor &>(ignore) :
static_cast<mad::damage_visitor &>(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<damage_visitor &>(ignore) :
static_cast<damage_visitor &>(fatal);
md->hints_->walk(he, dv);
}
e->end_hints();
// walk discards
// FIXME: walk discards
e->end_superblock();