Skip to content

ClusterSettings does not compute ClusterConnectionMode consistently #1163

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

Closed
wants to merge 1 commit into from

Conversation

stIncMale
Copy link
Member

@stIncMale stIncMale requested a review from jyemin July 28, 2023 22:36
@stIncMale stIncMale self-assigned this Jul 28, 2023
Copy link
Collaborator

@jyemin jyemin left a comment

Choose a reason for hiding this comment

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

Change looks good, but I recommend that we defer it to 5.0 since it could cause upgrade issues. Though it's a bug, it's similar to the issue regarding changing the default value of directionConnection, which I'm recommending that we not even do in a major release.

@@ -629,9 +630,14 @@ private ClusterSettings(final Builder builder) {
if (builder.mode == ClusterConnectionMode.SINGLE && builder.hosts.size() > 1) {
throw new IllegalArgumentException("Can not directly connect to more than one server");
}
mode = builder.mode != null ? builder.mode : hosts.size() == 1 ? ClusterConnectionMode.SINGLE : ClusterConnectionMode.MULTIPLE;
if (builder.mode != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this conditional is removed, the only test that fails is when connection string is applied to builder, all properties should be set. It seems like there should be a more direct test which covers the scenario where there is no connection string applied at all.

@@ -288,15 +288,16 @@ class ClusterSettingsSpecification extends Specification {
settings.hosts == [new ServerAddress('example.com:27018')]
}

def 'when cluster type is unknown and replica set name is specified, should set cluster type to ReplicaSet'() {
def 'when cluster type is UNKNOWN and replica set name is set, should set cluster type to REPLICA_SET and mode to MULTIPLE'() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider adding more tests which combine connection string application with explicit use of the builder properties (both before and after connection string application), e.g.

ClusterSettings.builder()
.applyConnectionString(new ConnectionString("mongodb://127.0.0.1:27017/"))
.requiredReplicaSetName("replset")
.build()
.getMode()

and

ClusterSettings.builder()
.requiredReplicaSetName("replset")
.applyConnectionString(new ConnectionString("mongodb://127.0.0.1:27017/"))
.build()
.getMode()

@stIncMale stIncMale closed this Jul 31, 2023
@stIncMale
Copy link
Member Author

Closed the PR, because the ticket was retargeted to 5.0.

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

Successfully merging this pull request may close these issues.

2 participants