diff options
author | Shaileja Jain <shaileja.jain@gmail.com> | 2019-06-13 11:22:10 -0400 |
---|---|---|
committer | Shaileja Jain <shaileja.jain@gmail.com> | 2019-06-26 15:52:11 -0400 |
commit | dac50f778efc784c316b79d1d936865f8cca59fe (patch) | |
tree | 860455c08f51d8d89f3666d1e11401fdde6bb36d /src/mongo/client/replica_set_monitor.cpp | |
parent | 7a02a2f84da35e671736427fea01a7b08a3b8f3f (diff) | |
download | mongo-dac50f778efc784c316b79d1d936865f8cca59fe.tar.gz |
SERVER-40490 RSM should check replicas at most twice per second
Diffstat (limited to 'src/mongo/client/replica_set_monitor.cpp')
-rw-r--r-- | src/mongo/client/replica_set_monitor.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/mongo/client/replica_set_monitor.cpp b/src/mongo/client/replica_set_monitor.cpp index d134f935070..58640f16596 100644 --- a/src/mongo/client/replica_set_monitor.cpp +++ b/src/mongo/client/replica_set_monitor.cpp @@ -511,7 +511,25 @@ void Refresher::scheduleNetworkRequests(WithLock withLock) { if (ns.step != Refresher::NextStep::CONTACT_HOST) break; - scheduleIsMaster(ns.host, withLock); + // cancel any scheduled isMaster calls that haven't yet been called + Node* node = _set->findOrCreateNode(ns.host); + if (node->scheduledIsMasterHandle) { + _set->executor->cancel(node->scheduledIsMasterHandle); + } + + // ensure that the call to isMaster is scheduled at most every 500ms + if (_set->executor && (_set->executor->now() < node->nextPossibleIsMasterCall) && + !_set->isMocked) { + // schedule a new call + node->scheduledIsMasterHandle = uassertStatusOK(_set->executor->scheduleWorkAt( + node->nextPossibleIsMasterCall, + [ *this, host = ns.host ](const CallbackArgs& cbArgs) mutable { + stdx::lock_guard lk(_set->mutex); + scheduleIsMaster(host, lk); + })); + } else { + scheduleIsMaster(ns.host, withLock); + } } DEV _set->checkInvariants(); @@ -544,7 +562,6 @@ void Refresher::scheduleIsMaster(const HostAndPort& host, WithLock withLock) { nullptr, Milliseconds(int64_t(socketTimeoutSecs * 1000))); request.sslMode = _set->setUri.getSSLMode(); - auto status = _set->executor ->scheduleRemoteCommand( @@ -671,6 +688,14 @@ void Refresher::receivedIsMaster(const HostAndPort& from, return; } + // ensure that isMaster calls occur at most 500ms after the previous call ended + if (_set->executor) { + Node* node = _set->findNode(from); + if (node) { + node->nextPossibleIsMasterCall = _set->executor->now() + Milliseconds(500); + } + } + if (reply.setName != _set->name) { if (reply.raw["isreplicaset"].trueValue()) { // The reply came from a node in the state referred to as RSGhost in the SDAM |