From 2e112333397750a1b683c41f58c3fae05321fc49 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 17 Jan 2013 21:38:49 -0800 Subject: [PATCH] mon: enforce unique name in mdsmap Add 'mds enforce unique name' option, defaulting to true. If set, when an MDS boots, it will kick any previous mds with the same name from the mdsmap. This is possibly less confusing for users. If an mds daemon restarts, it will immediately replace its previous instantiation. Two misconfigured daemons running with the same name will fight over the same role. Fixes: #3857 Signed-off-by: Sage Weil --- src/common/config_opts.h | 1 + src/mds/MDSMap.h | 10 ++++++++++ src/mon/MDSMonitor.cc | 10 +++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index a5df112576f..c611041f591 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -213,6 +213,7 @@ OPTION(mds_dir_max_commit_size, OPT_INT, 90) // MB OPTION(mds_decay_halflife, OPT_FLOAT, 5) OPTION(mds_beacon_interval, OPT_FLOAT, 4) OPTION(mds_beacon_grace, OPT_FLOAT, 15) +OPTION(mds_enforce_unique_name, OPT_BOOL, true) OPTION(mds_blacklist_interval, OPT_FLOAT, 24.0*60.0) // how long to blacklist failed nodes OPTION(mds_session_timeout, OPT_FLOAT, 60) // cap bits and leases time out if client idle OPTION(mds_session_autoclose, OPT_FLOAT, 300) // autoclose idle session diff --git a/src/mds/MDSMap.h b/src/mds/MDSMap.h index 3a83ed88b08..1314156f2d3 100644 --- a/src/mds/MDSMap.h +++ b/src/mds/MDSMap.h @@ -256,6 +256,16 @@ public: assert(up.count(m) && mds_info.count(up[m])); return mds_info[up[m]]; } + uint64_t find_mds_gid_by_name(const string& s) { + for (map::const_iterator p = mds_info.begin(); + p != mds_info.end(); + ++p) { + if (p->second.name == s) { + return p->first; + } + } + return 0; + } // counts unsigned get_num_in_mds() { diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index 74bf8b1cb8c..7585e42c5ea 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -354,6 +354,13 @@ bool MDSMonitor::prepare_beacon(MMDSBeacon *m) // boot? if (state == MDSMap::STATE_BOOT) { + // zap previous instance of this name? + if (g_conf->mds_enforce_unique_name) { + while (uint64_t existing = pending_mdsmap.find_mds_gid_by_name(m->get_name())) { + fail_mds_gid(existing); + } + } + // add MDSMap::mds_info_t& info = pending_mdsmap.mds_info[gid]; info.global_id = gid; @@ -376,7 +383,6 @@ bool MDSMonitor::prepare_beacon(MMDSBeacon *m) } } - // initialize the beacon timer last_beacon[gid].stamp = ceph_clock_now(g_ceph_context); last_beacon[gid].seq = seq; @@ -676,6 +682,8 @@ void MDSMonitor::fail_mds_gid(uint64_t gid) { assert(pending_mdsmap.mds_info.count(gid)); MDSMap::mds_info_t& info = pending_mdsmap.mds_info[gid]; + dout(10) << "fail_mds_gid " << gid << " mds." << info.name << " rank " << info.rank << dendl; + utime_t until = ceph_clock_now(g_ceph_context); until += g_conf->mds_blacklist_interval; -- 2.47.3