-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: directConnection adds unify behavior for replica set discovery #2349
Conversation
Adds `directConnection` option to unify behavior around configuration for replica set discovery. Migrated mongodb/specifications tests from commit "e56f5eceed7729f8b9b43a4a1f76c7e5840db49f". Skips SDAM tests for legacy topology / behavior that we do not intend to introduce to the legacy topology types. Users should switch to the unified topology. NODE-2452
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Completed manual review]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec changes
lib/sdam/topology_description.js
Outdated
if (serverType === ServerType.RSGhost || serverType === ServerType.Unknown) { | ||
return TopologyType.Unknown; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think switches are cleaner for this sort of thing.
switch (serverType) {
case ServerType.Standalone:
return TopologyType.single;
case ServerType.Mongos:
return TopologyType.Sharded;
case ServerType.RSPrimary:
return TopologyType.ReplicaSetWithPrimary;
default:
return TopologyType.Unknown;
}
Or if we want to keep it exactly the same (void return for unrecognized serverType
), replace default:
with
case ServerType.RSGhost:
case ServerType.Unknown:
return TopologyType.Unknown;
Thoughts?
f381018
to
0a50a18
Compare
return TopologyType.Unknown; | ||
default: | ||
case ServerType.RSOther: | ||
case ServerType.RSSecondary: | ||
return TopologyType.ReplicaSetNoPrimary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't make sense to me to have the "default" be ReplicaSetNoPrimary
so I swapped this, initial spec tests showed this worked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't find that using a switch
here improves readability at all 🤷♂️ Maybe adding some line breaks in there would be useful, I just find it hard to visually track
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally don't prefer switch syntax, but i think @emadum's recommendation makes sense here it does help restrict what this function can do. It makes it more obvious that this function takes a ServerType
and returns a TopologyType
and no other logic is really allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default Unknown
works for me, I'm fine to resolve this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question but LGTM 👍
lib/connection_string.js
Outdated
@@ -37,6 +37,10 @@ function matchesParentDomain(srvAddress, parentDomain) { | |||
function parseSrvConnectionString(uri, options, callback) { | |||
const result = URL.parse(uri, true); | |||
|
|||
if (options.directConnection || options.directconnection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to have both forms here? I was hoping we wouldn't be introducing more cases where we had to check the upper and lowercase version of URI options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so case translation comes into play in applyConnectionStringOption which is in turn called by parseQueryString. Your change here moves the call to parseSrvConnectionString
to after parseQueryString
is called, which means that we should be in a world where all known values are camelCased.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reggi I think we're waiting on you here
lib/mongo_client.js
Outdated
@@ -143,6 +143,7 @@ const { connect, validOptions } = require('./operations/connect'); | |||
* @param {boolean} [options.useNewUrlParser=true] Determines whether or not to use the new url parser. Enables the new, spec-compliant, url parser shipped in the core driver. This url parser fixes a number of problems with the original parser, and aims to outright replace that parser in the near future. Defaults to true, and must be explicitly set to false to use the legacy url parser. | |||
* @param {DriverInfoOptions} [options.driverInfo] Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver | |||
* @param {AutoEncrypter~AutoEncryptionOptions} [options.autoEncryption] Optionally enable client side auto encryption | |||
* @param {boolean} [options.directConnection=false] Enable directConnection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we improve this doc string? "Indicates that a client should directly connect to a node without attempting to discover its topology type" or something like that
lib/mongo_client.js
Outdated
@@ -388,6 +389,7 @@ MongoClient.prototype.isConnected = function(options) { | |||
* @param {number} [options.numberOfRetries=5] The number of retries for a tailable cursor | |||
* @param {boolean} [options.auto_reconnect=true] Enable auto reconnecting for single server instances | |||
* @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections | |||
* @param {boolean} [options.directConnection=false] Enable directConnection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
lib/sdam/topology.js
Outdated
@@ -101,6 +101,10 @@ class Topology extends EventEmitter { | |||
* @param {number} [options.localThresholdMS=15] The size of the latency window for selecting among multiple suitable servers | |||
* @param {number} [options.serverSelectionTimeoutMS=30000] How long to block for server selection before throwing an error | |||
* @param {number} [options.heartbeatFrequencyMS=10000] The frequency with which topology updates are scheduled | |||
* @param {boolean} [options.directConnection] will set topology to Single | |||
* @param {string} [options.replicaSet] will set topology to ReplicaSetNoPrimary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replicaSet
should be the only supported option, setName
and rs_name
can and should be removed in this major revision. Also I think the docstrings for all of these are a bit wanting, directConnection
means "connect directly to the node without discovering its type" and "replicaSet" is the name of the replica set to connect to (used for validation during initial handshake as well). You can find decent descriptions of these in the URI Options spec
return TopologyType.Unknown; | ||
default: | ||
case ServerType.RSOther: | ||
case ServerType.RSSecondary: | ||
return TopologyType.ReplicaSetNoPrimary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't find that using a switch
here improves readability at all 🤷♂️ Maybe adding some line breaks in there would be useful, I just find it hard to visually track
665942d
to
c1ee288
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Adds
directConnection
option to unify behavior around configuration for replica set discovery. Migrated mongodb/specifications tests from commit "e56f5eceed7729f8b9b43a4a1f76c7e5840db49f". Skips SDAM tests for legacy topology / behavior that we do not intend to introduce to the legacy topology types. Users should switch to the unified topology.NODE-2452