From 272d10784cf9771a2e0f85182bd43b76d5126a0f Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Mon, 9 Nov 2020 20:19:48 +0000 Subject: [PATCH] os/bluestore: fix "end reached" check in collection_list_legacy To preserve the old bluestore behavior it should compare the current object with the end using bluestore keys, not oids. Fixes: https://tracker.ceph.com/issues/48153 Signed-off-by: Mykola Golub (cherry picked from commit e63489f249f9ba3bc9cb1806568f860effd8a0b6) --- src/os/bluestore/BlueStore.cc | 37 ++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 71e996b1b8ee3..9f9e9748d8018 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -718,6 +718,16 @@ public: virtual void upper_bound(const ghobject_t &oid) = 0; virtual void next() = 0; + virtual int cmp(const ghobject_t &oid) const = 0; + + bool is_ge(const ghobject_t &oid) const { + return cmp(oid) >= 0; + } + + bool is_lt(const ghobject_t &oid) const { + return cmp(oid) < 0; + } + protected: KeyValueDB::Iterator m_it; }; @@ -761,6 +771,15 @@ public: get_oid(); } + int cmp(const ghobject_t &oid) const override { + ceph_assert(valid()); + + string key; + get_object_key(m_cct, oid, &key); + + return m_it->key().compare(key); + } + private: CephContext *m_cct; ghobject_t m_oid; @@ -836,6 +855,18 @@ public: } } + int cmp(const ghobject_t &oid) const override { + ceph_assert(valid()); + + if (this->oid() < oid) { + return -1; + } + if (this->oid() > oid) { + return 1; + } + return 0; + } + private: std::map m_chunk; std::map::iterator m_chunk_iter; @@ -10063,14 +10094,14 @@ int BlueStore::_collection_list( } dout(20) << __func__ << " pend " << pend << dendl; while (true) { - if (!it->valid() || it->oid() >= pend) { + if (!it->valid() || it->is_ge(pend)) { if (!it->valid()) dout(20) << __func__ << " iterator not valid (end of db?)" << dendl; else dout(20) << __func__ << " oid " << it->oid() << " >= " << pend << dendl; if (temp) { if (end.hobj.is_temp()) { - if (it->valid() && it->oid() < coll_range_temp_end) { + if (it->valid() && it->is_lt(coll_range_temp_end)) { *pnext = it->oid(); set_next = true; } @@ -10086,7 +10117,7 @@ int BlueStore::_collection_list( dout(30) << __func__ << " pend " << pend << dendl; continue; } - if (it->valid() && it->oid() < coll_range_end) { + if (it->valid() && it->is_lt(coll_range_end)) { *pnext = it->oid(); set_next = true; } -- 2.39.5