Skip to content

Commit 4e1a500

Browse files
committed
os/memstore: bring support for omap_iterate
Signed-off-by: Radoslaw Zarzynski <[email protected]>
1 parent 3c2b4bb commit 4e1a500

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/os/memstore/MemStore.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,48 @@ ObjectMap::ObjectMapIterator MemStore::get_omap_iterator(
619619
return ObjectMap::ObjectMapIterator(new OmapIteratorImpl(c, o));
620620
}
621621

622+
int MemStore::omap_iterate(
623+
CollectionHandle &ch, ///< [in] collection
624+
const ghobject_t &oid, ///< [in] object
625+
ObjectStore::omap_iter_seek_t start_from, ///< [in] where the iterator should point to at the beginning
626+
std::function<omap_iter_ret_t(std::string_view, std::string_view)> f)
627+
{
628+
Collection *c = static_cast<Collection*>(ch.get());
629+
ObjectRef o = c->get_object(oid);
630+
if (!o) {
631+
return -ENOENT;
632+
}
633+
634+
{
635+
std::lock_guard lock{o->omap_mutex};
636+
637+
// obtain seek the iterator
638+
decltype(o->omap)::iterator it;
639+
{
640+
if (start_from.seek_type == omap_iter_seek_t::LOWER_BOUND) {
641+
it = o->omap.lower_bound(start_from.seek_position);
642+
} else {
643+
it = o->omap.upper_bound(start_from.seek_position);
644+
}
645+
}
646+
647+
// iterate!
648+
while (it != o->omap.end()) {
649+
// potentially rectifying memcpy but who cares for memstore?
650+
omap_iter_ret_t ret =
651+
f(it->first, std::string_view{it->second.c_str(), it->second.length()});
652+
if (ret == omap_iter_ret_t::STOP) {
653+
break;
654+
} else if (ret == omap_iter_ret_t::NEXT) {
655+
++it;
656+
} else {
657+
ceph_abort();
658+
}
659+
}
660+
}
661+
return 0;
662+
}
663+
622664

623665
// ---------------
624666
// write operations

src/os/memstore/MemStore.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ class MemStore : public ObjectStore {
379379
const ghobject_t &oid ///< [in] object
380380
) override;
381381

382+
int omap_iterate(
383+
CollectionHandle &c, ///< [in] collection
384+
const ghobject_t &oid, ///< [in] object
385+
omap_iter_seek_t start_from, ///< [in] where the iterator should point to at the beginning
386+
std::function<omap_iter_ret_t(std::string_view, std::string_view)> f
387+
) override;
388+
382389
void set_fsid(uuid_d u) override;
383390
uuid_d get_fsid() override;
384391

0 commit comments

Comments
 (0)