diff --git a/space_map_disk.cc b/space_map_disk.cc index 9ac5b2b..20e0add 100644 --- a/space_map_disk.cc +++ b/space_map_disk.cc @@ -318,13 +318,44 @@ namespace { bool visit_leaf(unsigned level, bool is_root, btree_detail::node_ref const &n) { bool r = btree_checker<1, index_entry_traits>::visit_leaf(level, is_root, n); + if (!r) + return r; - if (r) - for (unsigned i = 0; i < n.get_nr_entries(); i++) - btree_checker<1, index_entry_traits>::get_counter().inc(n.value_at(i).blocknr_); + for (unsigned i = 0; i < n.get_nr_entries(); i++) { + if (seen_indexes_.count(n.key_at(i)) > 0) { + ostringstream out; + out << "index entry " << i << " is present twice"; + throw runtime_error(out.str()); + } - return r; + seen_indexes_.insert(n.key_at(i)); + btree_checker<1, index_entry_traits>::get_counter().inc(n.value_at(i).blocknr_); + } + + return true; } + + void check_all_index_entries_present(block_address nr_entries) { + for (block_address i = 0; i < nr_entries; i++) { + if (seen_indexes_.count(i) == 0) { + ostringstream out; + out << "missing index entry " << i; + throw runtime_error(out.str()); + } + } + + set::const_iterator it; + for (it = seen_indexes_.begin(); it != seen_indexes_.end(); ++it) { + if (*it >= nr_entries) { + ostringstream out; + out << "unexpected index entry " << *it; + throw runtime_error(out.str()); + } + } + } + + private: + set seen_indexes_; }; class sm_disk : public sm_disk_base { @@ -366,6 +397,9 @@ namespace { bitmap_tree_validator::ptr v(new bitmap_tree_validator(counter)); bitmaps_.visit(v); + + block_address nr_entries = div_up(get_nr_blocks(), get_entries_per_block()); + v->check_all_index_entries_present(nr_entries); } private: diff --git a/thin_dump.cc b/thin_dump.cc index 554434c..accbe69 100644 --- a/thin_dump.cc +++ b/thin_dump.cc @@ -12,7 +12,6 @@ namespace { void dump(string const &path) { metadata md(path); //human_readable::ptr emitter(new human_readable); - // md.dump(); }