From d33df28c2b85036940b54102c2c9084dfbbb1adb Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Fri, 6 Dec 2013 14:08:48 -0800 Subject: [PATCH] Elector: transmit local api on election win, accept leader's on loss 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 --- src/mon/Elector.cc | 25 +++++++++++++++++++++++-- src/mon/Elector.h | 1 + src/mon/Monitor.cc | 5 +++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/mon/Elector.cc b/src/mon/Elector.cc index 1650a997b2d09..9b32649733fc4 100644 --- a/src/mon/Elector.cc +++ b/src/mon/Elector.cc @@ -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::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(); } diff --git a/src/mon/Elector.h b/src/mon/Elector.h index f1f19b49becfb..d17429ffa78f9 100644 --- a/src/mon/Elector.h +++ b/src/mon/Elector.h @@ -114,6 +114,7 @@ class Elector { * victory. Also note each peer's feature set. */ map acked_me; + bufferlist my_supported_commands; /** * @} */ diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index ebdbd012d1a81..9c7a99fe5a3c4 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -1518,6 +1518,11 @@ void Monitor::win_election(epoch_t epoch, set& 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::iterator p = paxos_service.begin(); p != paxos_service.end(); ++p) (*p)->election_finished(); -- 2.39.5