From: Mykola Golub Date: Thu, 30 Jul 2020 07:39:45 +0000 (+0100) Subject: os: add collection_list_legacy X-Git-Tag: v12.2.14~2^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5b7b5358f961a1bbb309707947bf21c08a05a526;p=ceph.git os: add collection_list_legacy which provides the old collection_list behaviour on the bluestore. Signed-off-by: Mykola Golub (cherry picked from commit fb3c7d062e305d577286e9788e5d7536ad44364d) Conflicts: src/os/bluestore/BlueStore.h: trivial (std::vector vs vector) src/os/bluestore/BlueStore.cc: RWLock instead of std::shared_lock, c++11 compatibility --- diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 12879511047..8014411db35 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -1925,6 +1925,13 @@ public: return collection_list(c->get_cid(), start, end, max, ls, next); } + virtual int collection_list_legacy(CollectionHandle &c, + const ghobject_t& start, + const ghobject_t& end, int max, + std::vector *ls, + ghobject_t *next) { + return collection_list(c, start, end, max, ls, next); + } /// OMAP /// Get omap contents diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 5b0be127375..dc9af555256 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -680,26 +680,99 @@ namespace { class CollectionListIterator { public: CollectionListIterator(const KeyValueDB::Iterator &it) - : m_it(it), m_chunk_iter(m_chunk.end()) { + : m_it(it) { + } + virtual ~CollectionListIterator() { + } + + virtual bool valid() const = 0; + virtual const ghobject_t &oid() const = 0; + virtual const std::string &key() const = 0; + virtual void lower_bound(const std::string &key) = 0; + virtual void upper_bound(const std::string &key) = 0; + virtual void next() = 0; + +protected: + KeyValueDB::Iterator m_it; +}; + +class SimpleCollectionListIterator : public CollectionListIterator { +public: + SimpleCollectionListIterator(const KeyValueDB::Iterator &it) + : CollectionListIterator(it) { + } + + bool valid() const override { + return m_it->valid(); + } + + const ghobject_t &oid() const override { + ceph_assert(valid()); + + return m_oid; + } + + virtual const std::string &key() const override { + ceph_assert(valid()); + + return m_key; + } + + void lower_bound(const std::string &key) override { + m_it->lower_bound(key); + cache_key(); + } + + void upper_bound(const std::string &key) override { + m_it->upper_bound(key); + cache_key(); + } + + void next() override { + ceph_assert(valid()); + + m_it->next(); + cache_key(); + } + +private: + std::string m_key; + ghobject_t m_oid; + + void cache_key() { + if (!valid()) { + return; + } + + m_key = m_it->key(); + int r = get_key_object(m_key, &m_oid); + ceph_assert(r != -1); + } +}; + +class SortedCollectionListIterator : public CollectionListIterator { +public: + SortedCollectionListIterator(const KeyValueDB::Iterator &it) + : CollectionListIterator(it), m_chunk_iter(m_chunk.end()) { } - bool valid() const { + bool valid() const override { return m_chunk_iter != m_chunk.end(); } - const ghobject_t &oid() const { + const ghobject_t &oid() const override { ceph_assert(valid()); return m_chunk_iter->first; } - const std::string &key() const { + const std::string &key() const override { ceph_assert(valid()); return m_chunk_iter->second; } - void lower_bound(const std::string &key) { + void lower_bound(const std::string &key) override { ghobject_t oid; int r = get_key_object(key, &oid); ceph_assert(r != -1); @@ -725,7 +798,7 @@ public: } } - void upper_bound(const std::string &key) { + void upper_bound(const std::string &key) override { lower_bound(key); if (valid() && this->key() == key) { @@ -733,7 +806,7 @@ public: } } - void next() { + void next() override { ceph_assert(valid()); m_chunk_iter++; @@ -743,7 +816,6 @@ public: } private: - KeyValueDB::Iterator m_it; std::map m_chunk; std::map::iterator m_chunk_iter; @@ -7817,7 +7889,27 @@ int BlueStore::collection_list( int r; { RWLock::RLocker l(c->lock); - r = _collection_list(c, start, end, max, ls, pnext); + r = _collection_list(c, start, end, max, false, ls, pnext); + } + + dout(10) << __func__ << " " << c->cid + << " start " << start << " end " << end << " max " << max + << " = " << r << ", ls.size() = " << ls->size() + << ", next = " << (pnext ? *pnext : ghobject_t()) << dendl; + return r; +} + +int BlueStore::collection_list_legacy( + CollectionHandle &c_, const ghobject_t& start, const ghobject_t& end, int max, + vector *ls, ghobject_t *pnext) +{ + Collection *c = static_cast(c_.get()); + dout(15) << __func__ << " " << c->cid + << " start " << start << " end " << end << " max " << max << dendl; + int r; + { + RWLock::RLocker l(c->lock); + r = _collection_list(c, start, end, max, true, ls, pnext); } dout(10) << __func__ << " " << c->cid @@ -7829,7 +7921,7 @@ int BlueStore::collection_list( int BlueStore::_collection_list( Collection *c, const ghobject_t& start, const ghobject_t& end, int max, - vector *ls, ghobject_t *pnext) + bool legacy, vector *ls, ghobject_t *pnext) { if (!c->exists) @@ -7859,7 +7951,13 @@ int BlueStore::_collection_list( << " and " << pretty_binary_string(start_key) << " to " << pretty_binary_string(end_key) << " start " << start << dendl; - it.reset(new CollectionListIterator(db->get_iterator(PREFIX_OBJ))); + if (legacy) { + it.reset(new SimpleCollectionListIterator( + cct, db->get_iterator(PREFIX_OBJ))); + } else { + it.reset(new SortedCollectionListIterator( + db->get_iterator(PREFIX_OBJ))); + } if (start == ghobject_t() || start.hobj == hobject_t() || start == c->cid.get_min_hobj()) { @@ -12088,7 +12186,7 @@ int BlueStore::_remove_collection(TransContext *txc, const coll_t &cid, // then check if all of them are marked as non-existent. // Bypass the check if returned number is greater than nonexistent_count r = _collection_list(c->get(), ghobject_t(), ghobject_t::get_max(), - nonexistent_count + 1, &ls, &next); + nonexistent_count + 1, false, &ls, &next); if (r >= 0) { bool exists = false; //ls.size() > nonexistent_count; for (auto it = ls.begin(); !exists && it < ls.end(); ++it) { diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 6bcbed7b91e..0d031ab1b01 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2236,7 +2236,7 @@ private: int _collection_list( Collection *c, const ghobject_t& start, const ghobject_t& end, - int max, vector *ls, ghobject_t *next); + int max, bool legacy, vector *ls, ghobject_t *next); template T select_option(const std::string& opt_name, T val1, F f) { @@ -2446,6 +2446,13 @@ public: int max, vector *ls, ghobject_t *next) override; + int collection_list_legacy(CollectionHandle &c, + const ghobject_t& start, + const ghobject_t& end, + int max, + vector *ls, + ghobject_t *next) override; + int omap_get( const coll_t& cid, ///< [in] Collection containing oid const ghobject_t &oid, ///< [in] Object containing omap