Skip to content
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

Merged
merged 10 commits into from
May 15, 2020

Conversation

reggi
Copy link
Contributor

@reggi reggi commented May 4, 2020

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

Thomas Reggi added 2 commits May 4, 2020 17:51
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
Copy link
Contributor Author

@reggi reggi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Completed manual review]

@reggi reggi requested review from mbroadst and emadum May 5, 2020 16:25
Copy link
Contributor Author

@reggi reggi left a 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/server_selection.js Outdated Show resolved Hide resolved
lib/sdam/server_selection.js Outdated Show resolved Hide resolved
lib/connection_string.js Outdated Show resolved Hide resolved
lib/sdam/server_selection.js Outdated Show resolved Hide resolved
if (serverType === ServerType.RSGhost || serverType === ServerType.Unknown) {
return TopologyType.Unknown;
}

Copy link
Contributor

@emadum emadum May 5, 2020

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?

@reggi reggi force-pushed the NODE-2452/master/directConnection branch from f381018 to 0a50a18 Compare May 7, 2020 00:09
return TopologyType.Unknown;
default:
case ServerType.RSOther:
case ServerType.RSSecondary:
return TopologyType.ReplicaSetNoPrimary;
Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

@reggi reggi requested review from emadum and mbroadst May 7, 2020 18:32
Copy link
Contributor

@emadum emadum left a 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/sdam/topology_description.js Show resolved Hide resolved
@@ -37,6 +37,10 @@ function matchesParentDomain(srvAddress, parentDomain) {
function parseSrvConnectionString(uri, options, callback) {
const result = URL.parse(uri, true);

if (options.directConnection || options.directconnection) {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During testing it came in as both, I think it performs differently when in URL and passed in, this covers all our bases.

Screen Shot 2020-05-11 at 3 52 25 PM

Is there a helper I'm missing? It's also in CASE_TRANSLATION. 😫

Copy link
Member

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.

Copy link
Member

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

@@ -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
Copy link
Member

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

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

@@ -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
Copy link
Member

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;
Copy link
Member

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

test/unit/sdam/spec.test.js Show resolved Hide resolved
lib/sdam/topology_description.js Show resolved Hide resolved
@reggi reggi requested a review from mbroadst May 11, 2020 21:27
@reggi reggi force-pushed the NODE-2452/master/directConnection branch from 665942d to c1ee288 Compare May 13, 2020 22:26
Copy link
Member

@mbroadst mbroadst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants