From: Greg Farnum Date: Mon, 2 Nov 2020 08:14:48 +0000 (+0000) Subject: mon: retain disallowed leader list on restart X-Git-Tag: v16.1.0~657^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=41d7dcc1b7a627546648758bf8b14751c8804f15;p=ceph.git mon: retain disallowed leader list on restart We were only setting this when new monmaps were read from paxos -- whoops! Pull apart that mechanism a little bit and make sure to set them before doing elections, as part of bootstrap. Signed-off-by: Greg Farnum --- diff --git a/src/mon/Elector.h b/src/mon/Elector.h index 9ac85b631e85..1ecf566d9d6d 100644 --- a/src/mon/Elector.h +++ b/src/mon/Elector.h @@ -372,14 +372,19 @@ class Elector : public ElectionOwner, RankProvider { void notify_rank_removed(int rank_removed); void notify_strategy_maybe_changed(int strategy); /** - * Set the disallowed leaders. This has no effect - * if the disallowed set is identical; if it differs - * we call an election. + * Set the disallowed leaders. + * + * If you call this and the new disallowed set + * contains your current leader, you are + * responsible for calling an election! + * + * @returns false if the set is unchanged, + * true if the set changed */ - void set_disallowed_leaders(const set& dl) { - if (dl == disallowed_leaders) return; + bool set_disallowed_leaders(const set& dl) { + if (dl == disallowed_leaders) return false; disallowed_leaders = dl; - call_election(); + return true; } void dump_connection_scores(Formatter *f) { f->open_object_section("connection scores"); diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 1bb7b1713706..1235f3dacafd 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -1237,6 +1237,9 @@ void Monitor::bootstrap() dout(10) << "bootstrap -- finished compaction" << dendl; } + // stretch mode bits + set_elector_disallowed_leaders(false); + // singleton monitor? if (monmap->size() == 1 && rank == 0) { win_standalone_election(); @@ -2676,6 +2679,7 @@ void Monitor::get_mon_status(Formatter *f) f->close_section(); f->dump_object("feature_map", session_map.feature_map); + f->dump_bool("stretch_mode", stretch_mode_engaged); f->close_section(); // mon_status } @@ -6449,6 +6453,16 @@ void Monitor::notify_new_monmap() maybe_engage_stretch_mode(); } + if (is_stretch_mode()) { + if (!monmap->stretch_marked_down_mons.empty()) { + set_degraded_stretch_mode(); + } + } + set_elector_disallowed_leaders(true); +} + +void Monitor::set_elector_disallowed_leaders(bool allow_election) +{ set dl; for (auto name : monmap->disallowed_leaders) { dl.insert(monmap->get_rank(name)); @@ -6457,12 +6471,13 @@ void Monitor::notify_new_monmap() for (auto name : monmap->stretch_marked_down_mons) { dl.insert(monmap->get_rank(name)); } - if (!monmap->stretch_marked_down_mons.empty()) { - set_degraded_stretch_mode(); - } dl.insert(monmap->get_rank(monmap->tiebreaker_mon)); } - elector.set_disallowed_leaders(dl); + + bool disallowed_changed = elector.set_disallowed_leaders(dl); + if (disallowed_changed && allow_election) { + elector.call_election(); + } } struct CMonEnableStretchMode : public Context { diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 19dff639bae0..0a9a70fcf53b 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -257,6 +257,7 @@ private: bool session_stretch_allowed(MonSession *s, MonOpRequestRef& op); void disconnect_disallowed_stretch_sessions(); + void set_elector_disallowed_leaders(bool allow_election); public: bool is_stretch_mode() { return stretch_mode_engaged; } bool is_degraded_stretch_mode() { return degraded_stretch_mode; }