-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add support for server selection's deprioritized servers to all topologies. #1860
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
Changes from 44 commits
e6083b4
de2856b
689d6cb
a8ddab2
1eddabf
d62a576
777ced9
85cc1aa
893d419
19ab190
05beaf2
0bf110b
46b9b8d
cd5dcf1
dfae55b
bb54d82
3bd9710
1f38bc7
70e1eeb
59b1aa1
41849e7
cb3e7d6
793507a
f4ab841
11cf14a
9017de8
bc0f8da
23332b2
b4fe6f3
7a4dcfd
2e38a65
d1868a3
021e7f5
44a66c1
9f047b7
a1c052a
704d829
3736c17
817a5c5
3373c14
0cb9bf2
ae8d201
446f8ff
2bf6aaa
1f4c0c9
29199e5
4d03cd2
4e69816
40aecc7
a911780
8f1fbbb
0b8a594
6814a58
08c1164
0110bb0
4dc418f
755f43a
dd62a2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,9 @@ | |
| import static com.mongodb.connection.ServerDescription.MIN_DRIVER_SERVER_VERSION; | ||
| import static com.mongodb.connection.ServerDescription.MIN_DRIVER_WIRE_VERSION; | ||
| import static com.mongodb.internal.Locks.withInterruptibleLock; | ||
| import static com.mongodb.internal.VisibleForTesting.AccessModifier.PACKAGE; | ||
| import static com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE; | ||
| import static com.mongodb.internal.VisibleForTesting.AccessModifier.PROTECTED; | ||
| import static com.mongodb.internal.connection.EventHelper.wouldDescriptionsGenerateEquivalentEvents; | ||
| import static com.mongodb.internal.event.EventListenerHelper.singleClusterListener; | ||
| import static com.mongodb.internal.logging.LogMessage.Component.SERVER_SELECTION; | ||
|
|
@@ -94,7 +96,8 @@ | |
| import static java.util.concurrent.TimeUnit.NANOSECONDS; | ||
| import static java.util.stream.Collectors.toList; | ||
|
|
||
| abstract class BaseCluster implements Cluster { | ||
| @VisibleForTesting(otherwise = PROTECTED) | ||
| public abstract class BaseCluster implements Cluster { | ||
|
vbabanin marked this conversation as resolved.
Outdated
|
||
| private static final Logger LOGGER = Loggers.getLogger("cluster"); | ||
| private static final StructuredLogger STRUCTURED_LOGGER = new StructuredLogger("cluster"); | ||
|
|
||
|
|
@@ -112,10 +115,11 @@ abstract class BaseCluster implements Cluster { | |
| private volatile boolean isClosed; | ||
| private volatile ClusterDescription description; | ||
|
|
||
| BaseCluster(final ClusterId clusterId, | ||
| final ClusterSettings settings, | ||
| final ClusterableServerFactory serverFactory, | ||
| final ClientMetadata clientMetadata) { | ||
| @VisibleForTesting(otherwise = PACKAGE) | ||
| protected BaseCluster(final ClusterId clusterId, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in: 08b3466
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question - is this annotation even needed now?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Removed. |
||
| final ClusterSettings settings, | ||
| final ClusterableServerFactory serverFactory, | ||
| final ClientMetadata clientMetadata) { | ||
|
vbabanin marked this conversation as resolved.
|
||
| this.clusterId = notNull("clusterId", clusterId); | ||
| this.settings = notNull("settings", settings); | ||
| this.serverFactory = notNull("serverFactory", serverFactory); | ||
|
|
@@ -159,7 +163,7 @@ public ServerTuple selectServer(final ServerSelector serverSelector, final Opera | |
| if (serverTuple != null) { | ||
| ServerAddress serverAddress = serverTuple.getServerDescription().getAddress(); | ||
| logServerSelectionSucceeded(operationContext, clusterId, serverAddress, serverSelector, currentDescription); | ||
| serverDeprioritization.updateCandidate(serverAddress); | ||
| serverDeprioritization.updateCandidate(serverAddress, currentDescription.getType()); | ||
| return serverTuple; | ||
| } | ||
| computedServerSelectionTimeout.onExpired(() -> | ||
|
|
@@ -302,7 +306,7 @@ private boolean handleServerSelectionRequest( | |
| if (serverTuple != null) { | ||
| ServerAddress serverAddress = serverTuple.getServerDescription().getAddress(); | ||
| logServerSelectionSucceeded(operationContext, clusterId, serverAddress, request.originalSelector, description); | ||
| serverDeprioritization.updateCandidate(serverAddress); | ||
| serverDeprioritization.updateCandidate(serverAddress, description.getType()); | ||
| request.onResult(serverTuple, null); | ||
| return true; | ||
| } | ||
|
|
@@ -361,8 +365,7 @@ private static ServerSelector getCompleteServerSelector( | |
| final ClusterSettings settings) { | ||
| List<ServerSelector> selectors = Stream.of( | ||
| getRaceConditionPreFilteringSelector(serversSnapshot), | ||
| serverSelector, | ||
| serverDeprioritization.getServerSelector(), | ||
| serverDeprioritization.apply(serverSelector), | ||
| settings.getServerSelector(), // may be null | ||
| new LatencyMinimizingServerSelector(settings.getLocalThreshold(MILLISECONDS), MILLISECONDS), | ||
| AtMostTwoRandomServerSelector.instance(), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.