From: Sage Weil Date: Fri, 10 Feb 2017 23:39:53 +0000 (-0500) Subject: common/hobject: remove cmp_* comparators; add normal operators X-Git-Tag: v12.0.1~427^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=43244da571b88c1a9d8b2aa76d6d69de31108327;p=ceph.git common/hobject: remove cmp_* comparators; add normal operators Fix up callers. Signed-off-by: Sage Weil --- diff --git a/src/common/hobject.cc b/src/common/hobject.cc index 14acd4ba24f5..a965c87d6224 100644 --- a/src/common/hobject.cc +++ b/src/common/hobject.cc @@ -319,40 +319,7 @@ bool hobject_t::parse(const string &s) return true; } -int cmp_nibblewise(const hobject_t& l, const hobject_t& r) -{ - if (l.max < r.max) - return -1; - if (l.max > r.max) - return 1; - if (l.pool < r.pool) - return -1; - if (l.pool > r.pool) - return 1; - if (l.get_nibblewise_key() < r.get_nibblewise_key()) - return -1; - if (l.get_nibblewise_key() > r.get_nibblewise_key()) - return 1; - if (l.nspace < r.nspace) - return -1; - if (l.nspace > r.nspace) - return 1; - if (l.get_effective_key() < r.get_effective_key()) - return -1; - if (l.get_effective_key() > r.get_effective_key()) - return 1; - if (l.oid < r.oid) - return -1; - if (l.oid > r.oid) - return 1; - if (l.snap < r.snap) - return -1; - if (l.snap > r.snap) - return 1; - return 0; -} - -int cmp_bitwise(const hobject_t& l, const hobject_t& r) +int cmp(const hobject_t& l, const hobject_t& r) { if (l.max < r.max) return -1; @@ -606,27 +573,7 @@ bool ghobject_t::parse(const string& s) return true; } -int cmp_nibblewise(const ghobject_t& l, const ghobject_t& r) -{ - if (l.max < r.max) - return -1; - if (l.max > r.max) - return 1; - if (l.shard_id < r.shard_id) - return -1; - if (l.shard_id > r.shard_id) - return 1; - int ret = cmp_nibblewise(l.hobj, r.hobj); - if (ret != 0) - return ret; - if (l.generation < r.generation) - return -1; - if (l.generation > r.generation) - return 1; - return 0; -} - -int cmp_bitwise(const ghobject_t& l, const ghobject_t& r) +int cmp(const ghobject_t& l, const ghobject_t& r) { if (l.max < r.max) return -1; @@ -636,7 +583,7 @@ int cmp_bitwise(const ghobject_t& l, const ghobject_t& r) return -1; if (l.shard_id > r.shard_id) return 1; - int ret = cmp_bitwise(l.hobj, r.hobj); + int ret = cmp(l.hobj, r.hobj); if (ret != 0) return ret; if (l.generation < r.generation) diff --git a/src/common/hobject.h b/src/common/hobject.h index 14a9ffc7c95d..3b7f3b8ef02e 100644 --- a/src/common/hobject.h +++ b/src/common/hobject.h @@ -289,21 +289,32 @@ public: void decode(json_spirit::Value& v); void dump(Formatter *f) const; static void generate_test_instances(list& o); - friend int cmp_nibblewise(const hobject_t& l, const hobject_t& r); - friend int cmp_bitwise(const hobject_t& l, const hobject_t& r); + friend int cmp(const hobject_t& l, const hobject_t& r); + friend bool operator>(const hobject_t& l, const hobject_t& r) { + return cmp(l, r) > 0; + } + friend bool operator>=(const hobject_t& l, const hobject_t& r) { + return cmp(l, r) >= 0; + } + friend bool operator<(const hobject_t& l, const hobject_t& r) { + return cmp(l, r) < 0; + } + friend bool operator<=(const hobject_t& l, const hobject_t& r) { + return cmp(l, r) <= 0; + } friend bool operator==(const hobject_t&, const hobject_t&); friend bool operator!=(const hobject_t&, const hobject_t&); friend struct ghobject_t; struct NibblewiseComparator { bool operator()(const hobject_t& l, const hobject_t& r) const { - return cmp_nibblewise(l, r) < 0; + return cmp(l, r) < 0; } }; struct BitwiseComparator { bool operator()(const hobject_t& l, const hobject_t& r) const { - return cmp_bitwise(l, r) < 0; + return cmp(l, r) < 0; } }; @@ -311,20 +322,14 @@ public: bool bitwise; explicit Comparator(bool b) : bitwise(b) {} bool operator()(const hobject_t& l, const hobject_t& r) const { - if (bitwise) - return cmp_bitwise(l, r) < 0; - else - return cmp_nibblewise(l, r) < 0; + return cmp(l, r) < 0; } }; struct ComparatorWithDefault { bool bitwise; explicit ComparatorWithDefault(bool b=true) : bitwise(b) {} bool operator()(const hobject_t& l, const hobject_t& r) const { - if (bitwise) - return cmp_bitwise(l, r) < 0; - else - return cmp_nibblewise(l, r) < 0; + return cmp(l, r) < 0; } }; template @@ -373,62 +378,20 @@ inline bool operator!=(const T&, const hobject_t &rhs) { return !rhs.is_max(); } -extern int cmp_nibblewise(const hobject_t& l, const hobject_t& r); -extern int cmp_bitwise(const hobject_t& l, const hobject_t& r); -static inline int cmp(const hobject_t& l, const hobject_t& r, bool sort_bitwise) { - if (sort_bitwise) - return cmp_bitwise(l, r); - else - return cmp_nibblewise(l, r); -} +extern int cmp(const hobject_t& l, const hobject_t& r); template -static inline int cmp(const hobject_t &l, const T&, bool sort_bitwise) { +static inline int cmp(const hobject_t &l, const T&) { static_assert(always_false::value::value, "Do not compare to get_max()"); return l.is_max() ? 0 : -1; } template -static inline int cmp(const T&, const hobject_t&r, bool sort_bitwise) { - static_assert(always_false::value::value, "Do not compare to get_max()"); - return r.is_max() ? 0 : 1; -} -template -static inline int cmp_nibblewise(const hobject_t &l, const T&, bool sort_bitwise) { - static_assert(always_false::value::value, "Do not compare to get_max()"); - return l.is_max() ? 0 : -1; -} -template -static inline int cmp_nibblewise(const T&, const hobject_t&r, bool sort_bitwise) { - static_assert(always_false::value::value, "Do not compare to get_max()"); - return r.is_max() ? 0 : 1; -} -template -static inline int cmp_bitwise(const hobject_t &l, const T&, bool sort_bitwise) { - static_assert(always_false::value::value, "Do not compare to get_max()"); - return l.is_max() ? 0 : -1; -} -template -static inline int cmp_bitwise(const T&, const hobject_t&r, bool sort_bitwise) { +static inline int cmp(const T&, const hobject_t&r) { static_assert(always_false::value::value, "Do not compare to get_max()"); return r.is_max() ? 0 : 1; } -// these are convenient -static inline hobject_t MAX_HOBJ(const hobject_t& l, const hobject_t& r, bool bitwise) { - if (cmp(l, r, bitwise) >= 0) - return l; - else - return r; -} - -static inline hobject_t MIN_HOBJ(const hobject_t& l, const hobject_t& r, bool bitwise) { - if (cmp(l, r, bitwise) <= 0) - return l; - else - return r; -} - typedef version_t gen_t; struct ghobject_t { @@ -530,20 +493,31 @@ public: size_t encoded_size() const; void dump(Formatter *f) const; static void generate_test_instances(list& o); - friend int cmp_nibblewise(const ghobject_t& l, const ghobject_t& r); - friend int cmp_bitwise(const ghobject_t& l, const ghobject_t& r); + friend int cmp(const ghobject_t& l, const ghobject_t& r); + friend bool operator>(const ghobject_t& l, const ghobject_t& r) { + return cmp(l, r) > 0; + } + friend bool operator>=(const ghobject_t& l, const ghobject_t& r) { + return cmp(l, r) >= 0; + } + friend bool operator<(const ghobject_t& l, const ghobject_t& r) { + return cmp(l, r) < 0; + } + friend bool operator<=(const ghobject_t& l, const ghobject_t& r) { + return cmp(l, r) <= 0; + } friend bool operator==(const ghobject_t&, const ghobject_t&); friend bool operator!=(const ghobject_t&, const ghobject_t&); struct NibblewiseComparator { bool operator()(const ghobject_t& l, const ghobject_t& r) const { - return cmp_nibblewise(l, r) < 0; + return cmp(l, r) < 0; } }; struct BitwiseComparator { bool operator()(const ghobject_t& l, const ghobject_t& r) const { - return cmp_bitwise(l, r) < 0; + return cmp(l, r) < 0; } }; @@ -551,10 +525,7 @@ public: bool bitwise; explicit Comparator(bool b) : bitwise(b) {} bool operator()(const ghobject_t& l, const ghobject_t& r) const { - if (bitwise) - return cmp_bitwise(l, r) < 0; - else - return cmp_nibblewise(l, r) < 0; + return cmp(l, r) < 0; } }; }; @@ -573,31 +544,7 @@ ostream& operator<<(ostream& out, const ghobject_t& o); WRITE_EQ_OPERATORS_4(ghobject_t, max, shard_id, hobj, generation) -extern int cmp_nibblewise(const ghobject_t& l, const ghobject_t& r); -extern int cmp_bitwise(const ghobject_t& l, const ghobject_t& r); -static inline int cmp(const ghobject_t& l, const ghobject_t& r, - bool sort_bitwise) { - if (sort_bitwise) - return cmp_bitwise(l, r); - else - return cmp_nibblewise(l, r); -} - -// these are convenient -static inline ghobject_t MAX_GHOBJ(const ghobject_t& l, const ghobject_t& r, - bool bitwise) { - if (cmp(l, r, bitwise) >= 0) - return l; - else - return r; -} +extern int cmp(const ghobject_t& l, const ghobject_t& r); -static inline ghobject_t MIN_GHOBJ(const ghobject_t& l, const ghobject_t& r, - bool bitwise) { - if (cmp(l, r, bitwise) <= 0) - return l; - else - return r; -} #endif diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 7b9816b4efa4..335fa4cd1b4a 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -4205,7 +4205,7 @@ extern "C" int rados_object_list_cursor_cmp( { hobject_t *lhs = (hobject_t*)lhs_cur; hobject_t *rhs = (hobject_t*)rhs_cur; - return cmp_bitwise(*lhs, *rhs); + return cmp(*lhs, *rhs); } extern "C" int rados_object_list(rados_ioctx_t io, @@ -6073,7 +6073,7 @@ bool librados::ObjectCursor::operator<(const librados::ObjectCursor &rhs) { const hobject_t lhs_hobj = (c_cursor == nullptr) ? hobject_t() : *((hobject_t*)c_cursor); const hobject_t rhs_hobj = (rhs.c_cursor == nullptr) ? hobject_t() : *((hobject_t*)(rhs.c_cursor)); - return cmp_bitwise(lhs_hobj, rhs_hobj) == -1; + return lhs_hobj < rhs_hobj; } librados::ObjectCursor::ObjectCursor(const librados::ObjectCursor &rhs) diff --git a/src/os/filestore/DBObjectMap.cc b/src/os/filestore/DBObjectMap.cc index c17395c5a25a..73c113dc5de6 100644 --- a/src/os/filestore/DBObjectMap.cc +++ b/src/os/filestore/DBObjectMap.cc @@ -889,10 +889,10 @@ int DBObjectMap::clone(const ghobject_t &oid, if (oid == target) return 0; - MapHeaderLock _l1(this, MIN_GHOBJ(oid, target, true)); - MapHeaderLock _l2(this, MAX_GHOBJ(oid, target, true)); + MapHeaderLock _l1(this, std::min(oid, target)); + MapHeaderLock _l2(this, std::max(oid, target)); MapHeaderLock *lsource, *ltarget; - if (cmp_bitwise(oid, target) > 0) { + if (oid > target) { lsource = &_l2; ltarget= &_l1; } else { diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index 6c1c4c67419e..5e079f502deb 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -4801,7 +4801,7 @@ int FileStore::collection_list(const coll_t& c, sep.hobj.pool = -1; sep.set_shard(shard); if (!c.is_temp() && !c.is_meta()) { - if (cmp_bitwise(start, sep) < 0) { // bitwise vs nibble doesn't matter here + if (start < sep) { dout(10) << __func__ << " first checking temp pool" << dendl; coll_t temp = c.get_temp(); int r = collection_list(temp, start, end, max, ls, next); diff --git a/src/os/filestore/HashIndex.cc b/src/os/filestore/HashIndex.cc index 6bbb6330333e..5026ed393444 100644 --- a/src/os/filestore/HashIndex.cc +++ b/src/os/filestore/HashIndex.cc @@ -903,7 +903,7 @@ int HashIndex::get_path_contents_by_hash_bitwise( for (map::iterator i = rev_objects.begin(); i != rev_objects.end(); ++i) { - if (next_object && cmp_bitwise(i->second, *next_object) < 0) + if (next_object && i->second < *next_object) continue; string hash_prefix = get_path_str(i->second); hash_prefixes->insert(hash_prefix); @@ -1004,12 +1004,12 @@ int HashIndex::list_by_hash_bitwise( *next = j->second; return 0; } - if (cmp_bitwise(j->second, end) >= 0) { + if (j->second >= end) { if (next) *next = j->second; return 0; } - if (!next || cmp_bitwise(j->second, *next) >= 0) { + if (!next || j->second >= *next) { dout(20) << __func__ << " prefix " << *i << " ob " << j->second << dendl; out->push_back(j->second); } diff --git a/src/os/filestore/HashIndex.h b/src/os/filestore/HashIndex.h index add3c3559fcf..4ffde1d34ae9 100644 --- a/src/os/filestore/HashIndex.h +++ b/src/os/filestore/HashIndex.h @@ -359,20 +359,6 @@ private: return str; } - struct CmpPairNibblewise { - bool operator()(const pair& l, - const pair& r) - { - if (l.first < r.first) - return true; - if (l.first > r.first) - return false; - if (cmp_nibblewise(l.second, r.second) < 0) - return true; - return false; - } - }; - struct CmpPairBitwise { bool operator()(const pair& l, const pair& r) @@ -381,7 +367,7 @@ private: return true; if (l.first > r.first) return false; - if (cmp_bitwise(l.second, r.second) < 0) + if (cmp(l.second, r.second) < 0) return true; return false; } diff --git a/src/os/memstore/MemStore.cc b/src/os/memstore/MemStore.cc index 73ed1f720edd..d27557b87276 100644 --- a/src/os/memstore/MemStore.cc +++ b/src/os/memstore/MemStore.cc @@ -476,7 +476,7 @@ int MemStore::collection_list(const coll_t& cid, map::iterator p = c->object_map.lower_bound(start); while (p != c->object_map.end() && ls->size() < (unsigned)max && - cmp_bitwise(p->first, end) < 0) { + p->first < end) { ls->push_back(p->first); ++p; } diff --git a/src/osd/ECBackend.cc b/src/osd/ECBackend.cc index ddf238c83e02..faecd1c3aa6f 100644 --- a/src/osd/ECBackend.cc +++ b/src/osd/ECBackend.cc @@ -1475,7 +1475,7 @@ int ECBackend::get_min_avail_to_read_shards( assert(!shards.count(i->shard)); const pg_info_t &info = get_parent()->get_shard_info(*i); const pg_missing_t &missing = get_parent()->get_shard_missing(*i); - if (cmp(hoid, info.last_backfill, get_parent()->sort_bitwise()) < 0 && + if (hoid < info.last_backfill && !missing.is_missing(hoid)) { have.insert(i->shard); shards.insert(make_pair(i->shard, *i)); diff --git a/src/osd/ExtentCache.h b/src/osd/ExtentCache.h index 07a7feab5688..4354ba6c7e69 100644 --- a/src/osd/ExtentCache.h +++ b/src/osd/ExtentCache.h @@ -182,7 +182,7 @@ private: set extent_set; bool operator<(const object_extent_set &rhs) const { - return cmp_bitwise(oid, rhs.oid) < 0; + return oid < rhs.oid; } struct uint_cmp { @@ -330,10 +330,10 @@ private: }; struct Cmp { bool operator()(const hobject_t &oid, const object_extent_set &rhs) const { - return cmp_bitwise(oid, rhs.oid) < 0; + return oid < rhs.oid; } bool operator()(const object_extent_set &lhs, const hobject_t &oid) const { - return cmp_bitwise(lhs.oid, oid) < 0; + return lhs.oid < oid; } }; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 26df67911b8f..5ac536a7e4dd 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -8903,7 +8903,7 @@ void OSD::handle_backoff(OpRequestRef& op, OSDMapRef& osdmap) // advance pos = _pgid.get_hobj_end(osdmap->get_pg_pool(pos.pool)->get_pg_num()); dout(20) << __func__ << " next pg " << pos << dendl; - } while (cmp_bitwise(pos, m->end) < 0); + } while (pos < m->end); } template diff --git a/src/osd/PG.cc b/src/osd/PG.cc index e0000c30abd1..0b1b62528a97 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -567,7 +567,7 @@ bool PG::MissingLoc::add_source_info( << dendl; continue; } - if (cmp(p->first, oinfo.last_backfill, sort_bitwise) >= 0) { + if (p->first >= oinfo.last_backfill) { // FIXME: this is _probably_ true, although it could conceivably // be in the undefined region! Hmm! ldout(pg->cct, 10) << "search_for_missing " << soid << " " << need @@ -1742,7 +1742,7 @@ void PG::activate(ObjectStore::Transaction& t, for (list::iterator p = m->log.log.begin(); p != m->log.log.end(); ++p) - if (cmp(p->soid, pi.last_backfill, get_sort_bitwise()) <= 0) + if (p->soid <= pi.last_backfill) pm.add_next_event(*p); } @@ -2366,11 +2366,11 @@ void PG::release_backoffs(const hobject_t& begin, const hobject_t& end) Mutex::Locker l(backoff_lock); auto p = backoffs.lower_bound(begin); while (p != backoffs.end()) { - int r = cmp_bitwise(p->first, end); + int r = cmp(p->first, end); dout(20) << __func__ << " ? " << r << " " << p->first << " " << p->second << dendl; // note: must still examine begin=end=p->first case - if (r > 0 || (r == 0 && cmp_bitwise(begin, end) < 0)) { + if (r > 0 || (r == 0 && begin < end)) { break; } dout(20) << __func__ << " checking " << p->first @@ -2378,9 +2378,8 @@ void PG::release_backoffs(const hobject_t& begin, const hobject_t& end) auto q = p->second.begin(); while (q != p->second.end()) { dout(20) << __func__ << " checking " << *q << dendl; - int r = cmp_bitwise((*q)->begin, begin); - if (r == 0 || (r > 0 && - cmp_bitwise((*q)->end, end) < 0)) { + int r = cmp((*q)->begin, begin); + if (r == 0 || (r > 0 && (*q)->end < end)) { bv.push_back(*q); q = p->second.erase(q); } else { @@ -3264,7 +3263,7 @@ void PG::append_log( * here past last_backfill. It's ok for the same reason as * above */ if (transaction_applied && - (cmp(p->soid, info.last_backfill, get_sort_bitwise()) > 0)) { + p->soid > info.last_backfill) { pg_log.roll_forward(&handler); } } @@ -4431,8 +4430,8 @@ void PG::chunky_scrub(ThreadPool::TPHandle &handle) for (auto p = projected_log.log.rbegin(); p != projected_log.log.rend(); ++p) { - if (cmp(p->soid, scrubber.start, get_sort_bitwise()) >= 0 && - cmp(p->soid, scrubber.end, get_sort_bitwise()) < 0) { + if (p->soid >= scrubber.start && + p->soid < scrubber.end) { scrubber.subset_last_update = p->version; break; } @@ -4442,8 +4441,8 @@ void PG::chunky_scrub(ThreadPool::TPHandle &handle) pg_log.get_log().log.rbegin(); p != pg_log.get_log().log.rend(); ++p) { - if (cmp(p->soid, scrubber.start, get_sort_bitwise()) >= 0 && - cmp(p->soid, scrubber.end, get_sort_bitwise()) < 0) { + if (p->soid >= scrubber.start && + p->soid < scrubber.end) { scrubber.subset_last_update = p->version; break; } diff --git a/src/osd/PG.h b/src/osd/PG.h index 07a674df79b4..0daf3b8b74d1 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -488,7 +488,7 @@ public: auto pinfoiter = pinfo.find(i.first); assert(pinfoiter != pinfo.end()); if (item->need <= pinfoiter->second.last_update && - cmp(hoid, pinfoiter->second.last_backfill, sort_bitwise) <= 0 && + hoid <= pinfoiter->second.last_backfill && !i.second.is_missing(hoid)) mliter->second.insert(i.first); } @@ -768,7 +768,7 @@ public: void trim_to(const hobject_t &soid) { trim(); while (!objects.empty() && - cmp(objects.begin()->first, soid, sort_bitwise) <= 0) { + objects.begin()->first <= soid) { pop_front(); } } @@ -1209,8 +1209,8 @@ public: // classic (non chunk) scrubs block all writes // chunky scrubs only block writes to a range bool write_blocked_by_scrub(const hobject_t &soid, bool sort_bitwise) { - if (cmp(soid, start, sort_bitwise) >= 0 && - cmp(soid, end, sort_bitwise) < 0) + if (soid >= start && + soid < end) return true; return false; diff --git a/src/osd/PGLog.h b/src/osd/PGLog.h index 713d3d8ce356..022f0c156c23 100644 --- a/src/osd/PGLog.h +++ b/src/osd/PGLog.h @@ -753,7 +753,7 @@ protected: ldpp_dout(dpp, 20) << __func__ << ": merging hoid " << hoid << " entries: " << entries << dendl; - if (cmp(hoid, info.last_backfill, info.last_backfill_bitwise) > 0) { + if (hoid > info.last_backfill) { ldpp_dout(dpp, 10) << __func__ << ": hoid " << hoid << " after last_backfill" << dendl; return; @@ -1002,7 +1002,7 @@ public: ldpp_dout(dpp, 20) << "update missing, append " << *p << dendl; log->add(*p); } - if (cmp(p->soid, last_backfill, last_backfill_bitwise) <= 0 && + if (p->soid <= last_backfill && !p->is_error()) { missing.add_next_event(*p); if (rollbacker) { @@ -1192,7 +1192,7 @@ public: i != log.log.rend(); ++i) { if (!debug_verify_stored_missing && i->version <= info.last_complete) break; - if (cmp(i->soid, info.last_backfill, info.last_backfill_bitwise) > 0) + if (i->soid > info.last_backfill) continue; if (i->is_error()) continue; @@ -1240,7 +1240,7 @@ public: if (checked.count(i.first)) continue; if (i.second.need > log.tail || - cmp(i.first, info.last_backfill, info.last_backfill_bitwise) > 0) { + i.first > info.last_backfill) { lderr(dpp->get_cct()) << __func__ << ": invalid missing set entry found " << i.first << dendl; @@ -1266,7 +1266,7 @@ public: i != divergent_priors.rend(); ++i) { if (i->first <= info.last_complete) break; - if (cmp(i->second, info.last_backfill, info.last_backfill_bitwise) > 0) + if (i->second > info.last_backfill) continue; if (did.count(i->second)) continue; did.insert(i->second); diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index 35a8c1997424..2bc34cf9bc3e 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -593,8 +593,8 @@ bool PrimaryLogPG::is_degraded_or_backfilling_object(const hobject_t& soid) // Object is degraded if after last_backfill AND // we are backfilling it if (is_backfill_targets(peer) && - cmp(peer_info[peer].last_backfill, soid, get_sort_bitwise()) <= 0 && - cmp(last_backfill_started, soid, get_sort_bitwise()) >= 0 && + peer_info[peer].last_backfill <= soid && + last_backfill_started >= soid && backfills_in_flight.count(soid)) return true; } @@ -1109,10 +1109,8 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op) dout(10) << " pgnls lower_bound " << lower_bound << " pg_end " << pg_end << dendl; if (get_sort_bitwise() && - ((!lower_bound.is_max() && - cmp_bitwise(lower_bound, pg_end) >= 0) || - (lower_bound != hobject_t() && - cmp_bitwise(lower_bound, pg_start) < 0))) { + ((!lower_bound.is_max() && lower_bound >= pg_end) || + (lower_bound != hobject_t() && lower_bound < pg_start))) { // this should only happen with a buggy client. dout(10) << "outside of PG bounds " << pg_start << " .. " << pg_end << dendl; @@ -1159,7 +1157,7 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op) ++ls_iter; ++missing_iter; } - } else if (cmp(mcand, lcand, get_sort_bitwise()) < 0) { + } else if (mcand < lcand) { candidate = mcand; assert(!mcand.is_max()); ++missing_iter; @@ -1172,7 +1170,7 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op) dout(10) << " pgnls candidate 0x" << std::hex << candidate.get_hash() << " vs lower bound 0x" << lower_bound.get_hash() << dendl; - if (cmp(candidate, next, get_sort_bitwise()) >= 0) { + if (candidate >= next) { break; } @@ -1346,7 +1344,7 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op) ++ls_iter; ++missing_iter; } - } else if (cmp(mcand, lcand, get_sort_bitwise()) < 0) { + } else if (mcand < lcand) { candidate = mcand; assert(!mcand.is_max()); ++missing_iter; @@ -1356,7 +1354,7 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op) ++ls_iter; } - if (cmp(candidate, next, get_sort_bitwise()) >= 0) { + if (candidate >= next) { break; } @@ -1609,10 +1607,10 @@ void PrimaryLogPG::handle_backoff(OpRequestRef& op) session->put(); // get_priv takes a ref, and so does the SessionRef hobject_t begin = info.pgid.pgid.get_hobj_start(); hobject_t end = info.pgid.pgid.get_hobj_end(pool.info.get_pg_num()); - if (cmp_bitwise(begin, m->begin) < 0) { + if (begin < m->begin) { begin = m->begin; } - if (cmp_bitwise(end, m->end) > 0) { + if (end > m->end) { end = m->end; } dout(10) << __func__ << " backoff ack id " << m->id @@ -1763,7 +1761,7 @@ hobject_t PrimaryLogPG::earliest_backfill() const pg_shard_t bt = *i; map::const_iterator iter = peer_info.find(bt); assert(iter != peer_info.end()); - if (cmp(iter->second.last_backfill, e, get_sort_bitwise()) < 0) + if (iter->second.last_backfill < e) e = iter->second.last_backfill; } return e; @@ -6896,14 +6894,14 @@ void PrimaryLogPG::apply_stats( ++i) { pg_shard_t bt = *i; pg_info_t& pinfo = peer_info[bt]; - if (cmp(soid, pinfo.last_backfill, get_sort_bitwise()) <= 0) + if (soid <= pinfo.last_backfill) pinfo.stats.stats.add(delta_stats); - else if (cmp(soid, last_backfill_started, get_sort_bitwise()) <= 0) + else if (soid <= last_backfill_started) pending_backfill_updates[soid].stats.add(delta_stats); } if (is_primary() && scrubber.active) { - if (cmp(soid, scrubber.start, get_sort_bitwise()) < 0) { + if (soid < scrubber.start) { scrub_cstat.add(delta_stats); } } @@ -10770,7 +10768,7 @@ uint64_t PrimaryLogPG::recover_replicas(uint64_t max, ThreadPool::TPHandle &hand handle.reset_tp_timeout(); const hobject_t soid(p->second); - if (cmp(soid, pi->second.last_backfill, get_sort_bitwise()) > 0) { + if (soid > pi->second.last_backfill) { if (!recovering.count(soid)) { derr << __func__ << ": object added to missing set for backfill, but " << "is not in recovering, error!" << dendl; @@ -10827,7 +10825,7 @@ hobject_t PrimaryLogPG::earliest_peer_backfill() const map::const_iterator iter = peer_backfill_info.find(peer); assert(iter != peer_backfill_info.end()); - if (cmp(iter->second.begin, e, get_sort_bitwise()) < 0) + if (iter->second.begin < e) e = iter->second.begin; } return e; @@ -10953,14 +10951,12 @@ uint64_t PrimaryLogPG::recover_backfill( i != backfill_targets.end(); ++i) { peer_backfill_info[*i].trim_to( - MAX_HOBJ(peer_info[*i].last_backfill, last_backfill_started, - get_sort_bitwise())); + std::max(peer_info[*i].last_backfill, last_backfill_started)); } backfill_info.trim_to(last_backfill_started); while (ops < max) { - if (cmp(backfill_info.begin, earliest_peer_backfill(), - get_sort_bitwise()) <= 0 && + if (backfill_info.begin <= earliest_peer_backfill() && !backfill_info.extends_to_end() && backfill_info.empty()) { hobject_t next = backfill_info.end; backfill_info.reset(next, get_sort_bitwise()); @@ -10979,7 +10975,7 @@ uint64_t PrimaryLogPG::recover_backfill( BackfillInterval& pbi = peer_backfill_info[bt]; dout(20) << " peer shard " << bt << " backfill " << pbi << dendl; - if (cmp(pbi.begin, backfill_info.begin, get_sort_bitwise()) <= 0 && + if (pbi.begin <= backfill_info.begin && !pbi.extends_to_end() && pbi.empty()) { dout(10) << " scanning peer osd." << bt << " from " << pbi.end << dendl; epoch_t e = get_osdmap()->get_epoch(); @@ -11010,7 +11006,7 @@ uint64_t PrimaryLogPG::recover_backfill( // the set of targets for which that object applies. hobject_t check = earliest_peer_backfill(); - if (cmp(check, backfill_info.begin, get_sort_bitwise()) < 0) { + if (check < backfill_info.begin) { set check_targets; for (set::iterator i = backfill_targets.begin(); @@ -11107,8 +11103,7 @@ uint64_t PrimaryLogPG::recover_backfill( // Only include peers that we've caught up to their backfill line // otherwise, they only appear to be missing this object // because their pbi.begin > backfill_info.begin. - if (cmp(backfill_info.begin, pinfo.last_backfill, - get_sort_bitwise()) > 0) + if (backfill_info.begin > pinfo.last_backfill) missing_targs.push_back(bt); else skip_targs.push_back(bt); @@ -11172,8 +11167,8 @@ uint64_t PrimaryLogPG::recover_backfill( } } - hobject_t backfill_pos = MIN_HOBJ(backfill_info.begin, earliest_peer_backfill(), - get_sort_bitwise()); + hobject_t backfill_pos = + std::min(backfill_info.begin, earliest_peer_backfill()); for (set::iterator i = add_to_stat.begin(); i != add_to_stat.end(); @@ -11190,8 +11185,7 @@ uint64_t PrimaryLogPG::recover_backfill( // ordered before any subsequent updates send_remove_op(to_remove[i].get<0>(), to_remove[i].get<1>(), to_remove[i].get<2>()); - if (cmp(to_remove[i].get<0>(), last_backfill_started, - get_sort_bitwise()) <= 0) + if (to_remove[i].get<0>() <= last_backfill_started) pending_backfill_updates[to_remove[i].get<0>()]; // add empty stat! } @@ -11217,17 +11211,17 @@ uint64_t PrimaryLogPG::recover_backfill( for (map::iterator i = pending_backfill_updates.begin(); i != pending_backfill_updates.end() && - cmp(i->first, next_backfill_to_complete, get_sort_bitwise()) < 0; + i->first < next_backfill_to_complete; pending_backfill_updates.erase(i++)) { dout(20) << " pending_backfill_update " << i->first << dendl; - assert(cmp(i->first, new_last_backfill, get_sort_bitwise()) > 0); + assert(i->first > new_last_backfill); for (set::iterator j = backfill_targets.begin(); j != backfill_targets.end(); ++j) { pg_shard_t bt = *j; pg_info_t& pinfo = peer_info[bt]; //Add stats to all peers that were missing object - if (cmp(i->first, pinfo.last_backfill, get_sort_bitwise()) > 0) + if (i->first > pinfo.last_backfill) pinfo.stats.add(i->second); } new_last_backfill = i->first; @@ -11253,7 +11247,7 @@ uint64_t PrimaryLogPG::recover_backfill( pg_shard_t bt = *i; pg_info_t& pinfo = peer_info[bt]; - if (cmp(new_last_backfill, pinfo.last_backfill, get_sort_bitwise()) > 0) { + if (new_last_backfill > pinfo.last_backfill) { pinfo.set_last_backfill(new_last_backfill, get_sort_bitwise()); epoch_t e = get_osdmap()->get_epoch(); MOSDPGBackfill *m = NULL; @@ -11365,8 +11359,8 @@ void PrimaryLogPG::update_range( dout(10) << __func__ << ": updating from version " << e.version << dendl; const hobject_t &soid = e.soid; - if (cmp(soid, bi->begin, get_sort_bitwise()) >= 0 && - cmp(soid, bi->end, get_sort_bitwise()) < 0) { + if (soid >= bi->begin && + soid < bi->end) { if (e.is_update()) { dout(10) << __func__ << ": " << e.soid << " updated to version " << e.version << dendl; @@ -12010,8 +12004,8 @@ bool PrimaryLogPG::agent_work(int start_max, int agent_flush_quota) // See if we've made a full pass over the object hash space // This might check at most ls_max objects a second time to notice that // we've checked every objects at least once. - if (cmp(agent_state->position, agent_state->start, get_sort_bitwise()) < 0 && - cmp(next, agent_state->start, get_sort_bitwise()) >= 0) { + if (agent_state->position < agent_state->start && + next >= agent_state->start) { dout(20) << __func__ << " wrap around " << agent_state->start << dendl; if (total_started == 0) need_delay = true; @@ -12603,7 +12597,7 @@ bool PrimaryLogPG::_range_available_for_scrub( next.second = object_contexts.lookup(begin); next.first = begin; bool more = true; - while (more && cmp(next.first, end, get_sort_bitwise()) < 0) { + while (more && next.first < end) { if (next.second && next.second->is_blocked()) { next.second->requeue_scrub_on_unblock = true; dout(10) << __func__ << ": scrub delayed, " diff --git a/src/osd/PrimaryLogPG.h b/src/osd/PrimaryLogPG.h index a0b0ec3d0135..6863a556df81 100644 --- a/src/osd/PrimaryLogPG.h +++ b/src/osd/PrimaryLogPG.h @@ -395,8 +395,8 @@ public: assert(peer_info.count(peer)); bool should_send = hoid.pool != (int64_t)info.pgid.pool() || - cmp(hoid, last_backfill_started, get_sort_bitwise()) <= 0 || - cmp(hoid, peer_info[peer].last_backfill, get_sort_bitwise()) <= 0; + hoid <= last_backfill_started || + hoid <= peer_info[peer].last_backfill; if (!should_send) assert(is_backfill_targets(peer)); return should_send; diff --git a/src/osd/ReplicatedBackend.cc b/src/osd/ReplicatedBackend.cc index 51b50e10b664..976aa7f91178 100644 --- a/src/osd/ReplicatedBackend.cc +++ b/src/osd/ReplicatedBackend.cc @@ -1292,7 +1292,7 @@ void ReplicatedBackend::calc_head_subsets( c.snap = snapset.clones[j]; prev.intersection_of(snapset.clone_overlap[snapset.clones[j]]); if (!missing.is_missing(c) && - cmp(c, last_backfill, get_parent()->sort_bitwise()) < 0 && + c < last_backfill && get_parent()->try_lock_for_read(c, manager)) { dout(10) << "calc_head_subsets " << head << " has prev " << c << " overlap " << prev << dendl; @@ -1360,7 +1360,7 @@ void ReplicatedBackend::calc_clone_subsets( c.snap = snapset.clones[j]; prev.intersection_of(snapset.clone_overlap[snapset.clones[j]]); if (!missing.is_missing(c) && - cmp(c, last_backfill, get_parent()->sort_bitwise()) < 0 && + c < last_backfill && get_parent()->try_lock_for_read(c, manager)) { dout(10) << "calc_clone_subsets " << soid << " has prev " << c << " overlap " << prev << dendl; @@ -1381,7 +1381,7 @@ void ReplicatedBackend::calc_clone_subsets( c.snap = snapset.clones[j]; next.intersection_of(snapset.clone_overlap[snapset.clones[j-1]]); if (!missing.is_missing(c) && - cmp(c, last_backfill, get_parent()->sort_bitwise()) < 0 && + c < last_backfill && get_parent()->try_lock_for_read(c, manager)) { dout(10) << "calc_clone_subsets " << soid << " has next " << c << " overlap " << next << dendl; diff --git a/src/osd/Session.cc b/src/osd/Session.cc index 8f93ea95ae96..39591fa89700 100644 --- a/src/osd/Session.cc +++ b/src/osd/Session.cc @@ -47,8 +47,8 @@ void Session::ack_backoff( auto p = backoffs.lower_bound(begin); while (p != backoffs.end()) { // note: must still examine begin=end=p->first case - int r = cmp_bitwise(p->first, end); - if (r > 0 || (r == 0 && cmp_bitwise(begin, end) < 0)) { + int r = cmp(p->first, end); + if (r > 0 || (r == 0 && begin < end)) { break; } auto q = p->second.begin(); diff --git a/src/osd/Session.h b/src/osd/Session.h index 63a73c30073e..c6c80011599c 100644 --- a/src/osd/Session.h +++ b/src/osd/Session.h @@ -169,14 +169,14 @@ struct Session : public RefCountedObject { assert(backoff_count == (int)backoffs.size()); auto p = backoffs.lower_bound(oid); if (p != backoffs.begin() && - cmp_bitwise(p->first, oid) > 0) { + p->first > oid) { --p; } if (p != backoffs.end()) { - int r = cmp_bitwise(oid, p->first); + int r = cmp(oid, p->first); if (r == 0 || r > 0) { for (auto& q : p->second) { - if (r == 0 || cmp_bitwise(oid, q->end) < 0) { + if (r == 0 || oid < q->end) { return &(*q); } } diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index f592811b6fcc..c38a363c35e2 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -3075,15 +3075,15 @@ void Objecter::_send_op(Op *op, MOSDOp *m) auto q = op->session->backoffs.lower_bound(hoid); if (q != op->session->backoffs.begin()) { --q; - if (cmp_bitwise(hoid, q->second.end) >= 0) { + if (hoid >= q->second.end) { ++q; } } if (q != op->session->backoffs.end()) { ldout(cct, 20) << __func__ << " ? " << q->first << " [" << q->second.begin << "," << q->second.end << ")" << dendl; - int r = cmp_bitwise(hoid, q->second.begin); - if (r == 0 || (r > 0 && cmp_bitwise(hoid, q->second.end) < 0)) { + int r = cmp(hoid, q->second.begin); + if (r == 0 || (r > 0 && hoid < q->second.end)) { ldout(cct, 10) << __func__ << " backoff on " << hoid << ", queuing " << op << " tid " << op->tid << dendl; return; @@ -5012,7 +5012,7 @@ void Objecter::enumerate_objects( { assert(result); - if (!end.is_max() && cmp_bitwise(start, end) > 0) { + if (!end.is_max() && start > end) { lderr(cct) << __func__ << ": start " << start << " > end " << end << dendl; on_finish->complete(-EINVAL); return; @@ -5103,7 +5103,7 @@ void Objecter::_enumerate_reply( ldout(cct, 20) << __func__ << ": response.entries.size " << response.entries.size() << ", response.entries " << response.entries << dendl; - if (cmp_bitwise(response.handle, end) <= 0) { + if (response.handle <= end) { *next = response.handle; } else { ldout(cct, 10) << __func__ << ": adjusted next down to end " << end @@ -5131,7 +5131,7 @@ void Objecter::_enumerate_reply( hash, pool_id, response.entries.back().nspace); - if (cmp_bitwise(last, end) < 0) + if (last < end) break; ldout(cct, 20) << __func__ << " dropping item " << last << " >= end " << end << dendl; diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index 8682a61d7ad4..95d665a7a2d3 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -1236,8 +1236,8 @@ public: bool contained_by(const hobject_t& begin, const hobject_t& end) { hobject_t h = get_hobj(); - int r = cmp_bitwise(h, begin); - return r == 0 || (r > 0 && cmp_bitwise(h, end) < 0); + int r = cmp(h, begin); + return r == 0 || (r > 0 && h < end); } void dump(Formatter *f) const; diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index 4035b6d411c2..dbfd4f98830b 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -91,7 +91,7 @@ bool sorted(const vector &in) { for (vector::const_iterator i = in.begin(); i != in.end(); ++i) { - if (cmp(start, *i, true) > 0) { + if (start > *i) { cout << start << " should follow " << *i << std::endl; return false; } @@ -2329,24 +2329,24 @@ TEST_P(StoreTest, Sort) { ASSERT_EQ(a, b); b.oid.name = "b"; ASSERT_NE(a, b); - ASSERT_TRUE(cmp_bitwise(a, b) < 0); + ASSERT_TRUE(a < b); a.pool = 1; b.pool = 2; - ASSERT_TRUE(cmp_bitwise(a, b) < 0); + ASSERT_TRUE(a < b); a.pool = 3; - ASSERT_TRUE(cmp_bitwise(a, b) > 0); + ASSERT_TRUE(a > b); } { ghobject_t a(hobject_t(sobject_t("a", CEPH_NOSNAP))); ghobject_t b(hobject_t(sobject_t("b", CEPH_NOSNAP))); a.hobj.pool = 1; b.hobj.pool = 1; - ASSERT_TRUE(cmp_bitwise(a, b) < 0); + ASSERT_TRUE(a < b); a.hobj.pool = -3; - ASSERT_TRUE(cmp_bitwise(a, b) < 0); + ASSERT_TRUE(a < b); a.hobj.pool = 1; b.hobj.pool = -3; - ASSERT_TRUE(cmp_bitwise(a, b) > 0); + ASSERT_TRUE(a > b); } } diff --git a/src/test/osd/TestPGLog.cc b/src/test/osd/TestPGLog.cc index e00449ca860e..f1b12629c615 100644 --- a/src/test/osd/TestPGLog.cc +++ b/src/test/osd/TestPGLog.cc @@ -490,8 +490,9 @@ TEST_F(PGLogTest, merge_old_entry) { list remove_snap; info.last_backfill = hobject_t(); - info.last_backfill.set_hash(1); + info.last_backfill.set_hash(100); oe.soid.set_hash(2); + ASSERT_GT(oe.soid, info.last_backfill); EXPECT_FALSE(is_dirty()); EXPECT_TRUE(remove_snap.empty()); diff --git a/src/test/osd/types.cc b/src/test/osd/types.cc index 419c637177bc..d1d600789d88 100644 --- a/src/test/osd/types.cc +++ b/src/test/osd/types.cc @@ -1442,14 +1442,14 @@ TEST(ghobject_t, cmp) { sep.set_shard(shard_id_t(1)); sep.hobj.pool = -1; cout << min << " < " << sep << std::endl; - ASSERT_TRUE(cmp_bitwise(min, sep) < 0); + ASSERT_TRUE(min < sep); sep.set_shard(shard_id_t::NO_SHARD); cout << "sep shard " << sep.shard_id << std::endl; ghobject_t o(hobject_t(object_t(), string(), CEPH_NOSNAP, 0x42, 1, string())); cout << "o " << o << std::endl; - ASSERT_TRUE(cmp_bitwise(o, sep) > 0); + ASSERT_TRUE(o > sep); } TEST(ghobject_t, parse) {