]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MgrMonitor: add "down" setting to simplify testing
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 10 Jan 2024 17:50:51 +0000 (12:50 -0500)
committerPatrick Donnelly <pdonnell@redhat.com>
Tue, 26 Mar 2024 13:35:56 +0000 (09:35 -0400)
This flag prevents promotion of a standby manager to the active. It also drops
the current active.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
(cherry picked from commit 2e2a3f15cdd9125029fca78b834b8b5bb53edbb1)

src/mon/MgrMap.h
src/mon/MgrMonitor.cc
src/mon/MgrMonitor.h
src/mon/MonCommands.h

index f37ed97fd16c7d33d4a929a292ed3bd9dd3330b7..b36acef5a7f1456556d66aff82ca6728f5763c09 100644 (file)
@@ -225,6 +225,10 @@ public:
   epoch_t epoch = 0;
   epoch_t last_failure_osd_epoch = 0;
 
+
+  static const uint64_t FLAG_DOWN = (1<<0);
+  uint64_t flags = 0;
+
   /// global_id of the ceph-mgr instance selected as a leader
   uint64_t active_gid = 0;
   /// server address reported by the leader once it is active
@@ -401,7 +405,7 @@ public:
       ENCODE_FINISH(bl);
       return;
     }
-    ENCODE_START(12, 6, bl);
+    ENCODE_START(13, 6, bl);
     encode(epoch, bl);
     encode(active_addrs, bl, features);
     encode(active_gid, bl);
@@ -425,13 +429,14 @@ public:
     // backwards compatible messsage for older monitors.
     encode(clients_addrs, bl, features);
     encode(clients_names, bl, features);
+    encode(flags, bl);
     ENCODE_FINISH(bl);
     return;
   }
 
   void decode(ceph::buffer::list::const_iterator& p)
   {
-    DECODE_START(12, p);
+    DECODE_START(13, p);
     decode(epoch, p);
     decode(active_addrs, p);
     decode(active_gid, p);
@@ -498,11 +503,15 @@ public:
        }
       }
     }
