]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
elector: hoist handle_victory into ElectionLogic
authorGreg Farnum <gfarnum@redhat.com>
Mon, 10 Jun 2019 21:42:09 +0000 (14:42 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Mon, 19 Aug 2019 20:04:59 +0000 (13:04 -0700)
Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/mon/Elector.cc
src/mon/Elector.h

index 5c689e7f95b438b087c54555be43a6ff64886a76..93982ff1a9bf77e21821710dcbe7b2425f1783f4 100644 (file)
@@ -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);
 
index 5ac99735c6598dc08339697a8d6999eaf57b0fb4..20c14919657e5876dd5eb311fd7c7388638c0536 100644 (file)
@@ -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();