]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: set peon state to electing if other mons call an election
authorSage Weil <sage@inktank.com>
Sat, 13 Jul 2013 15:36:25 +0000 (08:36 -0700)
committerSage Weil <sage@inktank.com>
Mon, 15 Jul 2013 20:42:53 +0000 (13:42 -0700)
Previously we would call mon->reset() and set various flags (like
exited_quorum timestamp), but the state would remain PEON.  Make an
explicit join_election() callback and set the state there, and add
asserts in reset() (renamed to be private) so that we ensure all
callers are well-behaved.

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/Elector.cc
src/mon/Monitor.cc
src/mon/Monitor.h

index 4b1221d2c316c8edddefa0fba00953e7e827c97d..1650a997b2d096164838eada56860ae756058944 100644 (file)
@@ -55,7 +55,8 @@ void Elector::bump_epoch(epoch_t e)
   MonitorDBStore::Transaction t;
   t.put(Monitor::MONITOR_NAME, "election_epoch", epoch);
   mon->store->apply_transaction(t);
-  mon->reset();
+
+  mon->join_election();
 
   // clear up some state
   electing_me = false;
@@ -198,7 +199,6 @@ void Elector::handle_propose(MMonElection *m)
       dout(5) << " got propose from old epoch, quorum is " << mon->quorum 
              << ", " << m->get_source() << " must have just started" << dendl;
       // we may be active; make sure we reset things in the monitor appropriately.
-      mon->reset();
       mon->start_election();
     } else {
       dout(5) << " ignoring old propose" << dendl;
@@ -215,7 +215,6 @@ void Elector::handle_propose(MMonElection *m)
     } else {
       // wait, i should win!
       if (!electing_me) {
-       mon->reset();
        mon->start_election();
       }
     }
index 914714d733ca99b8951d824581903a97aa26f0ae..c801886eb452c94ab39c1ab48117f9d474193d78 100644 (file)
@@ -644,7 +644,7 @@ void Monitor::bootstrap()
   // reset
   state = STATE_PROBING;
 
-  reset();
+  _reset();
 
   // sync store
   if (g_conf->mon_compact_on_bootstrap) {
@@ -708,9 +708,12 @@ void Monitor::_add_bootstrap_peer_hint(string cmd, string args, ostream& ss)
 }
 
 // called by bootstrap(), or on leader|peon -> electing
-void Monitor::reset()
+void Monitor::_reset()
 {
-  dout(10) << "reset" << dendl;
+  dout(10) << __func__ << dendl;
+
+  assert(state == STATE_ELECTING ||
+        state == STATE_PROBING);
 
   cancel_probe_timeout();
   timecheck_finish();
@@ -1407,14 +1410,21 @@ void Monitor::handle_probe_reply(MMonProbe *m)
   m->put();
 }
 
+void Monitor::join_election()
+{
+  dout(10) << __func__ << dendl;
+  state = STATE_ELECTING;
+  _reset();
+}
+
 void Monitor::start_election()
 {
   dout(10) << "start_election" << dendl;
+  state = STATE_ELECTING;
+  _reset();
 
   cancel_probe_timeout();
 
-  // call a new election
-  state = STATE_ELECTING;
   clog.info() << "mon." << name << " calling new monitor election\n";
   elector.call_election();
 }
@@ -1447,8 +1457,10 @@ epoch_t Monitor::get_epoch()
 
 void Monitor::win_election(epoch_t epoch, set<int>& active, uint64_t features) 
 {
-  if (!is_electing())
-    reset();
+  if (!is_electing()) {
+    state = STATE_ELECTING;
+    _reset();
+  }
 
   state = STATE_LEADER;
   leader_since = ceph_clock_now(g_ceph_context);
@@ -2205,14 +2217,12 @@ void Monitor::handle_command(MMonCommand *m)
     string quorumcmd;
     cmd_getval(g_ceph_context, cmdmap, "quorumcmd", quorumcmd);
     if (quorumcmd == "exit") {
-      reset();
       start_election();
       elector.stop_participating();
       rs = "stopped responding to quorum, initiated new election";
       r = 0;
     } else if (quorumcmd == "enter") {
       elector.start_participating();
-      reset();
       start_election();
       rs = "started responding to quorum, initiated new election";
       r = 0;
index 35bff4207add8a3f40a45c4233b511dade32021c..5bf0c0ef962f75a2e9d6cfb8811d1dcf1134768d 100644 (file)
@@ -509,8 +509,11 @@ public:
     return quorum_features;
   }
 
+private:
+  void _reset();   ///< called from bootstrap, start_, or join_election
+public:
   void bootstrap();
-  void reset();
+  void join_election();
   void start_election();
   void win_standalone_election();
   void win_election(epoch_t epoch, set<int>& q,