From 4b3df5a850db054928f9fcc6ef0a160a05a2ffa9 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 10 Feb 2020 16:27:22 +0800 Subject: [PATCH] ceph-monstore-tool: rename mon-ids in initial monmap when ceph-mon starts, it checks to see if it's listed in the monmap, if not it complains ``` no public_addr or public_network specified, and mon.a not present in monmap or ceph.conf. ``` then bails out. normally, the monitor will try to rename its name in monmap when performing "mkfs", but in our case, we are merely using the "mkfs" monmap for passing the monmap built by ceph-monstore-tools, and we don't actually go through the "mkfs" process. so, ceph-mon won't rename when booting up. in this change, user is allowed to specify the mon-ids in command line when rebuilding mondb, the default mon-ids would be a,b,c,... if not specified. Signed-off-by: Kefu Chai --- .../troubleshooting/troubleshooting-mon.rst | 7 +++- src/tools/ceph_monstore_tool.cc | 38 +++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/doc/rados/troubleshooting/troubleshooting-mon.rst b/doc/rados/troubleshooting/troubleshooting-mon.rst index d1feedcdd13..e8d32c4cae9 100644 --- a/doc/rados/troubleshooting/troubleshooting-mon.rst +++ b/doc/rados/troubleshooting/troubleshooting-mon.rst @@ -439,7 +439,12 @@ information stored in OSDs.:: --cap mon 'allow *' ceph-authtool /path/to/admin.keyring -n client.admin \ --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow *' - ceph-monstore-tool $ms rebuild -- --keyring /path/to/admin.keyring + # if your monitors' ids are not single characters like 'a', 'b', 'c', please + # specify them in the command line by passing them as arguments of the "--mon-ids" + # option. if you are not sure, please check your ceph.conf to see if there is any + # sections named like '[mon.foo]'. don't pass the "--mon-ids" option, if you are + # using DNS SRV for looking up monitors. + ceph-monstore-tool $ms rebuild -- --keyring /path/to/admin.keyring --mon-ids alpha beta gamma # make a backup of the corrupted store.db just in case! repeat for # all monitors. diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index 95b3284eb0f..df097d32759 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -507,7 +507,9 @@ static int update_auth(MonitorDBStore& st, const string& keyring_path) return 0; } -static int update_mkfs(MonitorDBStore& st, const string& monmap_path) +static int update_mkfs(MonitorDBStore& st, + const string& monmap_path, + const vector& mon_ids) { MonMap monmap; if (!monmap_path.empty()) { @@ -528,6 +530,29 @@ static int update_mkfs(MonitorDBStore& st, const string& monmap_path) cerr << "no initial monitors" << std::endl; return -EINVAL; } + vector new_names; + if (!mon_ids.empty()) { + if (mon_ids.size() != monmap.size()) { + cerr << "Please pass the same number of to name the hosts " + << "listed in 'mon_host'. " + << mon_ids.size() << " mon-id(s) specified, " + << "while you have " << monmap.size() << " mon hosts." << std::endl; + return -EINVAL; + } + new_names = mon_ids; + } else { + for (unsigned rank = 0; rank < monmap.size(); rank++) { + string new_name{"a"}; + new_name[0] += rank; + new_names.push_back(std::move(new_name)); + } + } + for (unsigned rank = 0; rank < monmap.size(); rank++) { + auto name = monmap.get_name(rank); + if (name.compare(0, 7, "noname-") == 0) { + monmap.rename(name, new_names[rank]); + } + } } monmap.print(cout); bufferlist bl; @@ -652,13 +677,18 @@ int rebuild_monstore(const char* progname, po::options_description op_desc("Allowed 'rebuild' options"); string keyring_path; string monmap_path; + vector mon_ids; op_desc.add_options() ("keyring", po::value(&keyring_path), "path to the client.admin key") ("monmap", po::value(&monmap_path), - "path to the initial monmap"); + "path to the initial monmap") + ("mon-ids", po::value>(&mon_ids)->multitoken(), + "mon ids, use 'a', 'b', ... if not specified"); + po::positional_options_description pos_desc; + pos_desc.add("mon-ids", -1); po::variables_map op_vm; - int r = parse_cmd_args(&op_desc, nullptr, nullptr, subcmds, &op_vm); + int r = parse_cmd_args(&op_desc, nullptr, &pos_desc, subcmds, &op_vm); if (r) { return -r; } @@ -677,7 +707,7 @@ int rebuild_monstore(const char* progname, if ((r = update_paxos(st))) { return r; } - if ((r = update_mkfs(st, monmap_path))) { + if ((r = update_mkfs(st, monmap_path, mon_ids))) { return r; } if ((r = update_monitor(st))) { -- 2.39.5