]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os: add collection_list_legacy
authorMykola Golub <mgolub@suse.com>
Thu, 30 Jul 2020 07:39:45 +0000 (08:39 +0100)
committerMykola Golub <mgolub@suse.com>
Wed, 9 Sep 2020 09:13:51 +0000 (12:13 +0300)
which provides the old collection_list behaviour on the bluestore.

Signed-off-by: Mykola Golub <mgolub@suse.com>
(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

src/os/ObjectStore.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 12879511047dd737536c45e705fd3126dfdfc916..8014411db3598d8bb4f4b01fbe2696bf88a6e3e3 100644 (file)
@@ -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<ghobject_t> *ls,
+                                     ghobject_t *next) {
+    return collection_list(c, start, end, max, ls, next);
+  }
 
   /// OMAP
   /// Get omap contents
index 5b0be127375706039fbd1fc891c12c7473001047..dc9af555256b3c74c4987a4be522a44ee5ddbae6 100644 (file)
@@ -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<ghobject_t, std::string> m_chunk;
   std::map<ghobject_t, std::string>::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<ghobject_t> *ls, ghobject_t *pnext)
+{
+  Collection *c = static_cast<Collection *>(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<ghobject_t> *ls, ghobject_t *pnext)
+  bool legacy, vector<ghobject_t> *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) {
index 6bcbed7b91e3ac120a5dd7dcd1929dd0467ca8ba..0d031ab1b0186aa1b21ba340c6702393b16c3f94 100644 (file)
@@ -2236,7 +2236,7 @@ private:
 
   int _collection_list(
     Collection *c, const ghobject_t& start, const ghobject_t& end,
-    int max, vector<ghobject_t> *ls, ghobject_t *next);
+    int max, bool legacy, vector<ghobject_t> *ls, ghobject_t *next);
 
   template <typename T, typename F>
   T select_option(const std::string& opt_name, T val1, F f) {
@@ -2446,6 +2446,13 @@ public:
                      int max,
                      vector<ghobject_t> *ls, ghobject_t *next) override;
 
+  int collection_list_legacy(CollectionHandle &c,
+                             const ghobject_t& start,
+                             const ghobject_t& end,
+                             int max,
+                             vector<ghobject_t> *ls,
+                             ghobject_t *next) override;
+
   int omap_get(
     const coll_t& cid,                ///< [in] Collection containing oid
     const ghobject_t &oid,   ///< [in] Object containing omap