Skip to content

Commit 9a3c9dd

Browse files
committed
Don't gossip cluster time from monitoring connections (#1276)
JAVA-5256
1 parent b155d88 commit 9a3c9dd

File tree

6 files changed

+11
-49
lines changed

6 files changed

+11
-49
lines changed

driver-core/src/main/com/mongodb/internal/connection/CommandHelper.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.mongodb.connection.ClusterConnectionMode;
2323
import com.mongodb.internal.IgnorableRequestContext;
2424
import com.mongodb.internal.async.SingleResultCallback;
25-
import com.mongodb.internal.session.SessionContext;
2625
import com.mongodb.internal.validator.NoOpFieldNameValidator;
2726
import com.mongodb.lang.Nullable;
2827
import org.bson.BsonDocument;
@@ -46,20 +45,14 @@ public final class CommandHelper {
4645

4746
static BsonDocument executeCommand(final String database, final BsonDocument command, final ClusterConnectionMode clusterConnectionMode,
4847
@Nullable final ServerApi serverApi, final InternalConnection internalConnection) {
49-
return sendAndReceive(database, command, null, clusterConnectionMode, serverApi, internalConnection);
50-
}
51-
52-
public static BsonDocument executeCommand(final String database, final BsonDocument command, final ClusterClock clusterClock,
53-
final ClusterConnectionMode clusterConnectionMode, @Nullable final ServerApi serverApi,
54-
final InternalConnection internalConnection) {
55-
return sendAndReceive(database, command, clusterClock, clusterConnectionMode, serverApi, internalConnection);
48+
return sendAndReceive(database, command, clusterConnectionMode, serverApi, internalConnection);
5649
}
5750

5851
static BsonDocument executeCommandWithoutCheckingForFailure(final String database, final BsonDocument command,
5952
final ClusterConnectionMode clusterConnectionMode, @Nullable final ServerApi serverApi,
6053
final InternalConnection internalConnection) {
6154
try {
62-
return sendAndReceive(database, command, null, clusterConnectionMode, serverApi, internalConnection);
55+
return sendAndReceive(database, command, clusterConnectionMode, serverApi, internalConnection);
6356
} catch (MongoServerException e) {
6457
return new BsonDocument();
6558
}
@@ -94,14 +87,11 @@ static boolean isCommandOk(final BsonDocument response) {
9487
}
9588

9689
private static BsonDocument sendAndReceive(final String database, final BsonDocument command,
97-
@Nullable final ClusterClock clusterClock,
9890
final ClusterConnectionMode clusterConnectionMode, @Nullable final ServerApi serverApi,
9991
final InternalConnection internalConnection) {
100-
SessionContext sessionContext = clusterClock == null ? NoOpSessionContext.INSTANCE
101-
: new ClusterClockAdvancingSessionContext(NoOpSessionContext.INSTANCE, clusterClock);
10292
return assertNotNull(internalConnection.sendAndReceive(getCommandMessage(database, command, internalConnection,
103-
clusterConnectionMode, serverApi), new BsonDocumentCodec(), sessionContext, IgnorableRequestContext.INSTANCE,
104-
new OperationContext()));
93+
clusterConnectionMode, serverApi), new BsonDocumentCodec(), NoOpSessionContext.INSTANCE,
94+
IgnorableRequestContext.INSTANCE, new OperationContext()));
10595
}
10696

