From cb1616b7e4cafc228c25b5ce7790c5679911f917 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Fri, 21 Jul 2017 18:35:06 +0800 Subject: [PATCH] mon/HealthMonitor: avoid sending unnecessary MMonHealthChecks to leader If there is no historic warnings and no new warnings is generated, skip sending MMonHealthChecks(for peon) or updating quorum_checks(for leader). Signed-off-by: xie xingguo --- src/mon/HealthMonitor.cc | 27 +++++++++++++++++---------- src/mon/health_check.h | 3 +++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/mon/HealthMonitor.cc b/src/mon/HealthMonitor.cc index 53c79f50a69..a695e01db3e 100644 --- a/src/mon/HealthMonitor.cc +++ b/src/mon/HealthMonitor.cc @@ -278,19 +278,26 @@ bool HealthMonitor::check_member_health() } auto p = quorum_checks.find(mon->rank); - if (p == quorum_checks.end() || - p->second != next) { - if (mon->is_leader()) { - // prepare to propose - quorum_checks[mon->rank] = next; - changed = true; - } else { - // tell the leader - mon->messenger->send_message(new MMonHealthChecks(next), - mon->monmap->get_inst(mon->get_leader())); + if (p == quorum_checks.end()) { + if (next.empty()) { + return false; + } + } else { + if (p->second == next) { + return false; } } + if (mon->is_leader()) { + // prepare to propose + quorum_checks[mon->rank] = next; + changed = true; + } else { + // tell the leader + mon->messenger->send_message(new MMonHealthChecks(next), + mon->monmap->get_inst(mon->get_leader())); + } + return changed; } diff --git a/src/mon/health_check.h b/src/mon/health_check.h index f0c00d176e8..51f0e1095d8 100644 --- a/src/mon/health_check.h +++ b/src/mon/health_check.h @@ -87,6 +87,9 @@ struct health_check_map_t { void clear() { checks.clear(); } + bool empty() const { + return checks.empty(); + } void swap(health_check_map_t& other) { checks.swap(other.checks); } -- 2.39.5