+    if (struct_v >= 13) {
+      decode(flags, p);
+    }
     DECODE_FINISH(p);
   }
 
   void dump(ceph::Formatter *f) const {
     f->dump_int("epoch", epoch);
+    f->dump_int("flags", flags);
     f->dump_int("active_gid", get_active_gid());
     f->dump_string("active_name", get_active_name());
     f->dump_object("active_addrs", active_addrs);
index 2f6510846b3bebc67982dc38b36ef59260c59800..4e9fa7d023267312b91c4d3d735d7d1dccf371eb 100644 (file)
@@ -587,22 +587,23 @@ bool MgrMonitor::prepare_beacon(MonOpRequestRef op)
     if (pending_map.standbys.count(m->get_gid())) {
       drop_standby(m->get_gid(), false);
     }
-    dout(4) << "selecting new active " << m->get_gid()
-           << " " << m->get_name()
-           << " (was " << pending_map.active_gid << " "
-           << pending_map.active_name << ")" << dendl;
-    pending_map.active_gid = m->get_gid();
-    pending_map.active_name = m->get_name();
-    pending_map.active_change = ceph_clock_now();
-    pending_map.active_mgr_features = m->get_mgr_features();
-    pending_map.available_modules = m->get_available_modules();
-    encode(m->get_metadata(), pending_metadata[m->get_name()]);
-    pending_metadata_rm.erase(m->get_name());
-
-    mon.clog->info() << "Activating manager daemon "
-                      << pending_map.active_name;
+    if (!(pending_map.flags & MgrMap::FLAG_DOWN)) {
+      dout(4) << "selecting new active " << m->get_gid()
+             << " " << m->get_name()
+             << " (was " << pending_map.active_gid << " "
+             << pending_map.active_name << ")" << dendl;
+      pending_map.active_gid = m->get_gid();
+      pending_map.active_name = m->get_name();
+      pending_map.active_change = ceph_clock_now();
+      pending_map.active_mgr_features = m->get_mgr_features();
+      pending_map.available_modules = m->get_available_modules();
+      encode(m->get_metadata(), pending_metadata[m->get_name()]);
+      pending_metadata_rm.erase(m->get_name());
 
-    updated = true;
+      mon.clog->info() << "Activating manager daemon "
+                       << pending_map.active_name;
+      updated = true;
+    }
   } else {
     if (pending_map.standbys.count(m->get_gid()) > 0) {
       dout(10) << "from existing standby " << m->get_gid() << dendl;
@@ -877,6 +878,9 @@ void MgrMonitor::on_restart()
 bool MgrMonitor::promote_standby()
 {
   ceph_assert(pending_map.active_gid == 0);
+  if (pending_map.flags & MgrMap::FLAG_DOWN) {
+    return false;
+  }
   if (pending_map.standbys.size()) {
     // Promote a replacement (arbitrary choice of standby)
     auto replacement_gid = pending_map.standbys.begin()->first;
@@ -890,6 +894,9 @@ bool MgrMonitor::promote_standby()
     pending_map.active_addrs = entity_addrvec_t();
     pending_map.active_change = ceph_clock_now();
 
+    mon.clog->info() << "Activating manager daemon "
+                     << pending_map.active_name;
+
     drop_standby(replacement_gid, false);
 
     return true;
@@ -1181,7 +1188,37 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op)
   int r = 0;
   bool plugged = false;
 
-  if (prefix == "mgr fail") {
+  if (prefix == "mgr set") {
+    std::string var;
+    if (!cmd_getval(cmdmap, "var", var) || var.empty()) {
+      ss << "Invalid variable";
+      return -EINVAL;
+    }
+    string val;
+    if (!cmd_getval(cmdmap, "val", val)) {
+      return -EINVAL;
+    }
+
+    if (var == "down") {
+      bool enable_down = false;
+      int r = parse_bool(val, &enable_down, ss);
+      if (r != 0) {
+        return r;
+      }
+      if (enable_down) {
+        if (!mon.osdmon()->is_writeable()) {
+          mon.osdmon()->wait_for_writeable(op, new C_RetryMessage(this, op));
+          return false;
+        }
+        pending_map.flags |= MgrMap::FLAG_DOWN;
+        plugged |= drop_active();
+      } else {
+        pending_map.flags &= ~(MgrMap::FLAG_DOWN);
+      }
+    } else {
+      return -EINVAL;
+    }
+  } else if (prefix == "mgr fail") {
     string who;
     if (!cmd_getval(cmdmap, "who", who)) {
       if (!map.active_gid) {
index 79d4e50051d8049ba778b51a0b5522b49fe92c4b..a2a84c141f710ac9d572fa3eeab0a7ac12f8c04c 100644 (file)
@@ -21,8 +21,9 @@
 #include "MgrMap.h"
 #include "PaxosService.h"
 #include "MonCommand.h"
+#include "CommandHandler.h"
 
-class MgrMonitor: public PaxosService
+class MgrMonitor: public PaxosService, public CommandHandler
 {
   MgrMap map;
   MgrMap pending_map;
index 8fa39ed5df58fc7d0609dad3be558d2cb30e4302..24cd0ca7c25fbcccb3b37225a625e432f375d816 100644 (file)
@@ -1249,6 +1249,10 @@ COMMAND("mgr dump "
        "name=epoch,type=CephInt,range=0,req=false",
        "dump the latest MgrMap",
        "mgr", "r")
+COMMAND("mgr set "
+       "name=var,type=CephChoices,strings=down "
+       "name=val,type=CephString ",
+       "set mgr parameter <var> to <val>", "mgr", "rw")
 COMMAND("mgr fail name=who,type=CephString,req=false",
        "treat the named manager daemon as failed", "mgr", "rw")
 COMMAND("mgr module ls",