From fd28656aa657093e661711ac5c5eb2177fe0695f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 3 Jun 2016 16:41:37 -0400 Subject: [PATCH] os/bluestore: replace broken get_next with map_any The get_next implementation assumed the lru was local to the OnodeSpace, but it includes the whole cache now. Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 68 ++++++++++++++--------------------- src/os/bluestore/BlueStore.h | 4 ++- 2 files changed, 29 insertions(+), 43 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 54f63c24970db..6c8b13ba7388c 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -765,34 +765,16 @@ void BlueStore::OnodeSpace::rename(OnodeRef& oldo, get_object_key(new_oid, &o->key); } -bool BlueStore::OnodeSpace::get_next( - const ghobject_t& after, - pair *next) +bool BlueStore::OnodeSpace::map_any(std::function f) { std::lock_guard l(cache->lock); - dout(20) << __func__ << " after " << after << dendl; - - if (after == ghobject_t()) { - if (cache->onode_lru.empty()) { - return false; + dout(20) << __func__ << dendl; + for (auto& i : onode_map) { + if (f(i.second)) { + return true; } - ceph::unordered_map::iterator p = onode_map.begin(); - assert(p != onode_map.end()); - next->first = p->first; - next->second = p->second; - return true; - } - - ceph::unordered_map::iterator p = onode_map.find(after); - assert(p != onode_map.end()); // for now - auto pi = cache->onode_lru.iterator_to(*p->second); - ++pi; - if (pi == cache->onode_lru.end()) { - return false; } - next->first = pi->oid; - next->second = onode_map[pi->oid]; - return true; + return false; } @@ -2917,16 +2899,16 @@ void BlueStore::_reap_collections() ++p) { CollectionRef c = *p; dout(10) << __func__ << " " << c->cid << dendl; - { - pair next; - while (c->onode_map.get_next(next.first, &next)) { - assert(!next.second->exists); - if (!next.second->flush_txns.empty()) { - dout(10) << __func__ << " " << c->cid << " " << next.second->oid - << " flush_txns " << next.second->flush_txns << dendl; - return; - } - } + if (c->onode_map.map_any([&](OnodeRef o) { + assert(!o->exists); + if (!o->flush_txns.empty()) { + dout(10) << __func__ << " " << c->cid << " " << o->oid + << " flush_txns " << o->flush_txns << dendl; + return false; + } + return true; + })) { + return; } c->onode_map.clear(); dout(10) << __func__ << " " << c->cid << " done" << dendl; @@ -6614,14 +6596,16 @@ int BlueStore::_remove_collection(TransContext *txc, coll_t cid, goto out; } assert((*c)->exists); - pair next; - while ((*c)->onode_map.get_next(next.first, &next)) { - if (next.second->exists) { - dout(10) << __func__ << " " << next.first << " " << next.second - << " exists in onode_map" << dendl; - r = -ENOTEMPTY; - goto out; - } + if ((*c)->onode_map.map_any([&](OnodeRef o) { + if (o->exists) { + dout(10) << __func__ << " " << o->oid << " " << o + << " exists in onode_map" << dendl; + return true; + } + return false; + })) { + r = -ENOTEMPTY; + goto out; } coll_map.erase(cid); txc->removed_collections.push_back(*c); diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 52626d52671f9..4fa1f48e41a0c 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -449,7 +449,9 @@ public: OnodeRef lookup(const ghobject_t& o); void rename(OnodeRef& o, const ghobject_t& old_oid, const ghobject_t& new_oid); void clear(); - bool get_next(const ghobject_t& after, pair *next); + + /// return true if f true for any item + bool map_any(std::function f); }; struct Cache; -- 2.39.5