From 1cda402dec072018bf382a738135de1d24c5a677 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 2 Mar 2019 13:18:28 +0800 Subject: [PATCH] crimson/osd: add PG::is_{acting,up}() Signed-off-by: Kefu Chai --- src/crimson/osd/pg.cc | 23 +++++++++++++++++++++++ src/crimson/osd/pg.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/crimson/osd/pg.cc b/src/crimson/osd/pg.cc index f1a6590e4c0..c76a986ff5d 100644 --- a/src/crimson/osd/pg.cc +++ b/src/crimson/osd/pg.cc @@ -155,6 +155,29 @@ bool PG::is_primary() const return whoami == primary; } + +namespace { + bool has_shard(bool ec, const vector& osds, pg_shard_t pg_shard) + { + if (ec) { + return (osds.size() > static_cast(pg_shard.shard) && + osds[pg_shard.shard] == pg_shard.osd); + } else { + return std::find(osds.begin(), osds.end(), pg_shard.osd) != osds.end(); + } + } +} + +bool PG::is_acting(pg_shard_t pg_shard) const +{ + return has_shard(pool.is_erasure(), acting, pg_shard); +} + +bool PG::is_up(pg_shard_t pg_shard) const +{ + return has_shard(pool.is_erasure(), up, pg_shard); +} + epoch_t PG::get_last_peering_reset() const { return last_peering_reset; diff --git a/src/crimson/osd/pg.h b/src/crimson/osd/pg.h index 4c293d707e0..d2fb3535dd4 100644 --- a/src/crimson/osd/pg.h +++ b/src/crimson/osd/pg.h @@ -47,6 +47,8 @@ public: const PastIntervals& get_past_intervals() const; pg_shard_t get_primary() const; bool is_primary() const; + bool is_acting(pg_shard_t pg_shard) const; + bool is_up(pg_shard_t pg_shard) const; pg_shard_t get_whoami() const; epoch_t get_last_peering_reset() const; void update_last_peering_reset(); -- 2.39.5