From 3d38967a24b89c65b22e81a741559c3042becfd2 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Sat, 5 May 2018 20:30:19 -0700 Subject: [PATCH] MDSMonitor: refactor last_beacons to use mono_clock Signed-off-by: Patrick Donnelly (cherry picked from commit 1933bdf37098130342d0debacf4daa0a41011351) --- src/mon/MDSMonitor.cc | 66 ++++++++++++++++++++++--------------------- src/mon/MDSMonitor.h | 8 ++++-- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index 993913d00e465..72ea76058998a 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -303,8 +303,9 @@ void MDSMonitor::_note_beacon(MMDSBeacon *m) version_t seq = m->get_seq(); dout(15) << "_note_beacon " << *m << " noting time" << dendl; - last_beacon[gid].stamp = ceph_clock_now(); - last_beacon[gid].seq = seq; + auto &beacon = last_beacon[gid]; + beacon.stamp = mono_clock::now(); + beacon.seq = seq; } bool MDSMonitor::preprocess_beacon(MonOpRequestRef op) @@ -617,8 +618,9 @@ bool MDSMonitor::prepare_beacon(MonOpRequestRef op) } // initialize the beacon timer - last_beacon[gid].stamp = ceph_clock_now(); - last_beacon[gid].seq = seq; + auto &beacon = last_beacon[gid]; + beacon.stamp = mono_clock::now(); + beacon.seq = seq; // new incompat? if (!pending.compat.writeable(m->get_compat())) { @@ -1821,13 +1823,14 @@ void MDSMonitor::maybe_replace_gid(mds_gid_t gid, const MDSMap::mds_info_t& info // We will only take decisive action (replacing/removing a daemon) // if we have some indicating that some other daemon(s) are successfully // getting beacons through recently. - utime_t latest_beacon; - for (const auto & i : last_beacon) { - latest_beacon = std::max(i.second.stamp, latest_beacon); + mono_time latest_beacon = mono_clock::zero(); + for (const auto &p : last_beacon) { + latest_beacon = std::max(p.second.stamp, latest_beacon); } - const bool may_replace = latest_beacon > - (ceph_clock_now() - - std::max(g_conf->mds_beacon_interval, g_conf->mds_beacon_grace * 0.5)); + mono_time now = mono_clock::now(); + chrono::duration since = now-latest_beacon; + const bool may_replace = since.count() < + std::max(g_conf->mds_beacon_interval, g_conf->mds_beacon_grace * 0.5); // are we in? // and is there a non-laggy standby that can take over for us? @@ -2029,57 +2032,56 @@ void MDSMonitor::tick() do_propose |= maybe_resize_cluster(p.second->fscid); } - const auto now = ceph_clock_now(); - if (last_tick.is_zero()) { + mono_time now = mono_clock::now(); + if (mono_clock::is_zero(last_tick)) { last_tick = now; } + chrono::duration since_last = now-last_tick; - if (now - last_tick > (g_conf->mds_beacon_grace - g_conf->mds_beacon_interval)) { + if (since_last.count() > + (g_conf->mds_beacon_grace - g_conf->mds_beacon_interval)) { // This case handles either local slowness (calls being delayed // for whatever reason) or cluster election slowness (a long gap // between calls while an election happened) dout(4) << __func__ << ": resetting beacon timeouts due to mon delay " "(slow election?) of " << now - last_tick << " seconds" << dendl; - for (auto &i : last_beacon) { - i.second.stamp = now; + for (auto &p : last_beacon) { + p.second.stamp = now; } } last_tick = now; - // check beacon timestamps - utime_t cutoff = now; - cutoff -= g_conf->mds_beacon_grace; - // make sure last_beacon is fully populated for (auto &p : pending.mds_roles) { auto &gid = p.first; - if (last_beacon.count(gid) == 0) { - last_beacon[gid].stamp = now; - last_beacon[gid].seq = 0; - } + last_beacon.emplace(std::piecewise_construct, + std::forward_as_tuple(gid), + std::forward_as_tuple(mono_clock::now(), 0)); } + + // check beacon timestamps bool propose_osdmap = false; bool osdmap_writeable = mon->osdmon()->is_writeable(); - auto p = last_beacon.begin(); - while (p != last_beacon.end()) { - mds_gid_t gid = p->first; - auto beacon_info = p->second; - ++p; + for (auto it = last_beacon.begin(); it != last_beacon.end(); it++) { + mds_gid_t gid = it->first; + auto beacon_info = it->second; + chrono::duration since_last = now-beacon_info.stamp; if (!pending.gid_exists(gid)) { // clean it out - last_beacon.erase(gid); + it = last_beacon.erase(it); continue; } - if (beacon_info.stamp < cutoff) { + + if (since_last.count() >= g_conf->mds_beacon_grace) { auto &info = pending.get_info_gid(gid); dout(1) << "no beacon from mds." << info.rank << "." << info.inc << " (gid: " << gid << " addr: " << info.addr << " state: " << ceph_mds_state_name(info.state) << ")" - << " since " << beacon_info.stamp << dendl; + << " since " << since_last.count() << "s" << dendl; // If the OSDMap is writeable, we can blacklist things, so we can // try failing any laggy MDS daemons. Consider each one for failure. if (osdmap_writeable) { @@ -2131,7 +2133,7 @@ MDSMonitor::MDSMonitor(Monitor *mn, Paxos *p, string service_name) void MDSMonitor::on_restart() { // Clear out the leader-specific state. - last_tick = utime_t(); + last_tick = mono_clock::now(); last_beacon.clear(); } diff --git a/src/mon/MDSMonitor.h b/src/mon/MDSMonitor.h index fb2e6256f0e67..88cc9946c5991 100644 --- a/src/mon/MDSMonitor.h +++ b/src/mon/MDSMonitor.h @@ -100,8 +100,10 @@ class MDSMonitor : public PaxosService, public PaxosFSMap { // beacons struct beacon_info_t { - utime_t stamp; - uint64_t seq; + mono_time stamp = mono_clock::zero(); + uint64_t seq = 0; + beacon_info_t() {} + beacon_info_t(mono_time stamp, uint64_t seq) : stamp(stamp), seq(seq) {} }; map last_beacon; @@ -140,7 +142,7 @@ protected: // When did the mon last call into our tick() method? Used for detecting // when the mon was not updating us for some period (e.g. during slow // election) to reset last_beacon timeouts - utime_t last_tick; + mono_time last_tick = mono_clock::zero(); }; #endif -- 2.39.5