]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add set-weight command
authorxie xingguo <xie.xingguo@zte.com.cn>
Sat, 16 Mar 2019 03:34:57 +0000 (11:34 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Wed, 20 Mar 2019 03:23:32 +0000 (11:23 +0800)
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
qa/workunits/cephtool/test.sh
src/mon/MonCommands.h
src/mon/MonMap.h
src/mon/MonmapMonitor.cc

index 827d081090b7f6936114017a02240b7c42ffab14..548cc7572eeef4a64ecb31e18d6bdee8cf19433f 100755 (executable)
@@ -1177,6 +1177,19 @@ function test_mon_mon()
   expect_false ceph mon feature set abcd --yes-i-really-mean-it
 }
 
+function test_mon_priority_and_weight()
+{
+    for i in 0 1 65535; do
+      ceph mon set-weight a $i
+      w=$(ceph mon dump --format=json-pretty 2>/dev/null | jq '.mons[0].weight')
+      [[ "$w" == "$i" ]]
+    done
+
+    for i in -1 65536; do
+      expect_false ceph mon set-weight a $i
+    done
+}
+
 function gen_secrets_file()
 {
   # lets assume we can have the following types
index 38f605bed9b032f4c2717620a5e21997f0bc5e83..b87bd7facbee2f6eb59f6842c39ddb1f1960e16b 100644 (file)
@@ -463,6 +463,11 @@ COMMAND("mon set-addrs " \
        "name=addrs,type=CephString",
        "set the addrs (IPs and ports) a specific monitor binds to",
        "mon", "rw")
+COMMAND("mon set-weight " \
+        "name=name,type=CephString " \
+        "name=weight,type=CephInt,range=0|65535",
+        "set the weight for the specified mon",
+        "mon", "rw")
 COMMAND("mon enable-msgr2",
        "enable the msgr2 protocol on port 3300",
        "mon", "rw")
index 2c1f41216aa10db7e7e81e4cf1fbb35076d978c1..97db1e64c1cc592c84b6a83e2cfbda817eff4be7 100644 (file)
@@ -385,6 +385,11 @@ public:
     ceph_assert(it != mon_info.end());
     return it->second.weight;
   }
+  void set_weight(const string& n, uint16_t v) {
+    auto it = mon_info.find(n);
+    ceph_assert(it != mon_info.end());
+    it->second.weight = v;
+  }
 
   void encode(bufferlist& blist, uint64_t con_features) const;
   void decode(bufferlist& blist) {
index 9298f24421120a69f4e9ad3b3fd0558d8f9532ec..2497dadd4f7b471da93fb6f3825bc8b45a290061 100644 (file)
@@ -782,6 +782,23 @@ bool MonmapMonitor::prepare_command(MonOpRequestRef op)
     pending_map.set_addrvec(name, av);
     pending_map.last_changed = ceph_clock_now();
     propose = true;
+  } else if (prefix == "mon set-weight") {
+    string name;
+    int64_t weight;
+    if (!cmd_getval(g_ceph_context, cmdmap, "name", name) ||
+        !cmd_getval(g_ceph_context, cmdmap, "weight", weight)) {
+      err = -EINVAL;
+      goto reply;
+    }
+    if (!pending_map.contains(name)) {
+      ss << "mon." << name << " does not exist";
+      err = -ENOENT;
+      goto reply;
+    }
+    err = 0;
+    pending_map.set_weight(name, weight);
+    pending_map.last_changed = ceph_clock_now();
+    propose = true;
   } else if (prefix == "mon enable-msgr2") {
     if (!monmap.get_required_features().contains_all(
          ceph::features::mon::FEATURE_NAUTILUS)) {