]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: replace broken get_next with map_any
authorSage Weil <sage@redhat.com>
Fri, 3 Jun 2016 20:41:37 +0000 (16:41 -0400)
committerSage Weil <sage@redhat.com>
Fri, 3 Jun 2016 20:41:37 +0000 (16:41 -0400)
The get_next implementation assumed the lru was local to the OnodeSpace,
but it includes the whole cache now.

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 54f63c24970db8a8530d8301de16f04203e712e7..6c8b13ba7388c5bb985568dc14798ff0df695f32 100644 (file)
@@ -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<ghobject_t,OnodeRef> *next)
+bool BlueStore::OnodeSpace::map_any(std::function<bool(OnodeRef)> f)
 {
   std::lock_guard<std::mutex> 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<ghobject_t,OnodeRef>::iterator p = onode_map.begin();
-    assert(p != onode_map.end());
-    next->first = p->first;
-    next->second = p->second;
-    return true;
-  }
-
-  ceph::unordered_map<ghobject_t,OnodeRef>::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<ghobject_t,OnodeRef> 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<ghobject_t,OnodeRef> 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);
index 52626d52671f918c9957ec4159a28a5069dc5ebc..4fa1f48e41a0c27de4adecc22d1e619c971b0df9 100644 (file)
@@ -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<ghobject_t,OnodeRef> *next);
+
+    /// return true if f true for any item
+    bool map_any(std::function<bool(OnodeRef)> f);
   };
 
   struct Cache;