]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: extract pgstats_cb into a method of `OSD`
authorKefu Chai <kchai@redhat.com>
Mon, 23 Oct 2017 03:14:57 +0000 (11:14 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 24 Oct 2017 08:06:26 +0000 (16:06 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/osd/OSD.cc
src/osd/OSD.h

index 124e7f1e7dcde3d338fe6b260d9ddb093f050b91..aae1778c0545a4b99d00de785c92766cbbce0e42 100644 (file)
@@ -2594,40 +2594,7 @@ int OSD::init()
   if (r < 0)
     goto out;
 
-  // This implementation unconditionally sends every is_primary PG's
-  // stats every time we're called.  This has equivalent cost to the
-  // previous implementation's worst case where all PGs are busy and
-  // their stats are always enqueued for sending.
-  mgrc.set_pgstats_cb([this](){
-      RWLock::RLocker l(map_lock);
-      
-      utime_t had_for = ceph_clock_now() - had_map_since;
-      osd_stat_t cur_stat = service.get_osd_stat();
-      cur_stat.os_perf_stat = store->get_cur_stats();
-
-      MPGStats *m = new MPGStats(monc->get_fsid(), osdmap->get_epoch(), had_for);
-      m->osd_stat = cur_stat;
-
-      Mutex::Locker lec{min_last_epoch_clean_lock};
-      min_last_epoch_clean = osdmap->get_epoch();
-      min_last_epoch_clean_pgs.clear();
-      RWLock::RLocker lpg(pg_map_lock);
-      for (const auto &i : pg_map) {
-        PG *pg = i.second;
-        if (!pg->is_primary()) {
-          continue;
-        }
-
-       pg->get_pg_stats([&](const pg_stat_t& s, epoch_t lec) {
-           m->pg_stat[pg->pg_id.pgid] = s;
-           min_last_epoch_clean = min(min_last_epoch_clean, lec);
-           min_last_epoch_clean_pgs.push_back(pg->pg_id.pgid);
-         });
-      }
-
-      return m;
-  });
-
+  mgrc.set_pgstats_cb([this](){ return collect_pg_stats(); });
   mgrc.init();
   client_messenger->add_dispatcher_head(&mgrc);
 
@@ -7059,7 +7026,40 @@ void OSD::sched_scrub()
   dout(20) << "sched_scrub done" << dendl;
 }
 
+MPGStats* OSD::collect_pg_stats()
+{
+  // This implementation unconditionally sends every is_primary PG's
+  // stats every time we're called.  This has equivalent cost to the
+  // previous implementation's worst case where all PGs are busy and
+  // their stats are always enqueued for sending.
+  RWLock::RLocker l(map_lock);
+
+  utime_t had_for = ceph_clock_now() - had_map_since;
+  osd_stat_t cur_stat = service.get_osd_stat();
+  cur_stat.os_perf_stat = store->get_cur_stats();
+
+  auto m = new MPGStats(monc->get_fsid(), osdmap->get_epoch(), had_for);
+  m->osd_stat = cur_stat;
+
+  Mutex::Locker lec{min_last_epoch_clean_lock};
+  min_last_epoch_clean = osdmap->get_epoch();
+  min_last_epoch_clean_pgs.clear();
+  RWLock::RLocker lpg(pg_map_lock);
+  for (const auto &i : pg_map) {
+    PG *pg = i.second;
+    if (!pg->is_primary()) {
+      continue;
+    }
 
+    pg->get_pg_stats([&](const pg_stat_t& s, epoch_t lec) {
+       m->pg_stat[pg->pg_id.pgid] = s;
+       min_last_epoch_clean = min(min_last_epoch_clean, lec);
+       min_last_epoch_clean_pgs.push_back(pg->pg_id.pgid);
+      });
+  }
+
+  return m;
+}
 
 // =====================================================
 // MAP
index dfc15f8e152296522aa4dcce8facbd34197990f3..78d2e33eebd8157939a3dda80c6a89ba04563c9f 100644 (file)
@@ -2217,6 +2217,9 @@ protected:
     }
   } remove_wq;
 
+  // -- status reporting --
+  MPGStats *collect_pg_stats();
+
 private:
   bool ms_can_fast_dispatch_any() const override { return true; }
   bool ms_can_fast_dispatch(const Message *m) const override {