From 5e91201f75c97ebf82bd21a4ab9b3156243461fe Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 23 May 2018 15:37:57 -0500 Subject: [PATCH] mon/MonmapMonitor: add 'mon set-rank ' command 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 --- src/mon/MonCommands.h | 5 +++++ src/mon/MonMap.h | 15 +++++++++++++++ src/mon/MonmapMonitor.cc | 20 +++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index a17ba96f32e..66d90ee1b05 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -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 diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index 5d2e5def385..92d210b91a6 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -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); } diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc index a6be9a6d06b..d9158485df9 100644 --- a/src/mon/MonmapMonitor.cc +++ b/src/mon/MonmapMonitor.cc @@ -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; -- 2.39.5