From 1d1c143fbaf1125fb0b3bbaa8dadca9768ffefe6 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Mon, 10 Jun 2019 14:42:09 -0700 Subject: [PATCH] elector: hoist handle_victory into ElectionLogic Signed-off-by: Greg Farnum --- src/mon/Elector.cc | 34 ++++++++++++++++++++++------------ src/mon/Elector.h | 1 + 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/mon/Elector.cc b/src/mon/Elector.cc index 5c689e7f95b43..93982ff1a9bf7 100644 --- a/src/mon/Elector.cc +++ b/src/mon/Elector.cc @@ -470,6 +470,26 @@ void Elector::handle_ack(MonOpRequestRef op) logic.receive_ack(from, m->epoch); } +bool ElectionLogic::receive_victory_claim(int from, epoch_t from_epoch) +{ + ceph_assert(from < elector_my_rank()); + ceph_assert(from_epoch % 2 == 0); + + leader_acked = -1; + + // i should have seen this election if i'm getting the victory. + if (from_epoch != epoch + 1) { + dout(5) << "woah, that's a funny epoch, i must have rebooted. bumping and re-starting!" << dendl; + bump_epoch(from_epoch); + start(); + return false; + } + + bump_epoch(from_epoch); + + // they win + return true; +} void Elector::handle_victory(MonOpRequestRef op) { @@ -481,22 +501,12 @@ void Elector::handle_victory(MonOpRequestRef op) << dendl; int from = m->get_source().num(); - ceph_assert(from < mon->rank); - ceph_assert(m->epoch % 2 == 0); - - logic.leader_acked = -1; + bool accept_victory = logic.receive_victory_claim(from, m->epoch); - // i should have seen this election if i'm getting the victory. - if (m->epoch != logic.epoch + 1) { - dout(5) << "woah, that's a funny epoch, i must have rebooted. bumping and re-starting!" << dendl; - logic.bump_epoch(m->epoch); - logic.start(); + if (!accept_victory) { return; } - logic.bump_epoch(m->epoch); - - // they win mon->lose_election(logic.epoch, m->quorum, from, m->quorum_features, m->mon_features, m->mon_release); diff --git a/src/mon/Elector.h b/src/mon/Elector.h index 5ac99735c6598..20c14919657e5 100644 --- a/src/mon/Elector.h +++ b/src/mon/Elector.h @@ -45,6 +45,7 @@ public: void end_election_period(); void handle_propose_logic(epoch_t mepoch, int from); void receive_ack(int from, epoch_t from_epoch); + bool receive_victory_claim(int from, epoch_t from_epoch); void declare_victory(); -- 2.39.5