]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: narrow cache lock range for OnodeSpace::lookup
authorxie xingguo <xie.xingguo@zte.com.cn>
Mon, 26 Jun 2017 07:05:10 +0000 (15:05 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Tue, 27 Jun 2017 10:47:34 +0000 (18:47 +0800)
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/os/bluestore/BlueStore.cc

index d1417544a25ae4f0570db5f94cedadc24d3c8044..2e3da75fc1440f418de1f082d6cf0b9142f69221 100644 (file)
@@ -1494,19 +1494,30 @@ BlueStore::OnodeRef BlueStore::OnodeSpace::add(const ghobject_t& oid, OnodeRef o
 
 BlueStore::OnodeRef BlueStore::OnodeSpace::lookup(const ghobject_t& oid)
 {
-  std::lock_guard<std::recursive_mutex> l(cache->lock);
   ldout(cache->cct, 30) << __func__ << dendl;
-  ceph::unordered_map<ghobject_t,OnodeRef>::iterator p = onode_map.find(oid);
-  if (p == onode_map.end()) {
-    ldout(cache->cct, 30) << __func__ << " " << oid << " miss" << dendl;
+  OnodeRef o;
+  bool hit = false;
+
+  {
+    std::lock_guard<std::recursive_mutex> l(cache->lock);
+    ceph::unordered_map<ghobject_t,OnodeRef>::iterator p = onode_map.find(oid);
+    if (p == onode_map.end()) {
+      ldout(cache->cct, 30) << __func__ << " " << oid << " miss" << dendl;
+    } else {
+      ldout(cache->cct, 30) << __func__ << " " << oid << " hit " << p->second
+                           << dendl;
+      cache->_touch_onode(p->second);
+      hit = true;
+      o = p->second;
+    }
+  }
+
+  if (hit) {
+    cache->logger->inc(l_bluestore_onode_hits);
+  } else {
     cache->logger->inc(l_bluestore_onode_misses);
-    return OnodeRef();
   }
-  ldout(cache->cct, 30) << __func__ << " " << oid << " hit " << p->second
-                       << dendl;
-  cache->_touch_onode(p->second);
-  cache->logger->inc(l_bluestore_onode_hits);
-  return p->second;
+  return o;
 }
 
 void BlueStore::OnodeSpace::clear()