From 6c3035b912258f7032dee0ee13f0061b7142bb26 Mon Sep 17 00:00:00 2001 From: Michal Jarzabek Date: Mon, 5 Sep 2016 22:56:43 +0100 Subject: [PATCH] osd/OSD.cc: remove repeated searching of map Signed-off-by: Michal Jarzabek --- src/osd/OSD.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 3dc490fea8b..c1f3a54d0d0 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -3988,22 +3988,24 @@ void OSD::handle_osd_ping(MOSDPing *m) case MOSDPing::PING: { if (cct->_conf->osd_debug_drop_ping_probability > 0) { - if (debug_heartbeat_drops_remaining.count(from)) { - if (debug_heartbeat_drops_remaining[from] == 0) { - debug_heartbeat_drops_remaining.erase(from); + auto heartbeat_drop = debug_heartbeat_drops_remaining.find(from); + if (heartbeat_drop != debug_heartbeat_drops_remaining.end()) { + if (heartbeat_drop->second == 0) { + debug_heartbeat_drops_remaining.erase(heartbeat_drop); } else { - debug_heartbeat_drops_remaining[from]--; + --heartbeat_drop->second; dout(5) << "Dropping heartbeat from " << from - << ", " << debug_heartbeat_drops_remaining[from] + << ", " << heartbeat_drop->second << " remaining to drop" << dendl; break; } } else if (cct->_conf->osd_debug_drop_ping_probability > ((((double)(rand()%100))/100.0))) { - debug_heartbeat_drops_remaining[from] = - cct->_conf->osd_debug_drop_ping_duration; + heartbeat_drop = + debug_heartbeat_drops_remaining.insert(std::make_pair(from, + cct->_conf->osd_debug_drop_ping_duration)).first; dout(5) << "Dropping heartbeat from " << from - << ", " << debug_heartbeat_drops_remaining[from] + << ", " << heartbeat_drop->second << " remaining to drop" << dendl; break; } -- 2.39.5