]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/memstore: bring support for omap_iterate
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 26 Nov 2024 18:28:28 +0000 (18:28 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 14 Jan 2025 13:01:06 +0000 (13:01 +0000)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
(cherry picked from commit 4e1a500f9c6cc58a516e88ee0d01cc8b7bb65e7a)

src/os/memstore/MemStore.cc
src/os/memstore/MemStore.h

index a06b2f2d5894b4f3f54270f902c7960661b9b6b2..f9d3bf0d8a28723e57251839b41d7e031d48504e 100644 (file)
@@ -619,6 +619,48 @@ ObjectMap::ObjectMapIterator MemStore::get_omap_iterator(
   return ObjectMap::ObjectMapIterator(new OmapIteratorImpl(c, o));
 }
 
+int MemStore::omap_iterate(
+  CollectionHandle &ch,   ///< [in] collection
+  const ghobject_t &oid, ///< [in] object
+  ObjectStore::omap_iter_seek_t start_from, ///< [in] where the iterator should point to at the beginning
+  std::function<omap_iter_ret_t(std::string_view, std::string_view)> f)
+{
+  Collection *c = static_cast<Collection*>(ch.get());
+  ObjectRef o = c->get_object(oid);
+  if (!o) {
+    return -ENOENT;
+  }
+
+  {
+    std::lock_guard lock{o->omap_mutex};
+
+    // obtain seek the iterator
+    decltype(o->omap)::iterator it;
+    {
+      if (start_from.seek_type == omap_iter_seek_t::LOWER_BOUND) {
+        it = o->omap.lower_bound(start_from.seek_position);
+      } else {
+        it = o->omap.upper_bound(start_from.seek_position);
+      }
+    }
+
+    // iterate!
+    while (it != o->omap.end()) {
+      // potentially rectifying memcpy but who cares for memstore?
+      omap_iter_ret_t ret =
+        f(it->first, std::string_view{it->second.c_str(), it->second.length()});
+      if (ret == omap_iter_ret_t::STOP) {
+        break;
+      } else if (ret == omap_iter_ret_t::NEXT) {
+        ++it;
+      } else {
+        ceph_abort();
+      }
+    }
+  }
+  return 0;
+}
+
 
 // ---------------
 // write operations
index 61668ff17b1ff56ad9fa566ac9cb6902ee834ed0..9621773598f99ceef83786e5c8b1d6ccc1b90c94 100644 (file)
@@ -379,6 +379,13 @@ public:
     const ghobject_t &oid  ///< [in] object
     ) override;
 
+  int omap_iterate(
+    CollectionHandle &c,   ///< [in] collection
+    const ghobject_t &oid, ///< [in] object
+    omap_iter_seek_t start_from, ///< [in] where the iterator should point to at the beginning
+    std::function<omap_iter_ret_t(std::string_view, std::string_view)> f
+  ) override;
+
   void set_fsid(uuid_d u) override;
   uuid_d get_fsid() override;