From 2150e9914bd28376c8dc3a114ce3daeff81d89f4 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Oct 2016 17:36:50 -0400 Subject: [PATCH] os/bluestore: fix onode cache addition race 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 --- src/os/bluestore/BlueStore.cc | 13 +++++++++---- src/os/bluestore/BlueStore.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 92ce9f5d905b..5fa3e178a00f 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -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 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); } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 9831a0b728f8..cc2709c2fc9d 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -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, -- 2.47.3