From 97b35f4d7d4862da4b6f50ecaef0d292a671fd04 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Fri, 10 Feb 2017 15:50:57 -0800 Subject: [PATCH] DBObjectMap: strengthen in_complete_region post condition Previously, in_complete_region didn't guarantee anything about where it left complete_iter pointing. It will be handy for complete_iter to be pointing at the lowest interval which ends after to_test. Make it so. Signed-off-by: Samuel Just --- src/os/filestore/DBObjectMap.cc | 37 +++++++++++++++++++++++---------- src/os/filestore/DBObjectMap.h | 5 +++++ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/os/filestore/DBObjectMap.cc b/src/os/filestore/DBObjectMap.cc index d4f02e56fafc6..da771d9a66120 100644 --- a/src/os/filestore/DBObjectMap.cc +++ b/src/os/filestore/DBObjectMap.cc @@ -397,22 +397,37 @@ int DBObjectMap::DBObjectMapIteratorImpl::in_complete_region(const string &to_te string *begin, string *end) { + /* This is clumsy because one cannot call prev() on end(), nor can one + * test for == begin(). + */ complete_iter->upper_bound(to_test); - if (complete_iter->valid()) + if (complete_iter->valid()) { complete_iter->prev(); - else + if (!complete_iter->valid()) { + complete_iter->upper_bound(to_test); + return false; + } + } else { complete_iter->seek_to_last(); + if (!complete_iter->valid()) + return false; + } - if (!complete_iter->valid()) + assert(complete_iter->key() <= to_test); + assert(complete_iter->value().length() >= 1); + string _end(complete_iter->value().c_str(), + complete_iter->value().length() - 1); + if (_end.empty() || _end > to_test) { + if (begin) + *begin = complete_iter->key(); + if (end) + *end = _end; + return true; + } else { + complete_iter->next(); + assert(!complete_iter->valid() || complete_iter->key() > to_test); return false; - - string _end; - if (begin) - *begin = complete_iter->key(); - _end = string(complete_iter->value().c_str()); - if (end) - *end = _end; - return (to_test >= complete_iter->key()) && (!_end.size() || _end > to_test); + } } /** diff --git a/src/os/filestore/DBObjectMap.h b/src/os/filestore/DBObjectMap.h index 79a0f271a1a3d..b38a6535164d2 100644 --- a/src/os/filestore/DBObjectMap.h +++ b/src/os/filestore/DBObjectMap.h @@ -407,6 +407,11 @@ private: int next_parent(); /// Tests whether to_test is in complete region + /** + * Tests whether to_test is in complete region + * + * postcondition: complete_iter will be max s.t. complete_iter->value > to_test + */ int in_complete_region(const string &to_test, ///< [in] key to test string *begin, ///< [out] beginning of region string *end ///< [out] end of region -- 2.39.5