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

Direct retries to another mongos if one is available #1367

Merged
merged 23 commits into from
May 28, 2024

Conversation

stIncMale
Copy link
Member

@stIncMale stIncMale commented Apr 17, 2024

Given that the current specification wording is internally inconsistent, I confirmed the actual intent with the spec author and created DRIVERS-2901 Clarify the intent behind the list of deprioritized mongos'es and fix the pseudocode.

Performance considerations

Our ServerSelector and ClusterDescription API do not allow us to implement an efficient pipeline (CompositeServerSelector) of ServerSelectors: we can neither mutate the List<ServerDescription> in place, nor mutate ClusterDescription, nor even reuse the same ClusterDescription if a selector did not filter anything out. This PR added one more selector required by the specification logic, and introduced two more selectors by refactoring server selection code that wasn't expressed in terms of ServerSelectors. As a result, it is conceivable that the PR has negative performance impact.

Additionally, due to this refactoring d25010d, each server selection iteration now involves copying the map of Servers maintained by a Cluster. While that copying does not entail locking (all hail the CHM!), it may still have additional negative performance impact.

If we indeed notice performance degradation, we may try mitigating the issue by introducing InternalServerSelector extends ServerSelector (or a subclass of ClusterDescription that allows mutating getServerDescriptions, or both), which allows for a more optimal chaining, and use it for everything but the application-specific selector. This is assuming, of course, that the would be degradation is caused to a large extent by the inefficient selector chaining, and not by the CHM copying.

JAVA-4254, JAVA-5320

Implemented the change and unit tests

JAVA-4254, JAVA-5320
@stIncMale stIncMale self-assigned this Apr 17, 2024
@stIncMale stIncMale requested review from katcharov, a team and vbabanin and removed request for a team April 17, 2024 01:19
@stIncMale stIncMale requested a review from vbabanin April 30, 2024 05:59
…Context.java


Let's put various checks (validation, preconditions...) at the top of methods, with the operation at the bottom.

Co-authored-by: Maxim Katcharov <maxim.katcharov@mongodb.com>
Copy link
Member

@vbabanin vbabanin left a comment

Choose a reason for hiding this comment

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

LGTM!

@stIncMale stIncMale requested a review from katcharov May 8, 2024 23:43
Copy link
Member

@vbabanin vbabanin left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@katcharov katcharov left a comment

Choose a reason for hiding this comment

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

LGTM, just one optional suggestion

@stIncMale stIncMale merged commit 2412cbd into mongodb:master May 28, 2024
59 checks passed
@stIncMale stIncMale deleted the JAVA-4254 branch May 28, 2024 19:17
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