changed failureMonitor to use an unordered_map
This commit is contained in:
parent
e5a80f2c94
commit
f1a4bdd70d
|
@ -22,9 +22,10 @@
|
|||
#include "fdbrpc/FailureMonitor.h"
|
||||
#include "fdbclient/ClusterInterface.h"
|
||||
#include "flow/actorcompiler.h" // has to be last include
|
||||
#include <unordered_set>
|
||||
|
||||
struct FailureMonitorClientState : ReferenceCounted<FailureMonitorClientState> {
|
||||
std::set<NetworkAddress> knownAddrs;
|
||||
std::unordered_set<NetworkAddress> knownAddrs;
|
||||
double serverFailedTimeout;
|
||||
|
||||
FailureMonitorClientState() {
|
||||
|
@ -77,7 +78,7 @@ ACTOR Future<Void> failureMonitorClientLoop(
|
|||
changedAddresses.insert( reply.changes[c].addresses.secondaryAddress.get() );
|
||||
}
|
||||
}
|
||||
for(auto it : fmState->knownAddrs)
|
||||
for(auto& it : fmState->knownAddrs)
|
||||
if (!changedAddresses.count( it ))
|
||||
monitor->setStatus( it, FailureStatus() );
|
||||
fmState->knownAddrs.clear();
|
||||
|
|
|
@ -80,9 +80,9 @@ void SimpleFailureMonitor::setStatus( NetworkAddress const& address, FailureStat
|
|||
endpointKnownFailed.triggerRange( Endpoint({address}, UID()), Endpoint({address}, UID(-1,-1)) );
|
||||
}
|
||||
} else {
|
||||
bool triggerEndpoint = status != it->value;
|
||||
bool triggerEndpoint = status != it->second;
|
||||
if (status != FailureStatus())
|
||||
it->value = status;
|
||||
it->second = status;
|
||||
else
|
||||
addressStatus.erase(it);
|
||||
if(triggerEndpoint)
|
||||
|
@ -104,7 +104,7 @@ void SimpleFailureMonitor::notifyDisconnect( NetworkAddress const& address ) {
|
|||
Future<Void> SimpleFailureMonitor::onDisconnectOrFailure( Endpoint const& endpoint ) {
|
||||
// If the endpoint or address is already failed, return right away
|
||||
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);
|
||||
return Void();
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ FailureStatus SimpleFailureMonitor::getState( Endpoint const& endpoint ) {
|
|||
else {
|
||||
auto a = addressStatus.find(endpoint.getPrimaryAddress());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ bool SimpleFailureMonitor::onlyEndpointFailed( Endpoint const& endpoint ) {
|
|||
return false;
|
||||
auto a = addressStatus.find(endpoint.getPrimaryAddress());
|
||||
if (a == addressStatus.end()) return true;
|
||||
else return !a->value.failed;
|
||||
else return !a->second.failed;
|
||||
}
|
||||
|
||||
bool SimpleFailureMonitor::permanentlyFailed( Endpoint const& endpoint ) {
|
||||
|
@ -151,6 +151,6 @@ bool SimpleFailureMonitor::permanentlyFailed( Endpoint const& endpoint ) {
|
|||
}
|
||||
|
||||
void SimpleFailureMonitor::reset() {
|
||||
addressStatus = Map< NetworkAddress, FailureStatus >();
|
||||
addressStatus = std::unordered_map< NetworkAddress, FailureStatus >();
|
||||
endpointKnownFailed.resetNoWaiting();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "flow/flow.h"
|
||||
#include "flow/IndexedSet.h"
|
||||
#include "fdbrpc/FlowTransport.h" // Endpoint
|
||||
#include <unordered_map>
|
||||
|
||||
using std::vector;
|
||||
|
||||
|
@ -135,7 +136,7 @@ public:
|
|||
|
||||
void reset();
|
||||
private:
|
||||
Map< NetworkAddress, FailureStatus > addressStatus;
|
||||
std::unordered_map< NetworkAddress, FailureStatus > addressStatus;
|
||||
YieldedAsyncMap< Endpoint, bool > endpointKnownFailed;
|
||||
|
||||
friend class OnStateChangedActorActor;
|
||||
|
|
Loading…
Reference in New Issue