]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon/MonmapMonitor: add 'mon set-rank <name> <rank>' command
authorSage Weil <sage@redhat.com>
Wed, 23 May 2018 20:37:57 +0000 (15:37 -0500)
committerSage Weil <sage@redhat.com>
Sun, 27 May 2018 22:16:50 +0000 (17:16 -0500)
Add a command to manipulate the mon ranks.  This lets you control which
mon is preferred as the primary, in case you care about such things.
Mostly it doesn't matter.  (Previously we preferred the mon with the
lowest-sorting IP address, which is pretty arbitrary.)

Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/MonCommands.h
src/mon/MonMap.h
src/mon/MonmapMonitor.cc

index a17ba96f32e2f876e960b12735e0f9e26c2cfad2..66d90ee1b05d9a8a4181ebff5dc12095b21ef794 100644 (file)
@@ -443,6 +443,11 @@ COMMAND("mon feature set " \
         "name=sure,type=CephChoices,strings=--yes-i-really-mean-it,req=false", \
         "set provided feature on mon map", \
         "mon", "rw", "cli,rest")
+COMMAND("mon set-rank " \
+       "name=name,type=CephString " \
+       "name=rank,type=CephInt",
+       "set the rank for the specified mon",
+       "mon", "rw", "cli,rest")
 
 /*
  * OSD commands
index 5d2e5def38574f23596eef9318e8231bc1ea757e..92d210b91a6d96e24b3d7ca32f9418f273a11be0 100644 (file)
@@ -218,6 +218,21 @@ public:
     calc_addr_mons();
   }
 
+  int set_rank(const string& name, int rank) {
+    int oldrank = get_rank(name);
+    if (oldrank < 0) {
+      return -ENOENT;
+    }
+    if (rank < 0 || rank >= (int)ranks.size()) {
+      return -EINVAL;
+    }
+    if (oldrank != rank) {
+      ranks.erase(ranks.begin() + oldrank);
+      ranks.insert(ranks.begin() + rank, name);
+    }
+    return 0;
+  }
+
   bool contains(const string& name) const {
     return mon_info.count(name);
   }
index a6be9a6d06b045049033a5d26cf119d97bc3cbeb..d9158485df98493cdf6e9077ce890bd27e64c329 100644 (file)
@@ -676,7 +676,25 @@ bool MonmapMonitor::prepare_command(MonOpRequestRef op)
             << "persistent = " << pending_map.persistent_features
             // output optional nevertheless, for auditing purposes.
             << ", optional = " << pending_map.optional_features << dendl;
-    
+
+  } else if (prefix == "mon set-rank") {
+    string name;
+    int64_t rank;
+    if (!cmd_getval(g_ceph_context, cmdmap, "name", name) ||
+       !cmd_getval(g_ceph_context, cmdmap, "rank", rank)) {
+      err = -EINVAL;
+      goto reply;
+    }
+    int oldrank = pending_map.get_rank(name);
+    if (oldrank < 0) {
+      ss << "mon." << name << " does not exist in monmap";
+      err = -ENOENT;
+      goto reply;
+    }
+    err = 0;
+    pending_map.set_rank(name, rank);
+    pending_map.last_changed = ceph_clock_now();
+    propose = true;
   } else {
     ss << "unknown command " << prefix;
     err = -EINVAL;