Skip to content

Commit

Permalink
refactor(topology): remove extra timers around selection monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Nov 22, 2019
1 parent 391baf3 commit 2911d0c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
19 changes: 5 additions & 14 deletions lib/core/sdam/server_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const MongoTimeoutError = require('../error').MongoTimeoutError;

const common = require('./common');
const STATE_CLOSED = common.STATE_CLOSED;
const TOPOLOGY_DEFAULTS = common.TOPOLOGY_DEFAULTS;
const drainTimerQueue = common.drainTimerQueue;
const clearAndRemoveTimerFrom = common.clearAndRemoveTimerFrom;

// max staleness constants
Expand Down Expand Up @@ -183,7 +181,8 @@ function readPreferenceServerSelector(readPreference) {
const commonWireVersion = topologyDescription.commonWireVersion;
if (
commonWireVersion &&
(readPreference.minWireVersion && readPreference.minWireVersion > commonWireVersion)
readPreference.minWireVersion &&
readPreference.minWireVersion > commonWireVersion
) {
throw new MongoError(
`Minimum wire version '${
Expand Down Expand Up @@ -298,18 +297,10 @@ function selectServers(topology, selector, timeout, start, callback) {
}

const retrySelection = () => {
// clear all existing monitor timers
drainTimerQueue(topology.s.monitorTimers);

// ensure all server monitors attempt monitoring soon
topology.s.servers.forEach(server => {
const timer = setTimeout(
() => server.monitor({ heartbeatFrequencyMS: topology.description.heartbeatFrequencyMS }),
TOPOLOGY_DEFAULTS.minHeartbeatFrequencyMS
);

topology.s.monitorTimers.add(timer);
});
topology.s.servers.forEach(server =>
server.monitor({ heartbeatFrequencyMS: topology.description.heartbeatFrequencyMS })
);

const iterationTimer = setTimeout(() => {
topology.removeListener('topologyDescriptionChanged', descriptionChangedHandler);
Expand Down
2 changes: 0 additions & 2 deletions lib/core/sdam/topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ class Topology extends EventEmitter {
clusterTime: null,

// timer management
monitorTimers: new Set(),
iterationTimers: new Set(),
connectionTimers: new Set()
};
Expand Down Expand Up @@ -334,7 +333,6 @@ class Topology extends EventEmitter {
}

// clear all existing monitor timers
drainTimerQueue(this.s.monitorTimers);
drainTimerQueue(this.s.iterationTimers);
drainTimerQueue(this.s.connectionTimers);

Expand Down

0 comments on commit 2911d0c

Please sign in to comment.