]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: Monitor: dedup code on {win,lose}_election()
authorJoao Eduardo Luis <joao@suse.de>
Tue, 22 Mar 2016 22:42:12 +0000 (22:42 +0000)
committerJoao Eduardo Luis <joao@suse.de>
Sat, 29 Oct 2016 03:10:22 +0000 (04:10 +0100)
refactor out the loop that calls 'election_finished()' on all paxos
services.

Signed-off-by: Joao Eduardo Luis <joao@suse.de>
src/mon/Monitor.cc
src/mon/Monitor.h

index fbc9133615d24a68962bf39cdef55a83d5a39a2e..65c462283df928106836debd6a312de60fc953db 100644 (file)
@@ -1863,6 +1863,18 @@ epoch_t Monitor::get_epoch()
   return elector.get_epoch();
 }
 
+void Monitor::_finish_svc_election()
+{
+  assert(state == STATE_LEADER || state == STATE_PEON);
+
+  for (auto p : paxos_service) {
+    // we already called election_finished() on monmon(); avoid callig twice
+    if (state == STATE_LEADER && p == monmon())
+      continue;
+    p->election_finished();
+  }
+}
+
 void Monitor::win_election(epoch_t epoch, set<int>& active, uint64_t features,
                            const MonCommand *cmdset, int cmdsize,
                            const set<int> *classic_monitors)
@@ -1891,11 +1903,7 @@ void Monitor::win_election(epoch_t epoch, set<int>& active, uint64_t features,
   // when monitors are call elections or participating in a paxos
   // round without agreeing on who the participants are.
   monmon()->election_finished();
-  for (vector<PaxosService*>::iterator p = paxos_service.begin();
-       p != paxos_service.end(); ++p) {
-    if (*p != monmon())
-      (*p)->election_finished();
-  }
+  _finish_svc_election();
   health_monitor->start(epoch);
 
   logger->inc(l_mon_election_win);
@@ -1927,8 +1935,7 @@ void Monitor::lose_election(epoch_t epoch, set<int> &q, int l, uint64_t features
           << " quorum is " << quorum << " features are " << quorum_features << dendl;
 
   paxos->peon_init();
-  for (vector<PaxosService*>::iterator p = paxos_service.begin(); p != paxos_service.end(); ++p)
-    (*p)->election_finished();
+  _finish_svc_election();
   health_monitor->start(epoch);
 
   logger->inc(l_mon_election_lose);
index 49540f35ad0b7e2194b86b9c20b6dff743fa64d0..29f97d60b5077170167612289b66ec7c4c23b6eb 100644 (file)
@@ -592,6 +592,7 @@ public:
 private:
   void _reset();   ///< called from bootstrap, start_, or join_election
   void wait_for_paxos_write();
+  void _finish_svc_election(); ///< called by {win,lose}_election
 public:
   void bootstrap();
   void join_election();