From 142528151a0b2366bb9cc7a2f1fd18f1b592af60 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 12 Sep 2012 17:19:01 -0700 Subject: [PATCH] mon: share quorum features on election victory Inform peons what the quorum features are. Previously only the leader knew, which was of limited utility. This is one piece of #2690. Signed-off-by: Sage Weil --- src/messages/MMonElection.h | 18 ++++++++++++------ src/mon/Elector.cc | 4 ++-- src/mon/Monitor.cc | 8 ++++---- src/mon/Monitor.h | 5 +++-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/messages/MMonElection.h b/src/messages/MMonElection.h index 2f44c4ee8dc6d..b589d9842f1c1 100644 --- a/src/messages/MMonElection.h +++ b/src/messages/MMonElection.h @@ -21,7 +21,8 @@ class MMonElection : public Message { - static const int HEAD_VERSION = 2; + static const int HEAD_VERSION = 3; + static const int COMPAT_VERSION = 2; public: static const int OP_PROPOSE = 1; @@ -43,12 +44,12 @@ public: epoch_t epoch; bufferlist monmap_bl; set quorum; + uint64_t quorum_features; - MMonElection() : Message(MSG_MON_ELECTION, HEAD_VERSION) { } - MMonElection(int o, epoch_t e, MonMap *m) : - Message(MSG_MON_ELECTION, HEAD_VERSION), - fsid(m->fsid), op(o), epoch(e) { - + MMonElection() : Message(MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION) { } + MMonElection(int o, epoch_t e, MonMap *m) + : Message(MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION), + fsid(m->fsid), op(o), epoch(e), quorum_features(0) { // encode using full feature set; we will reencode for dest later, // if necessary m->encode(monmap_bl, CEPH_FEATURES_ALL); @@ -76,6 +77,7 @@ public: ::encode(epoch, payload); ::encode(monmap_bl, payload); ::encode(quorum, payload); + ::encode(quorum_features, payload); } void decode_payload() { bufferlist::iterator p = payload.begin(); @@ -87,6 +89,10 @@ public: ::decode(epoch, p); ::decode(monmap_bl, p); ::decode(quorum, p); + if (header.version >= 3) + ::decode(quorum_features, p); + else + quorum_features = 0; } }; diff --git a/src/mon/Elector.cc b/src/mon/Elector.cc index 515e21a5afa31..26190ee2aeb15 100644 --- a/src/mon/Elector.cc +++ b/src/mon/Elector.cc @@ -262,7 +262,7 @@ void Elector::handle_ack(MMonElection *m) void Elector::handle_victory(MMonElection *m) { - dout(5) << "handle_victory from " << m->get_source() << dendl; + dout(5) << "handle_victory from " << m->get_source() << " quorum_features " << m->quorum_features << dendl; int from = m->get_source().num(); assert(from < mon->rank); @@ -280,7 +280,7 @@ void Elector::handle_victory(MMonElection *m) bump_epoch(m->epoch); // they win - mon->lose_election(epoch, m->quorum, from); + mon->lose_election(epoch, m->quorum, from, m->quorum_features); // cancel my timer cancel_timer(); diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 287ff285e51d1..444e560043579 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -1083,7 +1083,7 @@ epoch_t Monitor::get_epoch() return elector.get_epoch(); } -void Monitor::win_election(epoch_t epoch, set& active, unsigned features) +void Monitor::win_election(epoch_t epoch, set& active, uint64_t features) { if (!is_electing()) reset(); @@ -1109,16 +1109,16 @@ void Monitor::win_election(epoch_t epoch, set& active, unsigned features) finish_election(); } -void Monitor::lose_election(epoch_t epoch, set &q, int l) +void Monitor::lose_election(epoch_t epoch, set &q, int l, uint64_t features) { state = STATE_PEON; leader_since = utime_t(); leader = l; quorum = q; outside_quorum.clear(); - quorum_features = 0; + quorum_features = features; dout(10) << "lose_election, epoch " << epoch << " leader is mon" << leader - << " quorum is " << quorum << dendl; + << " quorum is " << quorum << " features are " << quorum_features << dendl; for (vector::iterator p = paxos.begin(); p != paxos.end(); p++) (*p)->peon_init(); diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index f5cc1f636d1b9..fd45432f04fab 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -236,8 +236,9 @@ public: void start_election(); void win_standalone_election(); void win_election(epoch_t epoch, set& q, - unsigned features); // end election (called by Elector) - void lose_election(epoch_t epoch, set& q, int l); // end election (called by Elector) + uint64_t features); // end election (called by Elector) + void lose_election(epoch_t epoch, set& q, int l, + uint64_t features); // end election (called by Elector) void finish_election(); void update_logger(); -- 2.39.5