From 95bec98739256c1e2cefa7b63b1eff66d400d46c Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Fri, 12 Mar 2021 22:41:03 +0000 Subject: [PATCH] osd: PeeringState: implement an acting_set_writeable() function Use it instead of direct checks against min_size and stretch_set_can_peer() when deciding whether to go STATE_ACTIVE/STATE_PEERED or do updates to things like last_epoch_started. Signed-off-by: Greg Farnum --- src/osd/PeeringState.cc | 14 ++++---------- src/osd/PeeringState.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/osd/PeeringState.cc b/src/osd/PeeringState.cc index e0f13adb56f..c022ebb5e53 100644 --- a/src/osd/PeeringState.cc +++ b/src/osd/PeeringState.cc @@ -2654,8 +2654,7 @@ void PeeringState::activate( if (is_primary()) { // only update primary last_epoch_started if we will go active - if ((acting.size() >= pool.info.min_size) && - pool.info.stretch_set_can_peer(acting, *get_osdmap(), NULL)) { + if (acting_set_writeable()) { ceph_assert(cct->_conf->osd_find_best_info_ignore_history_les || info.last_epoch_started <= activation_epoch); info.last_epoch_started = activation_epoch; @@ -2956,8 +2955,7 @@ void PeeringState::activate( state_set(PG_STATE_ACTIVATING); pl->on_activate(std::move(to_trim)); } - if ((acting.size() >= pool.info.min_size) && - pool.info.stretch_set_can_peer(acting, *get_osdmap(), NULL)) { + if (acting_set_writeable()) { PGLog::LogEntryHandlerRef rollbacker{pl->get_log_handler(t)}; pg_log.roll_forward(rollbacker.get()); } @@ -6222,9 +6220,7 @@ boost::statechart::result PeeringState::Active::react(const AllReplicasActivated pl->set_not_ready_to_merge_source(pgid); } } - } else if ((ps->acting.size() < ps->pool.info.min_size) || - !ps->pool.info.stretch_set_can_peer(ps->acting, - *ps->get_osdmap(), NULL)) { + } else if (!ps->acting_set_writeable()) { ps->state_set(PG_STATE_PEERED); } else { ps->state_set(PG_STATE_ACTIVE); @@ -6382,9 +6378,7 @@ boost::statechart::result PeeringState::ReplicaActive::react( {}, /* lease */ ps->get_lease_ack()); - if ((ps->acting.size() >= ps->pool.info.min_size) && - ps->pool.info.stretch_set_can_peer(ps->acting, - *ps->get_osdmap(), NULL)) { + if (ps->acting_set_writeable()) { ps->state_set(PG_STATE_ACTIVE); } else { ps->state_set(PG_STATE_PEERED); diff --git a/src/osd/PeeringState.h b/src/osd/PeeringState.h index 2cae797d62d..01145a03287 100644 --- a/src/osd/PeeringState.h +++ b/src/osd/PeeringState.h @@ -2312,6 +2312,16 @@ public: hoid, get_min_last_complete_ondisk()); } + /** + * Returns whether the current acting set is able to go active + * and serve writes. It needs to satisfy min_size and any + * applicable stretch cluster constraints. + */ + bool acting_set_writeable() { + return (acting.size() >= pool.info.min_size) && + (pool.info.stretch_set_can_peer(acting, *get_osdmap(), NULL)); + } + /** * Returns whether all peers which might have unfound objects have been * queried or marked lost. -- 2.39.5