From 6a98997b80b17f178d4d6e749ccdff5adf69bd5f Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 4 Mar 2019 17:12:22 +0800 Subject: [PATCH] crimson/osd/pg: accessors for pg stats/state so OSD can collect pg stats and report them to mgr Signed-off-by: Kefu Chai --- src/crimson/osd/pg.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ src/crimson/osd/pg.h | 4 ++++ 2 files changed, 46 insertions(+) diff --git a/src/crimson/osd/pg.cc b/src/crimson/osd/pg.cc index 4d6a1ca80d1..b2a566a39f4 100644 --- a/src/crimson/osd/pg.cc +++ b/src/crimson/osd/pg.cc @@ -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; diff --git a/src/crimson/osd/pg.h b/src/crimson/osd/pg.h index 58a9e7089dd..72bb7a155a1 100644 --- a/src/crimson/osd/pg.h +++ b/src/crimson/osd/pg.h @@ -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; -- 2.39.5