From 6fe1cf4151a80fb722717a3e319d485ba4a5af39 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Thu, 30 Jul 2020 08:39:45 +0100 Subject: [PATCH] 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.cc: (std::shared_lock vs RWLock) src/os/bluestore/BlueStore.h: trivial (std::vector vs vector) --- src/os/ObjectStore.h | 7 ++ src/os/bluestore/BlueStore.cc | 123 ++++++++++++++++++++++++++++++---- src/os/bluestore/BlueStore.h | 9 ++- 3 files changed, 126 insertions(+), 13 deletions(-) diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 0349412eac6e9..1c12068954edc 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -1827,6 +1827,13 @@ public: int max, vector *ls, ghobject_t *next) = 0; + 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 f57b9ff05bf5f..557e7fea4af55 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -706,26 +706,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; + } - bool valid() const { + 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 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); @@ -751,7 +824,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) { @@ -759,7 +832,7 @@ public: } } - void next() { + void next() override { ceph_assert(valid()); m_chunk_iter++; @@ -769,7 +842,6 @@ public: } private: - KeyValueDB::Iterator m_it; std::map m_chunk; std::map::iterator m_chunk_iter; @@ -9889,7 +9961,28 @@ 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()); + c->flush(); + 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 @@ -9901,7 +9994,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) @@ -9931,7 +10024,13 @@ int BlueStore::_collection_list( << " and " << pretty_binary_string(start_key) << " to " << pretty_binary_string(end_key) << " start " << start << dendl; - it = std::make_unique(db->get_iterator(PREFIX_OBJ)); + if (legacy) { + it = std::make_unique( + db->get_iterator(PREFIX_OBJ)); + } else { + it = std::make_unique( + db->get_iterator(PREFIX_OBJ)); + } if (start == ghobject_t() || start.hobj == hobject_t() || start == c->cid.get_min_hobj()) { @@ -14179,7 +14278,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 (next != ghobject_t::get_max()) 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) { // If true mean collecton has more objects than nonexistent_count, // so bypass check. diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 3e0aaa2606168..f623a08cd83c9 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2379,7 +2379,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) { @@ -2600,6 +2600,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( CollectionHandle &c, ///< [in] Collection containing oid const ghobject_t &oid, ///< [in] Object containing omap -- 2.39.5