changed failureMonitor to use an unordered_map

This commit is contained in:
Evan Tschannen 2019-03-27 19:17:08 -07:00
parent e5a80f2c94
commit f1a4bdd70d
3 changed files with 11 additions and 9 deletions

View File

@ -22,9 +22,10 @@
#include "fdbrpc/FailureMonitor.h" #include "fdbrpc/FailureMonitor.h"
#include "fdbclient/ClusterInterface.h" #include "fdbclient/ClusterInterface.h"
#include "flow/actorcompiler.h" // has to be last include #include "flow/actorcompiler.h" // has to be last include
#include <unordered_set>
struct FailureMonitorClientState : ReferenceCounted<FailureMonitorClientState> { struct FailureMonitorClientState : ReferenceCounted<FailureMonitorClientState> {
std::set<NetworkAddress> knownAddrs; std::unordered_set<NetworkAddress> knownAddrs;
double serverFailedTimeout; double serverFailedTimeout;
FailureMonitorClientState() { FailureMonitorClientState() {
@ -77,7 +78,7 @@ ACTOR Future<Void> failureMonitorClientLoop(
changedAddresses.insert( reply.changes[c].addresses.secondaryAddress.get() ); changedAddresses.insert( reply.changes[c].addresses.secondaryAddress.get() );
} }
} }
for(auto it : fmState->knownAddrs) for(auto& it : fmState->knownAddrs)
if (!changedAddresses.count( it )) if (!changedAddresses.count( it ))
monitor->setStatus( it, FailureStatus() ); monitor->setStatus( it, FailureStatus() );
fmState->knownAddrs.clear(); fmState->knownAddrs.clear();

View File

@ -80,9 +80,9 @@ void SimpleFailureMonitor::setStatus( NetworkAddress const& address, FailureStat
endpointKnownFailed.triggerRange( Endpoint({address}, UID()), Endpoint({address}, UID(-1,-1)) ); endpointKnownFailed.triggerRange( Endpoint({address}, UID()), Endpoint({address}, UID(-1,-1)) );
} }
} else { } else {
bool triggerEndpoint = status != it->value; bool triggerEndpoint = status != it->second;
if (status != FailureStatus()) if (status != FailureStatus())
it->value = status; it->second = status;
else else
addressStatus.erase(it); addressStatus.erase(it);
if(triggerEndpoint) if(triggerEndpoint)
@ -104,7 +104,7 @@ void SimpleFailureMonitor::notifyDisconnect( NetworkAddress const& address ) {
Future<Void> SimpleFailureMonitor::onDisconnectOrFailure( Endpoint const& endpoint ) { Future<Void> SimpleFailureMonitor::onDisconnectOrFailure( Endpoint const& endpoint ) {
// If the endpoint or address is already failed, return right away // If the endpoint or address is already failed, return right away
auto i = addressStatus.find(endpoint.getPrimaryAddress()); auto i = addressStatus.find(endpoint.getPrimaryAddress());
if (i == addressStatus.end() || i->value.isFailed() || endpointKnownFailed.get(endpoint)) { if (i == addressStatus.end() || i->second.isFailed() || endpointKnownFailed.get(endpoint)) {
TraceEvent("AlreadyDisconnected").detail("Addr", endpoint.getPrimaryAddress()).detail("Tok", endpoint.token); TraceEvent("AlreadyDisconnected").detail("Addr", endpoint.getPrimaryAddress()).detail("Tok", endpoint.token);
return Void(); return Void();
} }
@ -133,7 +133,7 @@ FailureStatus SimpleFailureMonitor::getState( Endpoint const& endpoint ) {
else { else {
auto a = addressStatus.find(endpoint.getPrimaryAddress()); auto a = addressStatus.find(endpoint.getPrimaryAddress());
if (a == addressStatus.end()) return FailureStatus(); if (a == addressStatus.end()) return FailureStatus();
else return a->value; else return a->second;
//printf("%s.getState(%s) = %s %p\n", g_network->getLocalAddress().toString(), endpoint.address.toString(), a.failed ? "FAILED" : "OK", this); //printf("%s.getState(%s) = %s %p\n", g_network->getLocalAddress().toString(), endpoint.address.toString(), a.failed ? "FAILED" : "OK", this);
} }
} }
@ -143,7 +143,7 @@ bool SimpleFailureMonitor::onlyEndpointFailed( Endpoint const& endpoint ) {
return false; return false;
auto a = addressStatus.find(endpoint.getPrimaryAddress()); auto a = addressStatus.find(endpoint.getPrimaryAddress());
if (a == addressStatus.end()) return true; if (a == addressStatus.end()) return true;
else return !a->value.failed; else return !a->second.failed;
} }
bool SimpleFailureMonitor::permanentlyFailed( Endpoint const& endpoint ) { bool SimpleFailureMonitor::permanentlyFailed( Endpoint const& endpoint ) {
@ -151,6 +151,6 @@ bool SimpleFailureMonitor::permanentlyFailed( Endpoint const& endpoint ) {
} }
void SimpleFailureMonitor::reset() { void SimpleFailureMonitor::reset() {
addressStatus = Map< NetworkAddress, FailureStatus >(); addressStatus = std::unordered_map< NetworkAddress, FailureStatus >();
endpointKnownFailed.resetNoWaiting(); endpointKnownFailed.resetNoWaiting();
} }

View File

@ -25,6 +25,7 @@
#include "flow/flow.h" #include "flow/flow.h"
#include "flow/IndexedSet.h" #include "flow/IndexedSet.h"
#include "fdbrpc/FlowTransport.h" // Endpoint #include "fdbrpc/FlowTransport.h" // Endpoint
#include <unordered_map>
using std::vector; using std::vector;
@ -135,7 +136,7 @@ public:
void reset(); void reset();
private: private:
Map< NetworkAddress, FailureStatus > addressStatus; std::unordered_map< NetworkAddress, FailureStatus > addressStatus;
YieldedAsyncMap< Endpoint, bool > endpointKnownFailed; YieldedAsyncMap< Endpoint, bool > endpointKnownFailed;
friend class OnStateChangedActorActor; friend class OnStateChangedActorActor;