]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
elector: hoist victory into ElectionLogic
authorGreg Farnum <gfarnum@redhat.com>
Fri, 7 Jun 2019 22:19:40 +0000 (15:19 -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
src/mon/Monitor.cc
src/mon/Monitor.h

index 0c6daf8955ef76e432352496fbd61f8703eddb19..f7acbdce814f2fa2d89b40d5acfe0fb1ae6abc9a 100644 (file)
@@ -245,7 +245,7 @@ void ElectionLogic::end_election_period()
   if (electing_me &&
       acked_me.size() > (elector_paxos_size() / 2)) {
     // i win
-    elector->victory();
+    declare_victory();
   } else {
     // whoever i deferred to didn't declare victory quickly enough.
     if (elector_ever_participated())
@@ -255,18 +255,29 @@ void ElectionLogic::end_election_period()
   }
 }
 
-void Elector::victory()
+
+void ElectionLogic::declare_victory()
+{
+  leader_acked = -1;
+  electing_me = false;
+
+  set<int> new_quorum;
+  new_quorum.swap(acked_me);
+  
+  ceph_assert(epoch % 2 == 1);  // election
+  bump_epoch(epoch+1);     // is over!
+
+  elector->message_victory(new_quorum);
+}
+
+void Elector::message_victory(const set<int>& quorum)
 {
-  logic.leader_acked = -1;
-  logic.electing_me = false;
 
   uint64_t cluster_features = CEPH_FEATURES_ALL;
   mon_feature_t mon_features = ceph::features::mon::get_supported();
-  set<int> quorum;
   map<int,Metadata> metadata;
   ceph_release_t min_mon_release{ceph_release_t::unknown};
-  for (auto id : logic.acked_me) {
-    quorum.insert(id);
+  for (auto id : quorum) {
     auto i = peer_info.find(id);
     ceph_assert(i != peer_info.end());
     auto& info = i->second;
@@ -281,8 +292,6 @@ void Elector::victory()
 
   cancel_timer();
   
-  ceph_assert(logic.epoch % 2 == 1);  // election
-  logic.bump_epoch(logic.epoch+1);     // is over!
 
   // tell everyone!
   for (set<int>::iterator p = quorum.begin();
@@ -445,7 +454,7 @@ void Elector::handle_ack(MonOpRequestRef op)
     // is that _everyone_?
     if (logic.acked_me.size() == mon->monmap->size()) {
       // if yes, shortcut to election finish
-      victory();
+      logic.declare_victory();
     }
   } else {
     // ignore, i'm deferring already.
index 2593b64a30459127a074acdf285f8cb9c482b745..b0c81035cf598c00f474dac3a7c9adf3abcad02a 100644 (file)
@@ -44,6 +44,7 @@ public:
   void defer(int who);
   void end_election_period();
   void handle_propose_logic(epoch_t mepoch, int from);
+  void declare_victory();
 
   
 private:
@@ -264,8 +265,7 @@ private:
    * @post  We have a quorum, composed of the monitors that acked us
    * @post  We sent a message of type OP_VICTORY to each quorum member.
    */
-  void victory();
-
+  void message_victory(const set<int>& quorum);
   /**
    * Handle a message from some other node proposing itself to become it
    * the Leader.
index 6ee95fee85c66b65f31734a45817ff0d7d4e28cf..89bc41985d0fcbb11e87d1ede8b71f87b7cc6c47 100644 (file)
@@ -2136,7 +2136,7 @@ void Monitor::_finish_svc_election()
   }
 }
 
-void Monitor::win_election(epoch_t epoch, set<int>& active, uint64_t features,
+void Monitor::win_election(epoch_t epoch, const set<int>& active, uint64_t features,
                            const mon_feature_t& mon_features,
                           ceph_release_t min_mon_release,
                           const map<int,Metadata>& metadata)
index 81d9c66f781c14b6068147ac225f4c575c4f2c61..a369d998b7a1569613d503d91e4f3eba07b14411 100644 (file)
@@ -601,7 +601,7 @@ public:
   void start_election();
   void win_standalone_election();
   // end election (called by Elector)
-  void win_election(epoch_t epoch, set<int>& q,
+  void win_election(epoch_t epoch, const set<int>& q,
                    uint64_t features,
                     const mon_feature_t& mon_features,
                    ceph_release_t min_mon_release,