Skip to content

Commit 87d6447

Browse files
committed
os/bluestore: implement the lightweight OMAP iteration
Signed-off-by: Radoslaw Zarzynski <[email protected]>
1 parent f348ea3 commit 87d6447

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/os/bluestore/BlueStore.cc

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13734,6 +13734,76 @@ ObjectMap::ObjectMapIterator BlueStore::get_omap_iterator(
1373413734
return ObjectMap::ObjectMapIterator(new OmapIteratorImpl(logger,c, o, it));
1373513735
}
1373613736

13737+
int BlueStore::omap_iterate(
13738+
CollectionHandle &c_, ///< [in] collection
13739+
const ghobject_t &oid, ///< [in] object
13740+
ObjectStore::omap_iter_seek_t start_from, ///< [in] where the iterator should point to at the beginning
13741+
std::function<omap_iter_ret_t(std::string_view, std::string_view)> f
13742+
)
13743+
{
13744+
Collection *c = static_cast<Collection *>(c_.get());
13745+
dout(10) << __func__ << " " << c->get_cid() << " " << oid << dendl;
13746+
if (!c->exists) {
13747+
return -ENOENT;
13748+
}
13749+
std::shared_lock l(c->lock);
13750+
OnodeRef o = c->get_onode(oid, false);
13751+
if (!o || !o->exists) {
13752+
dout(10) << __func__ << " " << oid << "doesn't exist" <<dendl;
13753+
return -ENOENT;
13754+
}
13755+
o->flush();
13756+
dout(10) << __func__ << " has_omap = " << (int)o->onode.has_omap() <<dendl;
13757+
if (!o->onode.has_omap()) {
13758+
// nothing to do
13759+
return 0;
13760+
}
13761+
13762+
KeyValueDB::Iterator it;
13763+
{
13764+
auto bounds = KeyValueDB::IteratorBounds();
13765+
std::string lower_bound, upper_bound;
13766+
o->get_omap_key(string(), &lower_bound);
13767+
o->get_omap_tail(&upper_bound);
13768+
bounds.lower_bound = std::move(lower_bound);
13769+
bounds.upper_bound = std::move(upper_bound);
13770+
it = db->get_iterator(o->get_omap_prefix(), 0, std::move(bounds));
13771+
}
13772+
13773+
// seek the iterator
13774+
{
13775+
std::string key;
13776+
o->get_omap_key(start_from.seek_position, &key);
13777+
if (start_from.seek_type == omap_iter_seek_t::LOWER_BOUND) {
13778+
it->lower_bound(key);
13779+
} else {
13780+
it->upper_bound(key);
13781+
}
13782+
}
13783+
13784+
// iterate!
13785+
std::string tail;
13786+
o->get_omap_tail(&tail);
13787+
while (it->valid()) {
13788+
std::string user_key;
13789+
if (const auto& db_key = it->raw_key().second; db_key >= tail) {
13790+
break;
13791+
} else {
13792+
o->decode_omap_key(db_key, &user_key);
13793+
}
13794+
omap_iter_ret_t ret = f(user_key, it->value_as_sv());
13795+
if (ret == omap_iter_ret_t::STOP) {
13796+
break;
13797+
} else if (ret == omap_iter_ret_t::NEXT) {
13798+
it->next();
13799+
} else {
13800+
ceph_abort();
13801+
}
13802+
}
13803+
13804+
return 0;
13805+
}
13806+
1373713807
// -----------------
1373813808
// write helpers
1373913809

src/os/bluestore/BlueStore.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,6 +3423,13 @@ class BlueStore : public ObjectStore,
34233423
const ghobject_t &oid ///< [in] object
34243424
) override;
34253425

3426+
int omap_iterate(
3427+
CollectionHandle &c, ///< [in] collection
3428+
const ghobject_t &oid, ///< [in] object
3429+
omap_iter_seek_t start_from, ///< [in] where the iterator should point to at the beginning
3430+
std::function<omap_iter_ret_t(std::string_view, std::string_view)> f
3431+
) override;
3432+
34263433
void set_fsid(uuid_d u) override {
34273434
fsid = u;
34283435
}

0 commit comments

Comments
 (0)