10797
private static CommandMessage getCommandMessage(final String database, final BsonDocument command,

driver-core/src/main/com/mongodb/internal/connection/DefaultClusterableServerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public ClusterableServer create(final Cluster cluster, final ServerAddress serve
8989
ServerId serverId = new ServerId(cluster.getClusterId(), serverAddress);
9090
ClusterConnectionMode clusterMode = cluster.getSettings().getMode();
9191
SameObjectProvider<SdamServerDescriptionManager> sdamProvider = SameObjectProvider.uninitialized();
92-
ServerMonitor serverMonitor = new DefaultServerMonitor(serverId, serverSettings, cluster.getClock(),
92+
ServerMonitor serverMonitor = new DefaultServerMonitor(serverId, serverSettings,
9393
// no credentials, compressor list, or command listener for the server monitor factory
9494
new InternalStreamConnectionFactory(clusterMode, true, heartbeatStreamFactory, null, applicationName,
9595
mongoDriverInformation, emptyList(), loggerSettings, null, serverApi, inetAddressResolver),

driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class DefaultServerMonitor implements ServerMonitor {
7171

7272
private final ServerId serverId;
7373
private final ServerMonitorListener serverMonitorListener;
74-
private final ClusterClock clusterClock;
7574
private final Provider<SdamServerDescriptionManager> sdamProvider;
7675
private final InternalConnectionFactory internalConnectionFactory;
7776
private final ClusterConnectionMode clusterConnectionMode;
@@ -88,15 +87,13 @@ class DefaultServerMonitor implements ServerMonitor {
8887
private volatile boolean isClosed;
8988

9089
DefaultServerMonitor(final ServerId serverId, final ServerSettings serverSettings,
91-
final ClusterClock clusterClock,
92-
final InternalConnectionFactory internalConnectionFactory,
90+
final InternalConnectionFactory internalConnectionFactory,
9391
final ClusterConnectionMode clusterConnectionMode,
9492
@Nullable final ServerApi serverApi,
9593
final Provider<SdamServerDescriptionManager> sdamProvider) {
9694
this.serverSettings = notNull("serverSettings", serverSettings);
9795
this.serverId = notNull("serverId", serverId);
9896
this.serverMonitorListener = singleServerMonitorListener(serverSettings);
99-
this.clusterClock = notNull("clusterClock", clusterClock);
10097
this.internalConnectionFactory = notNull("internalConnectionFactory", internalConnectionFactory);
10198
this.clusterConnectionMode = notNull("clusterConnectionMode", clusterConnectionMode);
10299
this.serverApi = serverApi;
@@ -206,7 +203,7 @@ private ServerDescription lookupServerDescription(final ServerDescription curren
206203

207204
long start = System.nanoTime();
208205
try {
209-
SessionContext sessionContext = new ClusterClockAdvancingSessionContext(NoOpSessionContext.INSTANCE, clusterClock);
206+
SessionContext sessionContext = NoOpSessionContext.INSTANCE;
210207
if (!connection.hasMoreToCome()) {
211208
BsonDocument helloDocument = new BsonDocument(getHandshakeCommandName(currentServerDescription), new BsonInt32(1))
212209
.append("helloOk", BsonBoolean.TRUE);
@@ -432,7 +429,7 @@ private void pingServer(final InternalConnection connection) {
432429
long start = System.nanoTime();
433430
executeCommand("admin",
434431
new BsonDocument(getHandshakeCommandName(connection.getInitialServerDescription()), new BsonInt32(1)),
435-
clusterClock, clusterConnectionMode, serverApi, connection);
432+
clusterConnectionMode, serverApi, connection);
436433
long elapsedTimeNanos = System.nanoTime() - start;
437434
averageRoundTripTime.addSample(elapsedTimeNanos);
438435
}

driver-core/src/test/functional/com/mongodb/internal/connection/CommandHelperSpecification.groovy

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,13 @@ package com.mongodb.internal.connection
1818

1919
import com.mongodb.LoggerSettings
2020
import com.mongodb.MongoCommandException
21-
import com.mongodb.ServerAddress
2221
import com.mongodb.connection.ClusterConnectionMode
2322
import com.mongodb.connection.ClusterId
24-
import com.mongodb.connection.ConnectionDescription
25-
import com.mongodb.connection.ConnectionId
2623
import com.mongodb.connection.ServerId
27-
import com.mongodb.connection.ServerType
2824
import com.mongodb.connection.SocketSettings
2925
import com.mongodb.connection.netty.NettyStreamFactory
3026
import org.bson.BsonDocument
3127
import org.bson.BsonInt32
32-
import org.bson.BsonTimestamp
3328
import spock.lang.Specification
3429

3530
import java.util.concurrent.CountDownLatch
@@ -40,7 +35,6 @@ import static com.mongodb.ClusterFixture.getCredentialWithCache
4035
import static com.mongodb.ClusterFixture.getPrimary
4136
import static com.mongodb.ClusterFixture.getServerApi
4237
import static com.mongodb.ClusterFixture.getSslSettings
43-
import static com.mongodb.internal.connection.CommandHelper.executeCommand
4438
import static com.mongodb.internal.connection.CommandHelper.executeCommandAsync
4539

4640
class CommandHelperSpecification extends Specification {
@@ -58,24 +52,6 @@ class CommandHelperSpecification extends Specification {
5852
connection?.close()
5953
}
6054

61-
def 'should gossip cluster time'() {
62-
given:
63-
def connection = Mock(InternalStreamConnection) {
64-
getDescription() >> new ConnectionDescription(new ConnectionId(new ServerId(new ClusterId(), new ServerAddress())),
65-
6, ServerType.REPLICA_SET_PRIMARY, 1000, 1000, 1000, [])
66-
}
67-
def clusterClock = new ClusterClock()
68-
clusterClock.advance(new BsonDocument('clusterTime', new BsonTimestamp(42L)))
69-
70-
when:
71-
executeCommand('admin', new BsonDocument(LEGACY_HELLO, new BsonInt32(1)), clusterClock, getClusterConnectionMode(),
72-
getServerApi(), connection)
73-
74-
then:
75-
1 * connection.sendAndReceive(_, _, _ as ClusterClockAdvancingSessionContext, _, _) >> new BsonDocument()
76-
}
77-
78-
7955
def 'should execute command asynchronously'() {
8056
when:
8157
BsonDocument receivedDocument = null

driver-core/src/test/functional/com/mongodb/internal/connection/ServerMonitorSpecification.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ class ServerMonitorSpecification extends OperationFunctionalSpecification {
221221
}
222222
}
223223
serverMonitor = new DefaultServerMonitor(new ServerId(new ClusterId(), address), ServerSettings.builder().build(),
224-
new ClusterClock(),
225224
new InternalStreamConnectionFactory(SINGLE, new SocketStreamFactory(SocketSettings.builder()
226225
.connectTimeout(500, TimeUnit.MILLISECONDS)
227226
.build(),

driver-core/src/test/unit/com/mongodb/internal/connection/DefaultServerMonitorSpecification.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DefaultServerMonitorSpecification extends Specification {
8484
}
8585
}
8686
monitor = new DefaultServerMonitor(new ServerId(new ClusterId(), new ServerAddress()), ServerSettings.builder().build(),
87-
new ClusterClock(), internalConnectionFactory, ClusterConnectionMode.SINGLE, null, SameObjectProvider.initialized(sdam))
87+
internalConnectionFactory, ClusterConnectionMode.SINGLE, null, SameObjectProvider.initialized(sdam))
8888
monitor.start()
8989

9090
when:
@@ -169,7 +169,7 @@ class DefaultServerMonitorSpecification extends Specification {
169169
}
170170
monitor = new DefaultServerMonitor(new ServerId(new ClusterId(), new ServerAddress()),
171171
ServerSettings.builder().heartbeatFrequency(1, TimeUnit.SECONDS).addServerMonitorListener(serverMonitorListener).build(),
172-
new ClusterClock(), internalConnectionFactory, ClusterConnectionMode.SINGLE, null, mockSdamProvider())
172+
internalConnectionFactory, ClusterConnectionMode.SINGLE, null, mockSdamProvider())
173173

174174
when:
175175
monitor.start()
@@ -250,7 +250,7 @@ class DefaultServerMonitorSpecification extends Specification {
250250
}
251251
monitor = new DefaultServerMonitor(new ServerId(new ClusterId(), new ServerAddress()),
252252
ServerSettings.builder().heartbeatFrequency(1, TimeUnit.SECONDS).addServerMonitorListener(serverMonitorListener).build(),
253-
new ClusterClock(), internalConnectionFactory, ClusterConnectionMode.SINGLE, null, mockSdamProvider())
253+
internalConnectionFactory, ClusterConnectionMode.SINGLE, null, mockSdamProvider())
254254

255255
when:
256256
monitor.start()

0 commit comments

Comments
 (0)