Fix bugs turned up by _GLIBCXX_DEBUG

Compiling with -D_GLIBCXX_DEBUG enables libstc++ "debug mode", where
additional debug information is tracked with iterators and reported if
iterators are misused. This turned up two bugs.

I threw in removing dead code and avoiding an unnecessary map lookup
while I was in the neighborhood.
This commit is contained in:
Andrew Noyes 2021-02-04 02:37:51 +00:00
parent ca4adb7d93
commit cb196daefe
2 changed files with 7 additions and 6 deletions

View File

@ -29,10 +29,12 @@ void HealthMonitor::reportPeerClosed(const NetworkAddress& peerAddress) {
} }
void HealthMonitor::purgeOutdatedHistory() { void HealthMonitor::purgeOutdatedHistory() {
for (auto it : peerClosedHistory) { for (auto it = peerClosedHistory.begin(); it != peerClosedHistory.end();) {
if (it.first < now() - FLOW_KNOBS->HEALTH_MONITOR_CLIENT_REQUEST_INTERVAL_SECS) { if (it->first < now() - FLOW_KNOBS->HEALTH_MONITOR_CLIENT_REQUEST_INTERVAL_SECS) {
peerClosedNum[it.second] -= 1; auto& count = peerClosedNum[it->second];
ASSERT(peerClosedNum[it.second] >= 0); --count;
ASSERT(count >= 0);
++it; // Increment before pop_front to avoid iterator invalidation
peerClosedHistory.pop_front(); peerClosedHistory.pop_front();
} else { } else {
break; break;

View File

@ -240,7 +240,6 @@ ACTOR Future<vector<vector<UID>>> additionalSources(Standalone<RangeResultRef> s
std::map<UID, StorageServerInterface> ssiMap; std::map<UID, StorageServerInterface> ssiMap;
for(int s=0; s<serverListValues.size(); s++) { for(int s=0; s<serverListValues.size(); s++) {
auto si = decodeServerListValue(serverListValues[s].get());
StorageServerInterface ssi = decodeServerListValue(serverListValues[s].get()); StorageServerInterface ssi = decodeServerListValue(serverListValues[s].get());
ssiMap[ssi.id()] = ssi; ssiMap[ssi.id()] = ssi;
} }
@ -260,7 +259,7 @@ ACTOR Future<vector<vector<UID>>> additionalSources(Standalone<RangeResultRef> s
} }
for(int s=0; s<dest.size(); s++) { for(int s=0; s<dest.size(); s++) {
if( std::find(src.begin(), src.end(), dest[s]) == dest.end() ) { if (std::find(src.begin(), src.end(), dest[s]) == src.end()) {
destInterfs.push_back( ssiMap[dest[s]] ); destInterfs.push_back( ssiMap[dest[s]] );
} }
} }