diff options
author | Sage Weil <sage.weil@dreamhost.com> | 2012-04-20 00:31:51 +0200 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2012-04-21 01:56:06 +0200 |
commit | 92b299afc51be1fa4081b7b79e398aea7f9b3e4e (patch) | |
tree | fb46de6ac52f75a521b36fefb7cec1820b5d8e03 | |
parent | test_idempotent_sequence: Use FileStoreDiff class instead. (diff) | |
download | ceph-92b299afc51be1fa4081b7b79e398aea7f9b3e4e.tar.xz ceph-92b299afc51be1fa4081b7b79e398aea7f9b3e4e.zip |
FileStoreDiff: flip sense of diff*() methods around
true means diff, false means same.
Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
-rw-r--r-- | src/test/filestore/FileStoreDiff.cc | 102 | ||||
-rw-r--r-- | src/test/filestore/test_idempotent_sequence.cc | 6 |
2 files changed, 66 insertions, 42 deletions
diff --git a/src/test/filestore/FileStoreDiff.cc b/src/test/filestore/FileStoreDiff.cc index 13ba96460e9..d241d143b3e 100644 --- a/src/test/filestore/FileStoreDiff.cc +++ b/src/test/filestore/FileStoreDiff.cc @@ -45,80 +45,87 @@ FileStoreDiff::~FileStoreDiff() bool FileStoreDiff::diff_attrs(std::map<std::string,bufferptr>& b, std::map<std::string,bufferptr>& a) { + bool ret = false; std::map<std::string, bufferptr>::iterator b_it = b.begin(); std::map<std::string, bufferptr>::iterator a_it = a.begin(); for (; b_it != b.end(); ++b_it, ++a_it) { if (b_it->first != a_it->first) { dout(0) << "diff_attrs name mismatch (verify: " << b_it->first << ", store: " << a_it->first << ")" << dendl; - return false; + ret = true; + continue; } if (!b_it->second.cmp(a_it->second)) { dout(0) << "diff_attrs contents mismatch on attr " << b_it->first << dendl; - return false; + ret = true; + continue; } } - return true; + return ret; } bool FileStoreDiff::diff_objects_stat(struct stat& a, struct stat& b) { + bool ret = false; + if (a.st_uid != b.st_uid) { dout(0) << "diff_objects_stat uid mismatch (A: " << a.st_uid << " != B: " << b.st_uid << ")" << dendl; - return false; + ret = true; } if (a.st_gid != b.st_gid) { dout(0) << "diff_objects_stat gid mismatch (A: " << a.st_gid << " != B: " << b.st_gid << ")" << dendl; - return false; + ret = true; } if (a.st_mode != b.st_mode) { dout(0) << "diff_objects_stat mode mismatch (A: " << a.st_mode << " != B: " << b.st_mode << ")" << dendl; - return false; + ret = true; } if (a.st_nlink != b.st_nlink) { dout(0) << "diff_objects_stat nlink mismatch (A: " << a.st_nlink << " != B: " << b.st_nlink << ")" << dendl; - return false; + ret = true; } if (a.st_size != b.st_size) { dout(0) << "diff_objects_stat size mismatch (A: " << a.st_size << " != B: " << b.st_size << ")" << dendl; - return false; + ret = true; } - return true; + return ret; } bool FileStoreDiff::diff_objects(FileStore *a_store, FileStore *b_store, coll_t coll) { - dout(0) << __func__ << " coll " << coll << dendl; + dout(2) << __func__ << " coll " << coll << dendl; + + bool ret = false; int err; std::vector<hobject_t> b_objects, a_objects; err = b_store->collection_list(coll, b_objects); if (err < 0) { dout(0) << "diff_objects list on verify coll " << coll.to_str() - << " returns " << err << dendl; - return false; + << " returns " << err << dendl; + return true; } err = a_store->collection_list(coll, a_objects); if (err < 0) { dout(0) << "diff_objects list on store coll " << coll.to_str() << " returns " << err << dendl; - return false; + return true; } if (b_objects.size() != a_objects.size()) { dout(0) << "diff_objects num objs mismatch (A: " << a_objects.size() << ", B: " << b_objects.size() << ")" << dendl; - return false; + ret = true; } std::vector<hobject_t>::iterator b_it = b_objects.begin(); @@ -129,27 +136,28 @@ bool FileStoreDiff::diff_objects(FileStore *a_store, FileStore *b_store, coll_t dout(0) << "diff_objects name mismatch on A object " << coll << "/" << a_obj << " and B object " << coll << "/" << b_obj << dendl; - return false; + ret = true; + continue; } struct stat b_stat, a_stat; err = b_store->stat(coll, b_obj, &b_stat); if (err < 0) { dout(0) << "diff_objects error stating B object " - << coll.to_str() << "/" << b_obj.oid.name << dendl; - return false; + << coll.to_str() << "/" << b_obj.oid.name << dendl; + ret = true; } err = a_store->stat(coll, a_obj, &a_stat); if (err < 0) { dout(0) << "diff_objects error stating A object " << coll << "/" << a_obj << dendl; - return false; + ret = true; } - if (!diff_objects_stat(a_stat, b_stat)) { + if (diff_objects_stat(a_stat, b_stat)) { dout(0) << "diff_objects stat mismatch on " << coll << "/" << b_obj << dendl; - return false; + ret = true; } bufferlist a_obj_bl, b_obj_bl; @@ -159,7 +167,7 @@ bool FileStoreDiff::diff_objects(FileStore *a_store, FileStore *b_store, coll_t if (!a_obj_bl.contents_equal(b_obj_bl)) { dout(0) << "diff_objects content mismatch on " << coll << "/" << b_obj << dendl; - return false; + ret = true; } std::map<std::string, bufferptr> a_obj_attrs_map, b_obj_attrs_map; @@ -167,56 +175,60 @@ bool FileStoreDiff::diff_objects(FileStore *a_store, FileStore *b_store, coll_t if (err < 0) { dout(0) << "diff_objects getattrs on A object " << coll << "/" << a_obj << " returns " << err << dendl; - return false; + ret = true; } err = b_store->getattrs(coll, b_obj, b_obj_attrs_map); if (err < 0) { dout(0) << "diff_objects getattrs on B object " << coll << "/" << b_obj << "returns " << err << dendl; - return false; + ret = true; } - if (!diff_attrs(b_obj_attrs_map, a_obj_attrs_map)) { + if (diff_attrs(b_obj_attrs_map, a_obj_attrs_map)) { dout(0) << "diff_objects attrs mismatch on A object " << coll << "/" << a_obj << " and B object " << coll << "/" << b_obj << dendl; - return false; + ret = true; } } - return true; + return ret; } bool FileStoreDiff::diff_coll_attrs(FileStore *a_store, FileStore *b_store, coll_t coll) { + bool ret = false; + int err; std::map<std::string, bufferptr> b_coll_attrs, a_coll_attrs; err = b_store->collection_getattrs(coll, b_coll_attrs); if (err < 0) { dout(0) << "diff_attrs getattrs on verify coll " << coll.to_str() << "returns " << err << dendl; - return false; + ret = true; } err = a_store->collection_getattrs(coll, a_coll_attrs); if (err < 0) { dout(0) << "diff_attrs getattrs on A coll " << coll.to_str() << "returns " << err << dendl; - return false; + ret = true; } if (b_coll_attrs.size() != a_coll_attrs.size()) { dout(0) << "diff_attrs size mismatch (A: " << a_coll_attrs.size() << ", B: " << a_coll_attrs.size() << ")" << dendl; - return false; + ret = true; } - return diff_attrs(b_coll_attrs, a_coll_attrs); + return diff_attrs(b_coll_attrs, a_coll_attrs) || ret; } bool FileStoreDiff::diff() { - bool ret = true; - std::vector<coll_t> a_coll_list, b_coll_list;; + bool ret = false; + + std::vector<coll_t> a_coll_list, b_coll_list; + a_store->list_collections(a_coll_list); b_store->list_collections(b_coll_list); std::vector<coll_t>::iterator it = b_coll_list.begin(); @@ -224,16 +236,28 @@ bool FileStoreDiff::diff() coll_t b_coll = *it; if (!a_store->collection_exists(b_coll)) { dout(0) << "diff B coll " << b_coll.to_str() << " DNE on A" << dendl; - return false; + ret = true; + continue; + } + for (std::vector<coll_t>::iterator j = a_coll_list.begin(); + j != a_coll_list.end(); ++j) { + if (*j == *it) { + a_coll_list.erase(j); + break; + } } - ret = diff_coll_attrs(a_store, b_store, b_coll); - if (!ret) - break; + if (diff_coll_attrs(a_store, b_store, b_coll)) + ret = true; - ret = diff_objects(a_store, b_store, b_coll); - if (!ret) - break; + if (diff_objects(a_store, b_store, b_coll)) + ret = true; } + for (std::vector<coll_t>::iterator it = a_coll_list.begin(); + it != a_coll_list.end(); ++it) { + dout(0) << "diff A coll " << *it << " DNE on B" << dendl; + ret = true; + } + return ret; } diff --git a/src/test/filestore/test_idempotent_sequence.cc b/src/test/filestore/test_idempotent_sequence.cc index 2214bf594eb..9d8f46abc91 100644 --- a/src/test/filestore/test_idempotent_sequence.cc +++ b/src/test/filestore/test_idempotent_sequence.cc @@ -85,10 +85,10 @@ int run_diff(std::string& a_path, std::string& a_journal, FileStoreDiff fsd(a, b); int ret = 0; if (fsd.diff()) { - dout(0) << "diff looks okay!" << dendl; - } else { - dout(0) << "diff found an error." << dendl; + dout(0) << "diff found an difference" << dendl; ret = -1; + } else { + dout(0) << "no diff" << dendl; } return ret; |