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(NODE-3467): implement srvMaxHosts, srvServiceName options #3031

Merged
merged 30 commits into from Nov 16, 2021

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Nov 8, 2021

Description

What is changing?

A new option srvMaxHosts is now implemented that enables a user to limit the number of mongoses the driver will connect to. The driver will select from the list of hosts returned by a DNS lookup at random using the Fisher-Yates algorithm.

The srvServiceName allows the srv address prefix to be changed from the default of mongodb

Is there new documentation needed for these changes?

There is new TSDoc, I don't think further documentation will be needed.

What is the motivation for this change?

The number of mongos hosts can be large and each gets its own connection pool, it allows for tuning of how many query routers a driver connects to, primarily in order to manage networking resources.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: <type>(NODE-xxxx)<!>: <description>
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@dariakp dariakp self-requested a review November 9, 2021 15:13
@dariakp dariakp added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Nov 9, 2021
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

Some feedback just on the helpers

test/unit/utils.test.js Outdated Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
test/unit/utils.test.js Outdated Show resolved Hide resolved
test/unit/utils.test.js Outdated Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
test/unit/utils.test.js Outdated Show resolved Hide resolved
test/unit/utils.test.js Outdated Show resolved Hide resolved
test/unit/utils.test.js Outdated Show resolved Hide resolved
src/sdam/srv_polling.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

More feedback on just the shuffle portion

test/unit/utils.test.js Outdated Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
test/unit/utils.test.js Outdated Show resolved Hide resolved
test/unit/utils.test.js Show resolved Hide resolved
test/unit/utils.test.js Outdated Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

just some wording clean up on the shuffle

test/unit/utils.test.js Outdated Show resolved Hide resolved
test/unit/utils.test.js Outdated Show resolved Hide resolved
test/unit/utils.test.js Outdated Show resolved Hide resolved
test/unit/utils.test.js Outdated Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

Just capturing some thoughts before I move on to looking at more of this

src/mongo_client.ts Outdated Show resolved Hide resolved
src/mongo_client.ts Outdated Show resolved Hide resolved
src/connection_string.ts Show resolved Hide resolved
src/connection_string.ts Outdated Show resolved Hide resolved
src/sdam/srv_polling.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

Thoughts on srvMaxHosts specifically

src/connection_string.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

More notes

src/sdam/topology_description.ts Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

Still have tests to review, but here's more feedback

test/unit/utils.test.js Outdated Show resolved Hide resolved
src/connection_string.ts Outdated Show resolved Hide resolved
src/connection_string.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

Some feedback on just the code, maybe hopefully the last round, still need to look at the tests

src/utils.ts Outdated Show resolved Hide resolved
src/connection_string.ts Outdated Show resolved Hide resolved
src/connection_string.ts Outdated Show resolved Hide resolved
src/connection_string.ts Outdated Show resolved Hide resolved
src/connection_string.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

URI spec test portion comments

test/unit/mongo_client.test.js Show resolved Hide resolved
test/functional/uri_options_spec.test.js Outdated Show resolved Hide resolved
test/functional/uri_options_spec.test.js Outdated Show resolved Hide resolved
// TODO(): srvMaxHost limiting happens in the callback given to resolveSRVRecord inside the driver
// How can we test this in unit test?

// if (options.srvHost && comment.includes('srvMaxHosts')) {
Copy link
Member

Choose a reason for hiding this comment

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

Just a note but it's potentially one way to add a check... Could be that we test that the list of hosts after the randomisation is equal to the list of server description host names in the created topology? Just thinking aloud.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved these tests to initial_dns_seedlist_discovery.spec.test.ts to go along with our nice naming convention but also skipped them due to needing more concrete assertions around the error cases. And it is tracked here: NODE-3757

@nbbeeken
Copy link
Contributor Author

@dariakp I went through and made sure I addresses all your current comments.
@durran I've rewritten the commented out testing in connection_string.test.js, its close to working, I just need to do so much manual address lookups in the tests to make sure we get the same results expected by the tests. So everything expected is there, we just have slightly different shaped data.

Comment on lines 296 to 299
const selectedHosts =
options.srvMaxHosts === 0 || options.srvMaxHosts >= seedlist.length
? seedlist
: shuffle(seedlist, options.srvMaxHosts);
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 moved the initial shuffling to here, in order to unit test since the callback to resolveSRVRecord is inaccessible to the tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

seems like that works too

Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

Some comments while I look at the tests

src/utils.ts Outdated Show resolved Hide resolved
test/unit/mongo_client.test.js Outdated Show resolved Hide resolved
test/unit/mongo_client.test.js Show resolved Hide resolved
test/unit/mongo_client.test.js Outdated Show resolved Hide resolved
test/unit/mongo_client.test.js Show resolved Hide resolved
src/operations/connect.ts Outdated Show resolved Hide resolved
Co-authored-by: Daria Pardue <daria.pardue@mongodb.com>
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

Just to summarize what we discussed - we want to pull in the spec changes associated with test 13, which involve NODE-3450 along with the changes that would have been done in NODE-3680; we also want to make the mock tests more closely resemble the prose tests as written, and we want to break out the seed discovery tests into their own file and see if they can run as integration tests.

@dariakp dariakp added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Nov 16, 2021
@dariakp dariakp marked this pull request as ready for review November 16, 2021 14:59
@nbbeeken nbbeeken requested a review from durran November 16, 2021 17:01
Copy link
Member

@durran durran left a comment

Choose a reason for hiding this comment

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

LGTM and fine with implementing NODE-3757 later.

@dariakp dariakp merged commit 1f8b539 into main Nov 16, 2021
@dariakp dariakp deleted the NODE-3467/limit-mongos branch November 16, 2021 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
3 participants