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() { }
};
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<int, failure_reporter_t>::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<MonOpRequestRef>& ls) {
}
}
- 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;
}
};