From 09216c01be6f57938b1bdb491e45ecfb15a3f6c5 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 11 Mar 2021 17:47:50 +0800 Subject: [PATCH] mon/OSDMonitor: do not return old failure report when updating it there is no need to return stale report, as the caller is not interested in it. Signed-off-by: Kefu Chai --- src/mon/OSDMonitor.h | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index 255902169d9bd..fe179e5db5926 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -53,7 +53,8 @@ struct failure_reporter_t { MonOpRequestRef op; ///< failure op request failure_reporter_t() {} - explicit failure_reporter_t(utime_t s) : failed_since(s) {} + failure_reporter_t(utime_t s, MonOpRequestRef op) + : failed_since(s), op(op) {} ~failure_reporter_t() { } }; @@ -74,20 +75,15 @@ struct failure_info_t { return max_failed_since; } - // set the message for the latest report. return any old op request we had, - // if any, so we can discard it. - MonOpRequestRef add_report(int who, utime_t failed_since, - MonOpRequestRef op) { - auto p = reporters.find(who); - if (p == reporters.end()) { - if (max_failed_since != utime_t() && max_failed_since < failed_since) + // set the message for the latest report. + void add_report(int who, utime_t failed_since, MonOpRequestRef op) { + [[maybe_unused]] auto [it, new_reporter] = + reporters.insert_or_assign(who, failure_reporter_t{failed_since, op}); + if (new_reporter) { + if (max_failed_since != utime_t() && max_failed_since < failed_since) { max_failed_since = failed_since; - p = reporters.insert(std::map::value_type(who, failure_reporter_t(failed_since))).first; + } } - - MonOpRequestRef ret = p->second.op; - p->second.op = op; - return ret; } void take_report_messages(std::list& ls) { @@ -99,14 +95,9 @@ struct failure_info_t { } } - MonOpRequestRef cancel_report(int who) { - auto p = reporters.find(who); - if (p == reporters.end()) - return MonOpRequestRef(); - MonOpRequestRef ret = p->second.op; - reporters.erase(p); + void cancel_report(int who) { + reporters.erase(who); max_failed_since = utime_t(); - return ret; } }; -- 2.39.5