summaryrefslogtreecommitdiffstats
path: root/src/mon/Monitor.cc
diff options
context:
space:
mode:
authorJoao Eduardo Luis <joao@suse.de>2016-03-22 23:42:12 +0100
committerJoao Eduardo Luis <joao@suse.de>2016-10-29 05:10:22 +0200
commit639185b2957762ddbd3f66d79044aa5351a36c99 (patch)
tree17be7f1a924906cf8a56f420f7945b46b0669235 /src/mon/Monitor.cc
parentmon: Monitor: drop useless 'todo' comment (diff)
downloadceph-639185b2957762ddbd3f66d79044aa5351a36c99.tar.xz
ceph-639185b2957762ddbd3f66d79044aa5351a36c99.zip
mon: Monitor: dedup code on {win,lose}_election()
refactor out the loop that calls 'election_finished()' on all paxos services. Signed-off-by: Joao Eduardo Luis <joao@suse.de>
Diffstat (limited to 'src/mon/Monitor.cc')
-rw-r--r--src/mon/Monitor.cc21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc
index fbc9133615d..65c462283df 100644
--- a/src/mon/Monitor.cc
+++ b/src/mon/Monitor.cc
@@ -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);