From 3046d17f61d1fa11fe2f35f7cfe9428312a78593 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 2 Apr 2019 16:50:08 -0500 Subject: [PATCH] mon/MonmapMonitor: clean up empty created stamp in monmap Some old clusters have an empty created timestamp. This is mostly harmless, but it is confusing/wrong, and it does currently break the telemetry module with errors like ValueError: time data '0.000000' does not match format '%Y-%m-%d %H:%M:%S.%f' from 'ceph telemetry show'. If we detect an empty created stamp, look at old monmap and use the oldest modified stamp we can find. Fixes: http://tracker.ceph.com/issues/39085 Signed-off-by: Sage Weil --- src/mon/MonmapMonitor.cc | 35 +++++++++++++++++++++++++++++++++++ src/mon/MonmapMonitor.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc index 2497dadd4f7..f15a36185df 100644 --- a/src/mon/MonmapMonitor.cc +++ b/src/mon/MonmapMonitor.cc @@ -928,3 +928,38 @@ void MonmapMonitor::check_sub(Subscription *sub) } } } + +void MonmapMonitor::tick() +{ + if (!is_active() || + !mon->is_leader()) { + return; + } + + if (mon->monmap->created.is_zero()) { + dout(10) << __func__ << " detected empty created stamp" << dendl; + utime_t ctime; + for (version_t v = 1; v <= get_last_committed(); v++) { + bufferlist bl; + int r = get_version(v, bl); + if (r < 0) { + continue; + } + MonMap m; + auto p = bl.cbegin(); + decode(m, p); + if (!m.last_changed.is_zero()) { + dout(10) << __func__ << " first monmap with last_changed is " + << v << " with " << m.last_changed << dendl; + ctime = m.last_changed; + break; + } + } + if (ctime.is_zero()) { + ctime = ceph_clock_now(); + } + dout(10) << __func__ << " updating created stamp to " << ctime << dendl; + pending_map.created = ctime; + propose_pending(); + } +} diff --git a/src/mon/MonmapMonitor.h b/src/mon/MonmapMonitor.h index ced31e8d3e1..fc0bfdbde22 100644 --- a/src/mon/MonmapMonitor.h +++ b/src/mon/MonmapMonitor.h @@ -72,6 +72,8 @@ class MonmapMonitor : public PaxosService { void check_sub(Subscription *sub); + void tick() override; + private: void check_subs(); bufferlist monmap_bl;