]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: retain disallowed leader list on restart
authorGreg Farnum <gfarnum@redhat.com>
Mon, 2 Nov 2020 08:14:48 +0000 (08:14 +0000)
committerGreg Farnum <gfarnum@redhat.com>
Fri, 6 Nov 2020 06:13:03 +0000 (06:13 +0000)
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 <gfarnum@redhat.com>
src/mon/Elector.h
src/mon/Monitor.cc
src/mon/Monitor.h

index 9ac85b631e85190fc1503df4273bce690fa9c299..1ecf566d9d6d981623bd04d42fd7ec881cd7506d 100644 (file)
@@ -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<int>& dl) {
-    if (dl == disallowed_leaders) return;
+  bool set_disallowed_leaders(const set<int>& 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");
index 1bb7b17137062af5f1cadfb95e8c994ed49776b0..1235f3dacafd4aeb27aa62e7884aa246e15ffbf4 100644 (file)
@@ -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<int> 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 {
index 19dff639bae0d4e7c211b119a6ddf17540530fa2..0a9a70fcf53b9fdab62c0d4181140a7104884c79 100644 (file)
@@ -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; }