From 11559dd7cd237f1c9d94ae2b3a04583c0964698d Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Tue, 26 Nov 2024 18:28:28 +0000 Subject: [PATCH] os/memstore: bring support for omap_iterate Signed-off-by: Radoslaw Zarzynski (cherry picked from commit 4e1a500f9c6cc58a516e88ee0d01cc8b7bb65e7a) --- src/os/memstore/MemStore.cc | 42 +++++++++++++++++++++++++++++++++++++ src/os/memstore/MemStore.h | 7 +++++++ 2 files changed, 49 insertions(+) diff --git a/src/os/memstore/MemStore.cc b/src/os/memstore/MemStore.cc index a06b2f2d5894b..f9d3bf0d8a287 100644 --- a/src/os/memstore/MemStore.cc +++ b/src/os/memstore/MemStore.cc @@ -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 f) +{ + Collection *c = static_cast(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 diff --git a/src/os/memstore/MemStore.h b/src/os/memstore/MemStore.h index 61668ff17b1ff..9621773598f99 100644 --- a/src/os/memstore/MemStore.h +++ b/src/os/memstore/MemStore.h @@ -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 f + ) override; + void set_fsid(uuid_d u) override; uuid_d get_fsid() override; -- 2.39.5