]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd/OSD: refactor update_osd_stat() to narrow lock
authorxie xingguo <xie.xingguo@zte.com.cn>
Mon, 3 Jul 2017 03:31:37 +0000 (11:31 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Tue, 4 Jul 2017 10:22:09 +0000 (18:22 +0800)
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/osd/OSD.cc
src/osd/OSD.h

index 3f0249c7ab25353162df41e58857612df18c8127..93ddebf5a4e9a79e4992e8e9f23bf7e957363284 100644 (file)
@@ -919,15 +919,31 @@ void OSDService::set_injectfull(s_names type, int64_t count)
   injectfull = count;
 }
 
-void OSDService::update_osd_stat(vector<int>& hb_peers)
+osd_stat_t OSDService::set_osd_stat(const struct store_statfs_t &stbuf,
+                                    vector<int>& hb_peers)
 {
-  Mutex::Locker lock(stat_lock);
+  uint64_t bytes = stbuf.total;
+  uint64_t used = bytes - stbuf.available;
+  uint64_t avail = stbuf.available;
 
-  osd_stat.hb_peers.swap(hb_peers);
+  osd->logger->set(l_osd_stat_bytes, bytes);
+  osd->logger->set(l_osd_stat_bytes_used, used);
+  osd->logger->set(l_osd_stat_bytes_avail, avail);
 
-  osd->op_tracker.get_age_ms_histogram(&osd_stat.op_queue_age_hist);
+  {
+    Mutex::Locker l(stat_lock);
+    osd_stat.hb_peers.swap(hb_peers);
+    osd->op_tracker.get_age_ms_histogram(&osd_stat.op_queue_age_hist);
+    osd_stat.kb = bytes >> 10;
+    osd_stat.kb_used = used >> 10;
+    osd_stat.kb_avail = avail >> 10;
+    return osd_stat;
+  }
+}
 
-  // fill in osd stats too
+void OSDService::update_osd_stat(vector<int>& hb_peers)
+{
+  // load osd stats first
   struct store_statfs_t stbuf;
   int r = osd->store->statfs(&stbuf);
   if (r < 0) {
@@ -935,21 +951,10 @@ void OSDService::update_osd_stat(vector<int>& hb_peers)
     return;
   }
 
-  uint64_t bytes = stbuf.total;
-  uint64_t used = bytes - stbuf.available;
-  uint64_t avail = stbuf.available;
-
-  osd_stat.kb = bytes >> 10;
-  osd_stat.kb_used = used >> 10;
-  osd_stat.kb_avail = avail >> 10;
-
-  osd->logger->set(l_osd_stat_bytes, bytes);
-  osd->logger->set(l_osd_stat_bytes_used, used);
-  osd->logger->set(l_osd_stat_bytes_avail, avail);
-
-  dout(20) << "update_osd_stat " << osd_stat << dendl;
-
-  float ratio = ((float)osd_stat.kb_used) / ((float)osd_stat.kb);
+  auto new_stat = set_osd_stat(stbuf, hb_peers);
+  dout(20) << "update_osd_stat " << new_stat << dendl;
+  assert(new_stat.kb);
+  float ratio = ((float)new_stat.kb_used) / ((float)new_stat.kb);
   check_full_status(ratio);
 }
 
index 37835a6778f13f77e5c4853782a578931aa5d00b..2598ea3c2ef0d7da88a74ff3709a0194058cd16a 100644 (file)
@@ -1044,6 +1044,8 @@ public:
   uint32_t seq = 0;
 
   void update_osd_stat(vector<int>& hb_peers);
+  osd_stat_t set_osd_stat(const struct store_statfs_t &stbuf,
+                          vector<int>& hb_peers);
   osd_stat_t get_osd_stat() {
     Mutex::Locker l(stat_lock);
     ++seq;