Skip to content

Commit 330d3b1

Browse files
authored
Remove support for MongoDB 3.6 (#1375)
* Remove branching code in the driver based on 3.6 version checks * Remove testing of 3.6 * Clean up tests JAVA-5294
1 parent 1816e3c commit 330d3b1

33 files changed

+55
-167
lines changed

.evergreen/.evg.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,10 +1802,6 @@ axes:
18021802
display_name: "4.0"
18031803
variables:
18041804
VERSION: "4.0"
1805-
- id: "3.6"
1806-
display_name: "3.6"
1807-
variables:
1808-
VERSION: "3.6"
18091805
- id: os
18101806
display_name: OS
18111807
values:
@@ -2223,7 +2219,7 @@ buildvariants:
22232219
- name: "test"
22242220

22252221
- matrix_name: "tests-jdk8-unsecure"
2226-
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk8", version: ["3.6", "4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "latest"],
2222+
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk8", version: ["4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "latest"],
22272223
topology: "*", os: "linux" }
22282224
display_name: "${version} ${topology} ${auth} ${ssl} ${jdk} ${os} "
22292225
tags: ["tests-variant"]
@@ -2232,7 +2228,7 @@ buildvariants:
22322228

22332229
- matrix_name: "tests-jdk-secure"
22342230
matrix_spec: { auth: "auth", ssl: "ssl", jdk: [ "jdk8", "jdk17", "jdk21"],
2235-
version: [ "3.6", "4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "latest" ],
2231+
version: ["4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "latest" ],
22362232
topology: "*", os: "linux" }
22372233
display_name: "${version} ${topology} ${auth} ${ssl} ${jdk} ${os} "
22382234
tags: ["tests-variant"]

driver-core/src/main/com/mongodb/connection/ServerDescription.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class ServerDescription {
5858
* The minimum supported driver wire version
5959
* @since 3.8
6060
*/
61-
public static final int MIN_DRIVER_WIRE_VERSION = 6;
61+
public static final int MIN_DRIVER_WIRE_VERSION = 7;
6262
/**
6363
* The maximum supported driver wire version
6464
* @since 3.8

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import static com.mongodb.internal.connection.ReadConcernHelper.getReadConcernDocument;
5050
import static com.mongodb.internal.operation.ServerVersionHelper.FOUR_DOT_TWO_WIRE_VERSION;
5151
import static com.mongodb.internal.operation.ServerVersionHelper.FOUR_DOT_ZERO_WIRE_VERSION;
52-
import static com.mongodb.internal.operation.ServerVersionHelper.THREE_DOT_SIX_WIRE_VERSION;
5352

5453
/**
5554
* A command message that uses OP_MSG or OP_QUERY to send the command.
@@ -270,9 +269,7 @@ private void addServerApiElements(final List<BsonElement> extraElements) {
270269
}
271270

272271
private void checkServerVersionForTransactionSupport() {
273-
int wireVersion = getSettings().getMaxWireVersion();
274-
if (wireVersion < FOUR_DOT_ZERO_WIRE_VERSION
275-
|| (wireVersion < FOUR_DOT_TWO_WIRE_VERSION && getSettings().getServerType() == SHARD_ROUTER)) {
272+
if (getSettings().getMaxWireVersion() < FOUR_DOT_TWO_WIRE_VERSION && getSettings().getServerType() == SHARD_ROUTER) {
276273
throw new MongoClientException("Transactions are not supported by the MongoDB cluster to which this client is connected.");
277274
}
278275
}
@@ -287,12 +284,12 @@ private void addReadConcernDocument(final List<BsonElement> extraElements, final
287284

288285
private static OpCode getOpCode(final MessageSettings settings, final ClusterConnectionMode clusterConnectionMode,
289286
@Nullable final ServerApi serverApi) {
290-
return isServerVersionAtLeastThreeDotSix(settings) || clusterConnectionMode == LOAD_BALANCED || serverApi != null
287+
return isServerVersionKnown(settings) || clusterConnectionMode == LOAD_BALANCED || serverApi != null
291288
? OpCode.OP_MSG
292289
: OpCode.OP_QUERY;
293290
}
294291

295-
private static boolean isServerVersionAtLeastThreeDotSix(final MessageSettings settings) {
296-
return settings.getMaxWireVersion() >= THREE_DOT_SIX_WIRE_VERSION;
292+
private static boolean isServerVersionKnown(final MessageSettings settings) {
293+
return settings.getMaxWireVersion() >= FOUR_DOT_ZERO_WIRE_VERSION;
297294
}
298295
}

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import static com.mongodb.AuthenticationMechanism.SCRAM_SHA_256;
3333
import static com.mongodb.assertions.Assertions.assertNotNull;
3434
import static com.mongodb.assertions.Assertions.isTrueArgument;
35-
import static com.mongodb.internal.operation.ServerVersionHelper.serverIsLessThanVersionFourDotZero;
3635
import static java.lang.String.format;
3736

3837
class DefaultAuthenticator extends Authenticator implements SpeculativeAuthenticator {
@@ -48,29 +47,19 @@ class DefaultAuthenticator extends Authenticator implements SpeculativeAuthentic
4847

4948
@Override
5049
void authenticate(final InternalConnection connection, final ConnectionDescription connectionDescription) {
51-
if (serverIsLessThanVersionFourDotZero(connectionDescription)) {
52-
new ScramShaAuthenticator(getMongoCredentialWithCache().withMechanism(SCRAM_SHA_1), getClusterConnectionMode(), getServerApi())
53-
.authenticate(connection, connectionDescription);
54-
} else {
55-
try {
56-
setDelegate(connectionDescription);
57-
delegate.authenticate(connection, connectionDescription);
58-
} catch (Exception e) {
59-
throw wrapException(e);
60-
}
50+
try {
51+
setDelegate(connectionDescription);
52+
delegate.authenticate(connection, connectionDescription);
53+
} catch (Exception e) {
54+
throw wrapException(e);
6155
}
6256
}
6357

6458
@Override
6559
void authenticateAsync(final InternalConnection connection, final ConnectionDescription connectionDescription,
6660
final SingleResultCallback<Void> callback) {
67-
if (serverIsLessThanVersionFourDotZero(connectionDescription)) {
68-
new ScramShaAuthenticator(getMongoCredentialWithCache().withMechanism(SCRAM_SHA_1), getClusterConnectionMode(), getServerApi())
69-
.authenticateAsync(connection, connectionDescription, callback);
70-
} else {
71-
setDelegate(connectionDescription);
72-
delegate.authenticateAsync(connection, connectionDescription, callback);
73-
}
61+
setDelegate(connectionDescription);
62+
delegate.authenticateAsync(connection, connectionDescription, callback);
7463
}
7564

7665
@Override

driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,18 @@
2525
public final class ServerVersionHelper {
2626

2727
public static final int MIN_WIRE_VERSION = 0;
28-
public static final int THREE_DOT_SIX_WIRE_VERSION = 6;
2928
public static final int FOUR_DOT_ZERO_WIRE_VERSION = 7;
3029
public static final int FOUR_DOT_TWO_WIRE_VERSION = 8;
3130
public static final int FOUR_DOT_FOUR_WIRE_VERSION = 9;
3231
public static final int FIVE_DOT_ZERO_WIRE_VERSION = 12;
3332
public static final int SIX_DOT_ZERO_WIRE_VERSION = 17;
34-
private static final int SEVEN_DOT_ZERO_WIRE_VERSION = 21;
35-
36-
public static boolean serverIsAtLeastVersionFourDotZero(final ConnectionDescription description) {
37-
return description.getMaxWireVersion() >= FOUR_DOT_ZERO_WIRE_VERSION;
38-
}
39-
40-
public static boolean serverIsAtLeastVersionFourDotTwo(final ConnectionDescription description) {
41-
return description.getMaxWireVersion() >= FOUR_DOT_TWO_WIRE_VERSION;
42-
}
33+
public static final int SEVEN_DOT_ZERO_WIRE_VERSION = 21;
34+
public static final int LATEST_WIRE_VERSION = SEVEN_DOT_ZERO_WIRE_VERSION;
4335

4436
public static boolean serverIsAtLeastVersionFourDotFour(final ConnectionDescription description) {
4537
return description.getMaxWireVersion() >= FOUR_DOT_FOUR_WIRE_VERSION;
4638
}
4739

48-
public static boolean serverIsAtLeastVersionFiveDotZero(final ConnectionDescription description) {
49-
return description.getMaxWireVersion() >= FIVE_DOT_ZERO_WIRE_VERSION;
50-
}
51-
52-
public static boolean serverIsLessThanVersionFourDotZero(final ConnectionDescription description) {
53-
return description.getMaxWireVersion() < FOUR_DOT_ZERO_WIRE_VERSION;
54-
}
55-
5640
public static boolean serverIsLessThanVersionFourDotTwo(final ConnectionDescription description) {
5741
return description.getMaxWireVersion() < FOUR_DOT_TWO_WIRE_VERSION;
5842
}

driver-core/src/test/functional/com/mongodb/ClusterFixture.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,8 @@ public static ReadWriteBinding getBinding(final ReadPreference readPreference) {
330330

331331
private static ReadWriteBinding getBinding(final Cluster cluster, final ReadPreference readPreference) {
332332
if (!BINDING_MAP.containsKey(readPreference)) {
333-
ReadWriteBinding binding = new ClusterBinding(cluster, readPreference, ReadConcern.DEFAULT, getServerApi(),
334-
IgnorableRequestContext.INSTANCE);
335-
if (serverVersionAtLeast(3, 6)) {
336-
binding = new SessionBinding(binding);
337-
}
333+
ReadWriteBinding binding = new SessionBinding(new ClusterBinding(cluster, readPreference, ReadConcern.DEFAULT, getServerApi(),
334+
IgnorableRequestContext.INSTANCE));
338335
BINDING_MAP.put(readPreference, binding);
339336
}
340337
return BINDING_MAP.get(readPreference);
@@ -367,11 +364,8 @@ public static AsyncReadWriteBinding getAsyncBinding(final ReadPreference readPre
367364

368365
public static AsyncReadWriteBinding getAsyncBinding(final Cluster cluster, final ReadPreference readPreference) {
369366
if (!ASYNC_BINDING_MAP.containsKey(readPreference)) {
370-
AsyncReadWriteBinding binding = new AsyncClusterBinding(cluster, readPreference, ReadConcern.DEFAULT, getServerApi(),
371-
IgnorableRequestContext.INSTANCE);
372-
if (serverVersionAtLeast(3, 6)) {
373-
binding = new AsyncSessionBinding(binding);
374-
}
367+
AsyncReadWriteBinding binding = new AsyncSessionBinding(new AsyncClusterBinding(cluster, readPreference, ReadConcern.DEFAULT,
368+
getServerApi(), IgnorableRequestContext.INSTANCE));
375369
ASYNC_BINDING_MAP.put(readPreference, binding);
376370
}
377371
return ASYNC_BINDING_MAP.get(readPreference);

driver-core/src/test/functional/com/mongodb/client/CommandMonitoringTestHelper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.Map;
4444
import java.util.concurrent.TimeUnit;
4545

46-
import static com.mongodb.ClusterFixture.serverVersionAtLeast;
4746
import static com.mongodb.client.CrudTestHelper.replaceTypeAssertionWithActual;
4847
import static java.util.Arrays.asList;
4948
import static org.junit.Assert.assertEquals;
@@ -90,11 +89,9 @@ public static List<CommandEvent> getExpectedEvents(final BsonArray expectedEvent
9089
}
9190

9291
// Not clear whether these global fields should be included, but also not clear how to efficiently exclude them
93-
if (serverVersionAtLeast(3, 6)) {
94-
commandDocument.put("$db", new BsonString(actualDatabaseName));
95-
if (operation != null && operation.containsKey("read_preference")) {
96-
commandDocument.put("$readPreference", operation.getDocument("read_preference"));
97-
}
92+
commandDocument.put("$db", new BsonString(actualDatabaseName));
93+
if (operation != null && operation.containsKey("read_preference")) {
94+
commandDocument.put("$readPreference", operation.getDocument("read_preference"));
9895
}
9996
commandEvent = new CommandStartedEvent(null, 1, 1, null, actualDatabaseName, commandName,
10097
commandDocument);

driver-core/src/test/resources/server-discovery-and-monitoring/rs/compatible.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"b:27017"
1717
],
1818
"minWireVersion": 0,
19-
"maxWireVersion": 6
19+
"maxWireVersion": 21
2020
}
2121
],
2222
[

driver-core/src/test/resources/server-discovery-and-monitoring/rs/compatible_unknown.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"b:27017"
1717
],
1818
"minWireVersion": 0,
19-
"maxWireVersion": 6
19+
"maxWireVersion": 21
2020
}
2121
]
2222
],

driver-core/src/test/resources/server-discovery-and-monitoring/sharded/compatible.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"isWritablePrimary": true,
2424
"msg": "isdbgrid",
2525
"minWireVersion": 0,
26-
"maxWireVersion": 6
26+
"maxWireVersion": 21
2727
}
2828
]
2929
],

driver-core/src/test/resources/server-discovery-and-monitoring/single/compatible.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"helloOk": true,
1212
"isWritablePrimary": true,
1313
"minWireVersion": 0,
14-
"maxWireVersion": 6
14+
"maxWireVersion": 21
1515
}
1616
]
1717
],

driver-core/src/test/resources/server-discovery-and-monitoring/single/too_old_then_upgraded.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "Standalone with default maxWireVersion of 0 is upgraded to one with maxWireVersion 6",
2+
"description": "Standalone with default maxWireVersion of 0 is upgraded to one with maxWireVersion 21",
33
"uri": "mongodb://a",
44
"phases": [
55
{
@@ -35,7 +35,7 @@
3535
"helloOk": true,
3636
"isWritablePrimary": true,
3737
"minWireVersion": 0,
38-
"maxWireVersion": 6
38+
"maxWireVersion": 21
3939
}
4040
]
4141
],

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

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import java.nio.ByteBuffer
4343

4444
import static com.mongodb.internal.connection.SplittablePayload.Type.INSERT
4545
import static com.mongodb.internal.operation.ServerVersionHelper.FOUR_DOT_ZERO_WIRE_VERSION
46-
import static com.mongodb.internal.operation.ServerVersionHelper.THREE_DOT_SIX_WIRE_VERSION
46+
import static com.mongodb.internal.operation.ServerVersionHelper.LATEST_WIRE_VERSION
4747

4848
class CommandMessageSpecification extends Specification {
4949

@@ -55,7 +55,7 @@ class CommandMessageSpecification extends Specification {
5555
given:
5656
def message = new CommandMessage(namespace, command, fieldNameValidator, readPreference,
5757
MessageSettings.builder()
58-
.maxWireVersion(THREE_DOT_SIX_WIRE_VERSION)
58+
.maxWireVersion(LATEST_WIRE_VERSION)
5959
.serverType(serverType as ServerType)
6060
.sessionSupported(true)
6161
.build(),
@@ -148,24 +148,22 @@ class CommandMessageSpecification extends Specification {
148148

149149
def expectedCommandDocument = new BsonDocument('insert', new BsonString('coll')).append('documents',
150150
new BsonArray([new BsonDocument('_id', new BsonInt32(1)), new BsonDocument('_id', new BsonInt32(2))]))
151-
if (maxWireVersion == THREE_DOT_SIX_WIRE_VERSION) {
152-
expectedCommandDocument.append('$db', new BsonString(namespace.getDatabaseName()))
153-
}
151+
expectedCommandDocument.append('$db', new BsonString(namespace.getDatabaseName()))
154152
then:
155153
commandDocument == expectedCommandDocument
156154

157155

158156
where:
159157
[maxWireVersion, originalCommandDocument, payload] << [
160158
[
161-
THREE_DOT_SIX_WIRE_VERSION,
159+
LATEST_WIRE_VERSION,
162160
new BsonDocument('insert', new BsonString('coll')),
163161
new SplittablePayload(INSERT, [new BsonDocument('_id', new BsonInt32(1)),
164162
new BsonDocument('_id', new BsonInt32(2))]
165163
.withIndex().collect { doc, i -> new WriteRequestWithIndex(new InsertRequest(doc), i) } ),
166164
],
167165
[
168-
THREE_DOT_SIX_WIRE_VERSION,
166+
LATEST_WIRE_VERSION,
169167
new BsonDocument('insert', new BsonString('coll')).append('documents',
170168
new BsonArray([new BsonDocument('_id', new BsonInt32(1)), new BsonDocument('_id', new BsonInt32(2))])),
171169
null
@@ -176,7 +174,7 @@ class CommandMessageSpecification extends Specification {
176174
def 'should respect the max message size'() {
177175
given:
178176
def maxMessageSize = 1024
179-
def messageSettings = MessageSettings.builder().maxMessageSize(maxMessageSize).maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
177+
def messageSettings = MessageSettings.builder().maxMessageSize(maxMessageSize).maxWireVersion(LATEST_WIRE_VERSION).build()
180178
def insertCommand = new BsonDocument('insert', new BsonString(namespace.collectionName))
181179
def payload = new SplittablePayload(INSERT, [new BsonDocument('_id', new BsonInt32(1)).append('a', new BsonBinary(new byte[913])),
182180
new BsonDocument('_id', new BsonInt32(2)).append('b', new BsonBinary(new byte[441])),
@@ -262,7 +260,7 @@ class CommandMessageSpecification extends Specification {
262260

263261
def 'should respect the max batch count'() {
264262
given:
265-
def messageSettings = MessageSettings.builder().maxBatchCount(2).maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
263+
def messageSettings = MessageSettings.builder().maxBatchCount(2).maxWireVersion(LATEST_WIRE_VERSION).build()
266264
def payload = new SplittablePayload(INSERT, [new BsonDocument('a', new BsonBinary(new byte[900])),
267265
new BsonDocument('b', new BsonBinary(new byte[450])),
268266
new BsonDocument('c', new BsonBinary(new byte[450]))]
@@ -309,7 +307,7 @@ class CommandMessageSpecification extends Specification {
309307
def 'should throw if payload document bigger than max document size'() {
310308
given:
311309
def messageSettings = MessageSettings.builder().maxDocumentSize(900)
312-
.maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
310+
.maxWireVersion(LATEST_WIRE_VERSION).build()
313311
def payload = new SplittablePayload(INSERT, [new BsonDocument('a', new BsonBinary(new byte[900]))]
314312
.withIndex().collect { doc, i -> new WriteRequestWithIndex(new InsertRequest(doc), i) })
315313
def message = new CommandMessage(namespace, command, fieldNameValidator, ReadPreference.primary(), messageSettings,
@@ -326,25 +324,6 @@ class CommandMessageSpecification extends Specification {
326324
thrown(BsonMaximumSizeExceededException)
327325
}
328326

329-
def 'should throw if wire version does not support transactions'() {
330-
given:
331-
def messageSettings = MessageSettings.builder().maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
332-
def payload = new SplittablePayload(INSERT, [new BsonDocument('a', new BsonInt32(1))])
333-
def message = new CommandMessage(namespace, command, fieldNameValidator, ReadPreference.primary(), messageSettings,
334-
false, payload, fieldNameValidator, ClusterConnectionMode.MULTIPLE, null)
335-
def output = new BasicOutputBuffer()
336-
def sessionContext = Stub(SessionContext) {
337-
getReadConcern() >> ReadConcern.DEFAULT
338-
hasActiveTransaction() >> true
339-
}
340-
341-
when:
342-
message.encode(output, sessionContext)
343-
344-
then:
345-
thrown(MongoClientException)
346-
}
347-
348327
def 'should throw if wire version and sharded cluster does not support transactions'() {
349328
given:
350329
def messageSettings = MessageSettings.builder().serverType(ServerType.SHARD_ROUTER)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import static com.mongodb.connection.ConnectionDescription.getDefaultMaxWriteBat
6767
import static com.mongodb.connection.ServerDescription.getDefaultMaxDocumentSize
6868
import static com.mongodb.internal.connection.MessageHelper.LEGACY_HELLO
6969
import static com.mongodb.internal.connection.MessageHelper.LEGACY_HELLO_LOWER
70-
import static com.mongodb.internal.operation.ServerVersionHelper.THREE_DOT_SIX_WIRE_VERSION
70+
import static com.mongodb.internal.operation.ServerVersionHelper.LATEST_WIRE_VERSION
7171
import static java.util.concurrent.TimeUnit.NANOSECONDS
7272
import static java.util.concurrent.TimeUnit.SECONDS
7373

@@ -81,7 +81,7 @@ class InternalStreamConnectionSpecification extends Specification {
8181
def serverAddress = new ServerAddress()
8282
def connectionId = new ConnectionId(SERVER_ID, 1, 1)
8383
def commandListener = new TestCommandListener()
84-
def messageSettings = MessageSettings.builder().maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
84+
def messageSettings = MessageSettings.builder().maxWireVersion(LATEST_WIRE_VERSION).build()
8585

8686
def connectionDescription = new ConnectionDescription(connectionId, 3,
8787
ServerType.STANDALONE, getDefaultMaxWriteBatchSize(), getDefaultMaxDocumentSize(), getDefaultMaxMessageSize(), [])

0 commit comments

Comments
 (0)