]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/osd/pg: accessors for pg stats/state
authorKefu Chai <kchai@redhat.com>
Mon, 4 Mar 2019 09:12:22 +0000 (17:12 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 20 Mar 2019 09:33:38 +0000 (17:33 +0800)
so OSD can collect pg stats and report them to mgr

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/pg.cc
src/crimson/osd/pg.h

index 4d6a1ca80d132567c07fbc7003cf3bc5265daf33..b2a566a39f4cbcde255d2bd5234f2e0ad07ff7c3 100644 (file)
@@ -92,6 +92,48 @@ const pg_info_t& PG::get_info() const
   return info;
 }
 
+const pg_stat_t& PG::get_stats() const
+{
+  return info.stats;
+}
+
+void PG::clear_state(uint64_t mask)
+{
+  if (!test_state(mask))
+    return;
+  info.stats.state &= ~mask;
+  const auto now = utime_t{coarse_real_clock::now()};
+  info.stats.last_change = now;
+  if (mask & PG_STATE_ACTIVE) {
+    info.stats.last_active = now;
+  }
+}
+
+bool PG::test_state(uint64_t mask) const
+{
+  return info.stats.state & mask;
+}
+
+void PG::set_state(uint64_t mask)
+{
+  if (test_state(mask)) {
+    return;
+  }
+  info.stats.state |= mask;
+  const auto now = utime_t{coarse_real_clock::now()};
+  info.stats.last_change = now;
+  if (mask & PG_STATE_ACTIVE) {
+    info.stats.last_became_active = now;
+  }
+  if (mask & (PG_STATE_ACTIVE | PG_STATE_PEERED) &&
+      test_state(PG_STATE_ACTIVE | PG_STATE_PEERED)) {
+    info.stats.last_became_peered = now;
+  }
+  if (mask & PG_STATE_CLEAN) {
+    info.stats.last_epoch_clean = get_osdmap_epoch();
+  }
+}
+
 const PastIntervals& PG::get_past_intervals() const
 {
   return past_intervals;
index 58a9e7089dd47476f3663f2cea366dee2442ce5c..72bb7a155a14dbfec8943fa466f83c33842dc40b 100644 (file)
@@ -39,6 +39,10 @@ public:
 
   epoch_t get_osdmap_epoch() const;
   const pg_info_t& get_info() const;
+  const pg_stat_t& get_stats() const;
+  void clear_state(uint64_t mask);
+  bool test_state(uint64_t mask) const;
+  void set_state(uint64_t mask);
   const PastIntervals& get_past_intervals() const;
   pg_shard_t get_primary() const;
   bool is_primary() const;