Skip to content

ClusterSettings does not compute ClusterConnectionMode consistently #1261

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 31 commits into from

Conversation

stIncMale
Copy link
Member

@stIncMale stIncMale commented Nov 16, 2023

This PR addresses test concerns expressed in the original PR #1163. New tests discovered more issues, so more changes were done in ClusterSettings.

JAVA-5088

jyemin added 29 commits October 10, 2023 16:06
  MongoClientSettings#getStreamFactoryFactory()
  MongoClientSettings.Builder#streamFactoryFactory(StreamFactoryFactory)
  AsynchronousSocketChannelStreamFactory
  AsynchronousSocketChannelStreamFactoryFactory
  BufferProvider
  SocketStreamFactory
  Stream
  StreamFactory
  StreamFactoryFactory
  TlsChannelStreamFactoryFactory
  NettyStreamFactory
  NettyStreamFactoryFactory

JAVA-5161
* Remove builders
* Remove now-unused factory configuration
* Simplify usage in MongoClient instantiation

JAVA-5161
* ServerAddress#getSocketAddress
* ServerAddress#getSocketAddresses
* UnixServerAddress#getSocketAddress
* UnixServerAddress#getUnixSocketAddress

JAVA-4937
Since we ended up adding explain support to FindIterable,
no reason to leave it deprecated in the legacy API.

JAVA-5154
The dead code is a remnant of when the driver supported the
full range of OP_REPLY wire protocol message usage.  Since the driver
now only runs against MongoDB releases that support OP_MSG,
OP_REPLY is only used for the response to the `hello` command
in the handshake, and therefore most of the OP_REPLY-handling code is
no longer on any execution paths.

JAVA-5204
Now that Stream is not part of the API, this method
can be removed.  It only existed due to the possibility
that an application creates its own Stream implementation.

JAVA-5180
* getStats
* isCapped

JAVA-5116
from the following internal interfaces:

* ClusterAwareReadWriteBinding
* AsyncClusterAwareReadWriteBinding

The interfaces remain as they have picket up a second method.

JAVA-5217
Since StreamFactoryFactory is now internal, just made that interface
extend AutoCloseable in order to simplify MongoClients code

JAVA-5158
* ConnectionPoolOpenedEvent
* ConnectionAddedEvent
* ConnectionRemovedEvent
* ConnectionPoolListener#connectionPoolOpened
* ConnectionPoolListener#connectionAdded
* ConnectionPoolListener#connectionRemoved

JAVA-5151
* ClusterListenerAdapter
* ConnectionPoolListenerAdapter
* ServerListenerAdapter
* ServerMonitorListenerAdapter

JAVA-5151
It's still used by IterableCodecProvider, so it can't be removed entirely.
(Though IterableCodecProvider is almost entirely supplanted by CollectionCodecProvider,
it was not itself deprecated because it provides a codec for any Iterable, while
CollectionCodecProvider only provides one for any Collection, which is not quite the
same thing).

JAVA-5142
@stIncMale stIncMale self-assigned this Nov 16, 2023
Comment on lines 340 to 349
} else if (directConnection != null) {
mode(directConnection ? ClusterConnectionMode.SINGLE : ClusterConnectionMode.MULTIPLE);
hosts(singletonList(createServerAddress(connectionString.getHosts().get(0))));
} else {
mode = null;
List<ServerAddress> seedList = connectionString.getHosts().stream()
.map(ServerAddressHelper::createServerAddress)
.collect(Collectors.toList());
mode(ClusterConnectionMode.MULTIPLE).hosts(seedList);
hosts(seedList);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Without this change, the following test fails:

        when:
        settings = ClusterSettings.builder()
                .applyConnectionString(new ConnectionString('mongodb://example.com:27018'))
                .requiredReplicaSetName("test")
                .build()

        then:
        settings.mode == ClusterConnectionMode.MULTIPLE

@stIncMale stIncMale requested review from jyemin and vbabanin November 16, 2023 23:56
@stIncMale stIncMale requested a review from jyemin November 17, 2023 05:18
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.

Even in relatively simple code like this, I don't find it easy to tease apart the refactoring from the behavioral change that fixes the bug, and would probably prefer that it be split into two commits. But I think I understand everything and the tests look good, so LGTM regardless.

.build()

then:
settings.mode == ClusterConnectionMode.MULTIPLE
Copy link
Collaborator

Choose a reason for hiding this comment

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

A note for us in the future: when run against the original code, this assertion fails

when:
def settings = ClusterSettings.builder().hosts([new ServerAddress()]).requiredReplicaSetName('yeah').build()

then:
ClusterType.REPLICA_SET == settings.requiredClusterType
ClusterConnectionMode.MULTIPLE == settings.mode
Copy link
Collaborator

Choose a reason for hiding this comment

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

A note for us in the future: when run against the original code, this assertion fails

if (srvHost != null) {
throw new IllegalArgumentException("An SRV host name was provided but the connection mode is not MULTIPLE");
} else if (builder.hosts.size() > 1) {
throw new IllegalArgumentException("Can not directly connect to more than one server");
Copy link
Member

Choose a reason for hiding this comment

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

[Optional]: I've noticed a slightly different wording in the error description for ConnectionString validation. Specifically, the wording differs: "Direct connections are not supported when using multiple hosts." Given that this change is targeted for the 5.0 release and involves some refactoring, should we ensure consistency in the error descriptions with those in ConnectionString?

@jyemin jyemin force-pushed the 5.x branch 3 times, most recently from c076264 to 7b3312a Compare December 4, 2023 19:45
@jyemin jyemin deleted the branch mongodb:5.x December 5, 2023 16:13
@jyemin jyemin closed this Dec 5, 2023
@stIncMale stIncMale deleted the JAVA-5088_5.x branch December 6, 2023 19:28
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.

3 participants