Skip to content

Commit

Permalink
tools: Check for overlaps in internal "complete" table for DBObjectMap
Browse files Browse the repository at this point in the history
Changed check to return an error count and fix tool error message

Signed-off-by: David Zafman <dzafman@redhat.com>
  • Loading branch information
dzafman committed Mar 27, 2017
1 parent f410159 commit e5e8eb9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/os/ObjectMap.h
Expand Up @@ -138,7 +138,7 @@ class ObjectMap {
const SequencerPosition *spos=0 ///< [in] Sequencer
) { return 0; }

virtual bool check(std::ostream &out) { return true; }
virtual int check(std::ostream &out) { return 0; }

typedef KeyValueDB::GenericIteratorImpl ObjectMapIteratorImpl;
typedef ceph::shared_ptr<ObjectMapIteratorImpl> ObjectMapIterator;
Expand Down
24 changes: 19 additions & 5 deletions src/os/filestore/DBObjectMap.cc
Expand Up @@ -55,9 +55,9 @@ static void append_escaped(const string &in, string *out)
}
}

bool DBObjectMap::check(std::ostream &out)
int DBObjectMap::check(std::ostream &out)
{
bool retval = true;
int errors = 0;
map<uint64_t, uint64_t> parent_to_num_children;
map<uint64_t, uint64_t> parent_to_actual_num_children;
KeyValueDB::Iterator iter = db->get_iterator(HOBJECT_TO_SEQ);
Expand All @@ -69,6 +69,20 @@ bool DBObjectMap::check(std::ostream &out)
header.decode(bliter);
if (header.seq != 0)
parent_to_actual_num_children[header.seq] = header.num_children;

// Check complete table
boost::optional<string> prev;
KeyValueDB::Iterator complete_iter = db->get_iterator(USER_PREFIX + header_key(header.seq) + COMPLETE_PREFIX);
for (complete_iter->seek_to_first(); complete_iter->valid();
complete_iter->next()) {
if (prev && prev >= complete_iter->key()) {
out << "Bad complete for " << header.oid << std::endl;
errors++;
break;
}
prev = string(complete_iter->value().c_str(), complete_iter->value().length() - 1);
}

if (header.parent == 0)
break;

Expand All @@ -84,7 +98,7 @@ bool DBObjectMap::check(std::ostream &out)
db->get(sys_parent_prefix(header), to_get, &got);
if (got.empty()) {
out << "Missing: seq " << header.parent << std::endl;
retval = false;
errors++;
break;
} else {
bl = got.begin()->second;
Expand All @@ -101,11 +115,11 @@ bool DBObjectMap::check(std::ostream &out)
out << "Invalid: seq " << i->first << " recorded children: "
<< parent_to_actual_num_children[i->first] << " found: "
<< i->second << std::endl;
retval = false;
errors++;
}
parent_to_actual_num_children.erase(i->first);
}
return retval;
return errors;
}

string DBObjectMap::ghobject_key(const ghobject_t &oid)
Expand Down
2 changes: 1 addition & 1 deletion src/os/filestore/DBObjectMap.h
Expand Up @@ -213,7 +213,7 @@ class DBObjectMap : public ObjectMap {
int upgrade_to_v2();

/// Consistency check, debug, there must be no parallel writes
bool check(std::ostream &out) override;
int check(std::ostream &out) override;

/// Ensure that all previous operations are durable
int sync(const ghobject_t *oid=0, const SequencerPosition *spos=0) override;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ObjectMap/test_object_map.cc
Expand Up @@ -542,7 +542,7 @@ class ObjectMapTest : public ::testing::Test {

void TearDown() override {
std::cerr << "Checking..." << std::endl;
assert(db->check(std::cerr));
assert(db->check(std::cerr) == 0);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/tools/ceph_osdomap_tool.cc
Expand Up @@ -150,8 +150,8 @@ int main(int argc, char **argv) {
}
} else if (cmd == "check") {
r = omap.check(std::cout);
if (!r) {
std::cerr << "check got: " << cpp_strerror(r) << std::endl;
if (r > 0) {
std::cerr << "check got " << r << " error(s)" << std::endl;
goto done;
}
std::cout << "check succeeded" << std::endl;
Expand Down

0 comments on commit e5e8eb9

Please sign in to comment.