]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Elector: transmit local api on election win, accept leader's on loss
authorGreg Farnum <greg@inktank.com>
Fri, 6 Dec 2013 22:08:48 +0000 (14:08 -0800)
committerGreg Farnum <greg@inktank.com>
Mon, 9 Dec 2013 19:26:04 +0000 (11:26 -0800)
If we're the leader, just point to our local set. Disseminating these
will let peons advertise the full command set supported by the leader.
INCOMPLETE: does not yet handle winning Electors who do not send a command set.

Signed-off-by: Greg Farnum <greg@inktank.com>
src/mon/Elector.cc
src/mon/Elector.h
src/mon/Monitor.cc

index 1650a997b2d096164838eada56860ae756058944..9b32649733fc48a32ebf137f74712dcf103c297c 100644 (file)
@@ -165,8 +165,16 @@ void Elector::victory()
   
   assert(epoch % 2 == 1);  // election
   bump_epoch(epoch+1);     // is over!
+
+  // calculate my supported commands for peons to advertise
+  if (!my_supported_commands.length()) {
+    const MonCommand *cmds;
+    int cmdsize;
+    get_locally_supported_monitor_commands(&cmds, &cmdsize);
+    MonCommand::encode_array(cmds, cmdsize, my_supported_commands);
+  }
   
-  // tell everyone
+  // tell everyone!
   for (set<int>::iterator p = quorum.begin();
        p != quorum.end();
        ++p) {
@@ -174,6 +182,7 @@ void Elector::victory()
     MMonElection *m = new MMonElection(MMonElection::OP_VICTORY, epoch, mon->monmap);
     m->quorum = quorum;
     m->quorum_features = features;
+    m->commands = my_supported_commands;
     mon->messenger->send_message(m, mon->monmap->get_inst(*p));
   }
     
@@ -292,7 +301,19 @@ void Elector::handle_victory(MMonElection *m)
   mon->lose_election(epoch, m->quorum, from, m->quorum_features);
   
   // cancel my timer
-  cancel_timer();      
+  cancel_timer();
+
+  // stash leader's commands
+  if (m->commands.length()) {
+    MonCommand *new_cmds;
+    int cmdsize;
+    bufferlist::iterator bi = m->commands.begin();
+    MonCommand::decode_array(&new_cmds, &cmdsize, bi);
+    set_leader_supported_commands(new_cmds, cmdsize);
+  } else { // they are a legacy monitor; use known legacy command set
+    // TODO: actually store legacy command set, and use here!
+  }
+
   m->put();
 }
 
index f1f19b49becfb5d90125b797727db4bb8f3a5197..d17429ffa78f913188827049d841791d607b5c5d 100644 (file)
@@ -114,6 +114,7 @@ class Elector {
    * victory.  Also note each peer's feature set.
    */
   map<int, uint64_t> acked_me;
+  bufferlist my_supported_commands;
   /**
    * @}
    */
index ebdbd012d1a81c54384cecbfef82c55d78608db4..9c7a99fe5a3c4c57018a76c59f6884508a0772b3 100644 (file)
@@ -1518,6 +1518,11 @@ void Monitor::win_election(epoch_t epoch, set<int>& active, uint64_t features)
   clog.info() << "mon." << name << "@" << rank
                << " won leader election with quorum " << quorum << "\n";
 
+  const MonCommand *new_cmds;
+  int cmdsize;
+  get_locally_supported_monitor_commands(&new_cmds, &cmdsize);
+  set_leader_supported_commands(new_cmds, cmdsize);
+
   paxos->leader_init();
   for (vector<PaxosService*>::iterator p = paxos_service.begin(); p != paxos_service.end(); ++p)
     (*p)->election_finished();