]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore: fix onode cache addition race
authorSage Weil <sage@redhat.com>
Mon, 3 Oct 2016 21:36:50 +0000 (17:36 -0400)
committerSage Weil <sage@redhat.com>
Mon, 3 Oct 2016 21:37:15 +0000 (17:37 -0400)
Two threads may try to add the same onode to the cache.
This is rare, but allowed (in the case of the meta
collection).  If that happens, one of them will just
back off and use the winning onode ref.

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

index 92ce9f5d905b89189397e4b39edb4b8a818d33af..5fa3e178a00f8f4a878b64d24510c6495d56316e 100644 (file)
@@ -1076,13 +1076,19 @@ void BlueStore::BufferSpace::finish_write(uint64_t seq)
 #undef dout_prefix
 #define dout_prefix *_dout << "bluestore.OnodeSpace(" << this << " in " << cache << ") "
 
-void BlueStore::OnodeSpace::add(const ghobject_t& oid, OnodeRef o)
+BlueStore::OnodeRef BlueStore::OnodeSpace::add(const ghobject_t& oid, OnodeRef o)
 {
   std::lock_guard<std::recursive_mutex> l(cache->lock);
+  auto p = onode_map.find(oid);
+  if (p != onode_map.end()) {
+    dout(30) << __func__ << " " << oid << " " << o
+            << " raced, returning existing " << p->second << dendl;
+    return p->second;
+  }
   dout(30) << __func__ << " " << oid << " " << o << dendl;
-  assert(onode_map.count(oid) == 0);
   onode_map[oid] = o;
   cache->_add_onode(o, 1);
+  return o;
 }
 
 BlueStore::OnodeRef BlueStore::OnodeSpace::lookup(const ghobject_t& oid)
@@ -2181,8 +2187,7 @@ BlueStore::OnodeRef BlueStore::Collection::get_onode(
     }
   }
   o.reset(on);
-  onode_map.add(oid, o);
-  return o;
+  return onode_map.add(oid, o);
 }
 
 
index 9831a0b728f891eb2490d30ebad282cf4e4cd7b6..cc2709c2fc9da1b86aa465c1750220d15d31fb68 100644 (file)
@@ -874,7 +874,7 @@ public:
       clear();
     }
 
-    void add(const ghobject_t& oid, OnodeRef o);
+    OnodeRef add(const ghobject_t& oid, OnodeRef o);
     OnodeRef lookup(const ghobject_t& o);
     void rename(OnodeRef& o, const ghobject_t& old_oid,
                const ghobject_t& new_oid,