Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
feat(topology-description): always calculate commonWireVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Feb 25, 2019
1 parent 2590c57 commit 5c630ab
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lib/sdam/topology_description.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TopologyDescription {
setName,
maxSetVersion,
maxElectionId,
commonWireVersion,
options,
error
) {
Expand All @@ -55,6 +56,7 @@ class TopologyDescription {
this.localThresholdMS = options.localThresholdMS || 0;
this.options = options;
this.error = error;
this.commonWireVersion = commonWireVersion || null;

// determine server compatibility
for (const serverDescription of this.servers.values()) {
Expand Down Expand Up @@ -89,19 +91,6 @@ class TopologyDescription {
}, null);
}

/**
* @returns The minimum reported wire version of all known servers
*/
get commonWireVersion() {
return Array.from(this.servers.values())
.filter(server => server.type !== ServerType.Unknown)
.reduce(
(min, server) =>
min == null ? server.maxWireVersion : Math.min(min, server.maxWireVersion),
null
);
}

/**
* Returns a copy of this description updated with a given ServerDescription
*
Expand All @@ -117,11 +106,21 @@ class TopologyDescription {
let setName = this.setName;
let maxSetVersion = this.maxSetVersion;
let maxElectionId = this.maxElectionId;
let commonWireVersion = this.commonWireVersion;
let error = serverDescription.error || null;

const serverType = serverDescription.type;
let serverDescriptions = new Map(this.servers);

// update common wire version
if (serverDescription.maxWireVersion !== 0) {
if (commonWireVersion == null) {
commonWireVersion = serverDescription.maxWireVersion;
} else {
commonWireVersion = Math.min(commonWireVersion, serverDescription.maxWireVersion);
}
}

// update the actual server description
serverDescriptions.set(address, serverDescription);

Expand All @@ -133,6 +132,7 @@ class TopologyDescription {
setName,
maxSetVersion,
maxElectionId,
commonWireVersion,
this.options,
error
);
Expand Down Expand Up @@ -214,6 +214,7 @@ class TopologyDescription {
setName,
maxSetVersion,
maxElectionId,
commonWireVersion,
this.options,
error
);
Expand Down

0 comments on commit 5c630ab

Please sign in to comment.