Skip to content

Remove support for MongoDB 3.6 #1375

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

Merged
merged 6 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .evergreen/.evg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1802,10 +1802,6 @@ axes:
display_name: "4.0"
variables:
VERSION: "4.0"
- id: "3.6"
display_name: "3.6"
variables:
VERSION: "3.6"
- id: os
display_name: OS
values:
Expand Down Expand Up @@ -2223,7 +2219,7 @@ buildvariants:
- name: "test"

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

- matrix_name: "tests-jdk-secure"
matrix_spec: { auth: "auth", ssl: "ssl", jdk: [ "jdk8", "jdk17", "jdk21"],
version: [ "3.6", "4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "latest" ],
version: ["4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "latest" ],
topology: "*", os: "linux" }
display_name: "${version} ${topology} ${auth} ${ssl} ${jdk} ${os} "
tags: ["tests-variant"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ServerDescription {
* The minimum supported driver wire version
* @since 3.8
*/
public static final int MIN_DRIVER_WIRE_VERSION = 6;
public static final int MIN_DRIVER_WIRE_VERSION = 7;
/**
* The maximum supported driver wire version
* @since 3.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import static com.mongodb.internal.connection.ReadConcernHelper.getReadConcernDocument;
import static com.mongodb.internal.operation.ServerVersionHelper.FOUR_DOT_TWO_WIRE_VERSION;
import static com.mongodb.internal.operation.ServerVersionHelper.FOUR_DOT_ZERO_WIRE_VERSION;
import static com.mongodb.internal.operation.ServerVersionHelper.THREE_DOT_SIX_WIRE_VERSION;

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

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

private static OpCode getOpCode(final MessageSettings settings, final ClusterConnectionMode clusterConnectionMode,
@Nullable final ServerApi serverApi) {
return isServerVersionAtLeastThreeDotSix(settings) || clusterConnectionMode == LOAD_BALANCED || serverApi != null
return isServerVersionKnown(settings) || clusterConnectionMode == LOAD_BALANCED || serverApi != null
? OpCode.OP_MSG
: OpCode.OP_QUERY;
}

private static boolean isServerVersionAtLeastThreeDotSix(final MessageSettings settings) {
return settings.getMaxWireVersion() >= THREE_DOT_SIX_WIRE_VERSION;
private static boolean isServerVersionKnown(final MessageSettings settings) {
return settings.getMaxWireVersion() >= FOUR_DOT_ZERO_WIRE_VERSION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static com.mongodb.AuthenticationMechanism.SCRAM_SHA_256;
import static com.mongodb.assertions.Assertions.assertNotNull;
import static com.mongodb.assertions.Assertions.isTrueArgument;
import static com.mongodb.internal.operation.ServerVersionHelper.serverIsLessThanVersionFourDotZero;
import static java.lang.String.format;

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

@Override
void authenticate(final InternalConnection connection, final ConnectionDescription connectionDescription) {
if (serverIsLessThanVersionFourDotZero(connectionDescription)) {
new ScramShaAuthenticator(getMongoCredentialWithCache().withMechanism(SCRAM_SHA_1), getClusterConnectionMode(), getServerApi())
.authenticate(connection, connectionDescription);
} else {
try {
setDelegate(connectionDescription);
delegate.authenticate(connection, connectionDescription);
} catch (Exception e) {
throw wrapException(e);
}
try {
setDelegate(connectionDescription);
delegate.authenticate(connection, connectionDescription);
} catch (Exception e) {
throw wrapException(e);
}
}

@Override
void authenticateAsync(final InternalConnection connection, final ConnectionDescription connectionDescription,
final SingleResultCallback<Void> callback) {
if (serverIsLessThanVersionFourDotZero(connectionDescription)) {
new ScramShaAuthenticator(getMongoCredentialWithCache().withMechanism(SCRAM_SHA_1), getClusterConnectionMode(), getServerApi())
.authenticateAsync(connection, connectionDescription, callback);
} else {
setDelegate(connectionDescription);
delegate.authenticateAsync(connection, connectionDescription, callback);
}
setDelegate(connectionDescription);
delegate.authenticateAsync(connection, connectionDescription, callback);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,18 @@
public final class ServerVersionHelper {

public static final int MIN_WIRE_VERSION = 0;
public static final int THREE_DOT_SIX_WIRE_VERSION = 6;
public static final int FOUR_DOT_ZERO_WIRE_VERSION = 7;
public static final int FOUR_DOT_TWO_WIRE_VERSION = 8;
public static final int FOUR_DOT_FOUR_WIRE_VERSION = 9;
public static final int FIVE_DOT_ZERO_WIRE_VERSION = 12;
public static final int SIX_DOT_ZERO_WIRE_VERSION = 17;
private static final int SEVEN_DOT_ZERO_WIRE_VERSION = 21;

public static boolean serverIsAtLeastVersionFourDotZero(final ConnectionDescription description) {
return description.getMaxWireVersion() >= FOUR_DOT_ZERO_WIRE_VERSION;
}

public static boolean serverIsAtLeastVersionFourDotTwo(final ConnectionDescription description) {
return description.getMaxWireVersion() >= FOUR_DOT_TWO_WIRE_VERSION;
}
public static final int SEVEN_DOT_ZERO_WIRE_VERSION = 21;
public static final int LATEST_WIRE_VERSION = SEVEN_DOT_ZERO_WIRE_VERSION;

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

public static boolean serverIsAtLeastVersionFiveDotZero(final ConnectionDescription description) {
return description.getMaxWireVersion() >= FIVE_DOT_ZERO_WIRE_VERSION;
}

public static boolean serverIsLessThanVersionFourDotZero(final ConnectionDescription description) {
return description.getMaxWireVersion() < FOUR_DOT_ZERO_WIRE_VERSION;
}

public static boolean serverIsLessThanVersionFourDotTwo(final ConnectionDescription description) {
return description.getMaxWireVersion() < FOUR_DOT_TWO_WIRE_VERSION;
}
Expand Down
14 changes: 4 additions & 10 deletions driver-core/src/test/functional/com/mongodb/ClusterFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,8 @@ public static ReadWriteBinding getBinding(final ReadPreference readPreference) {

private static ReadWriteBinding getBinding(final Cluster cluster, final ReadPreference readPreference) {
if (!BINDING_MAP.containsKey(readPreference)) {
ReadWriteBinding binding = new ClusterBinding(cluster, readPreference, ReadConcern.DEFAULT, getServerApi(),
IgnorableRequestContext.INSTANCE);
if (serverVersionAtLeast(3, 6)) {
binding = new SessionBinding(binding);
}
ReadWriteBinding binding = new SessionBinding(new ClusterBinding(cluster, readPreference, ReadConcern.DEFAULT, getServerApi(),
IgnorableRequestContext.INSTANCE));
BINDING_MAP.put(readPreference, binding);
}
return BINDING_MAP.get(readPreference);
Expand Down Expand Up @@ -367,11 +364,8 @@ public static AsyncReadWriteBinding getAsyncBinding(final ReadPreference readPre

public static AsyncReadWriteBinding getAsyncBinding(final Cluster cluster, final ReadPreference readPreference) {
if (!ASYNC_BINDING_MAP.containsKey(readPreference)) {
AsyncReadWriteBinding binding = new AsyncClusterBinding(cluster, readPreference, ReadConcern.DEFAULT, getServerApi(),
IgnorableRequestContext.INSTANCE);
if (serverVersionAtLeast(3, 6)) {
binding = new AsyncSessionBinding(binding);
}
AsyncReadWriteBinding binding = new AsyncSessionBinding(new AsyncClusterBinding(cluster, readPreference, ReadConcern.DEFAULT,
getServerApi(), IgnorableRequestContext.INSTANCE));
ASYNC_BINDING_MAP.put(readPreference, binding);
}
return ASYNC_BINDING_MAP.get(readPreference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

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

// Not clear whether these global fields should be included, but also not clear how to efficiently exclude them
if (serverVersionAtLeast(3, 6)) {
commandDocument.put("$db", new BsonString(actualDatabaseName));
if (operation != null && operation.containsKey("read_preference")) {
commandDocument.put("$readPreference", operation.getDocument("read_preference"));
}
commandDocument.put("$db", new BsonString(actualDatabaseName));
if (operation != null && operation.containsKey("read_preference")) {
commandDocument.put("$readPreference", operation.getDocument("read_preference"));
}
commandEvent = new CommandStartedEvent(null, 1, 1, null, actualDatabaseName, commandName,
commandDocument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"b:27017"
],
"minWireVersion": 0,
"maxWireVersion": 6
"maxWireVersion": 21
}
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"b:27017"
],
"minWireVersion": 0,
"maxWireVersion": 6
"maxWireVersion": 21
}
]
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"isWritablePrimary": true,
"msg": "isdbgrid",
"minWireVersion": 0,
"maxWireVersion": 6
"maxWireVersion": 21
}
]
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"helloOk": true,
"isWritablePrimary": true,
"minWireVersion": 0,
"maxWireVersion": 6
"maxWireVersion": 21
}
]
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "Standalone with default maxWireVersion of 0 is upgraded to one with maxWireVersion 6",
"description": "Standalone with default maxWireVersion of 0 is upgraded to one with maxWireVersion 21",
"uri": "mongodb://a",
"phases": [
{
Expand Down Expand Up @@ -35,7 +35,7 @@
"helloOk": true,
"isWritablePrimary": true,
"minWireVersion": 0,
"maxWireVersion": 6
"maxWireVersion": 21
}
]
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import java.nio.ByteBuffer

import static com.mongodb.internal.connection.SplittablePayload.Type.INSERT
import static com.mongodb.internal.operation.ServerVersionHelper.FOUR_DOT_ZERO_WIRE_VERSION
import static com.mongodb.internal.operation.ServerVersionHelper.THREE_DOT_SIX_WIRE_VERSION
import static com.mongodb.internal.operation.ServerVersionHelper.LATEST_WIRE_VERSION

class CommandMessageSpecification extends Specification {

Expand All @@ -55,7 +55,7 @@ class CommandMessageSpecification extends Specification {
given:
def message = new CommandMessage(namespace, command, fieldNameValidator, readPreference,
MessageSettings.builder()
.maxWireVersion(THREE_DOT_SIX_WIRE_VERSION)
.maxWireVersion(LATEST_WIRE_VERSION)
.serverType(serverType as ServerType)
.sessionSupported(true)
.build(),
Expand Down Expand Up @@ -148,24 +148,22 @@ class CommandMessageSpecification extends Specification {

def expectedCommandDocument = new BsonDocument('insert', new BsonString('coll')).append('documents',
new BsonArray([new BsonDocument('_id', new BsonInt32(1)), new BsonDocument('_id', new BsonInt32(2))]))
if (maxWireVersion == THREE_DOT_SIX_WIRE_VERSION) {
expectedCommandDocument.append('$db', new BsonString(namespace.getDatabaseName()))
}
expectedCommandDocument.append('$db', new BsonString(namespace.getDatabaseName()))
then:
commandDocument == expectedCommandDocument


where:
[maxWireVersion, originalCommandDocument, payload] << [
[
THREE_DOT_SIX_WIRE_VERSION,
LATEST_WIRE_VERSION,
new BsonDocument('insert', new BsonString('coll')),
new SplittablePayload(INSERT, [new BsonDocument('_id', new BsonInt32(1)),
new BsonDocument('_id', new BsonInt32(2))]
.withIndex().collect { doc, i -> new WriteRequestWithIndex(new InsertRequest(doc), i) } ),
],
[
THREE_DOT_SIX_WIRE_VERSION,
LATEST_WIRE_VERSION,
new BsonDocument('insert', new BsonString('coll')).append('documents',
new BsonArray([new BsonDocument('_id', new BsonInt32(1)), new BsonDocument('_id', new BsonInt32(2))])),
null
Expand All @@ -176,7 +174,7 @@ class CommandMessageSpecification extends Specification {
def 'should respect the max message size'() {
given:
def maxMessageSize = 1024
def messageSettings = MessageSettings.builder().maxMessageSize(maxMessageSize).maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
def messageSettings = MessageSettings.builder().maxMessageSize(maxMessageSize).maxWireVersion(LATEST_WIRE_VERSION).build()
def insertCommand = new BsonDocument('insert', new BsonString(namespace.collectionName))
def payload = new SplittablePayload(INSERT, [new BsonDocument('_id', new BsonInt32(1)).append('a', new BsonBinary(new byte[913])),
new BsonDocument('_id', new BsonInt32(2)).append('b', new BsonBinary(new byte[441])),
Expand Down Expand Up @@ -262,7 +260,7 @@ class CommandMessageSpecification extends Specification {

def 'should respect the max batch count'() {
given:
def messageSettings = MessageSettings.builder().maxBatchCount(2).maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
def messageSettings = MessageSettings.builder().maxBatchCount(2).maxWireVersion(LATEST_WIRE_VERSION).build()
def payload = new SplittablePayload(INSERT, [new BsonDocument('a', new BsonBinary(new byte[900])),
new BsonDocument('b', new BsonBinary(new byte[450])),
new BsonDocument('c', new BsonBinary(new byte[450]))]
Expand Down Expand Up @@ -309,7 +307,7 @@ class CommandMessageSpecification extends Specification {
def 'should throw if payload document bigger than max document size'() {
given:
def messageSettings = MessageSettings.builder().maxDocumentSize(900)
.maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
.maxWireVersion(LATEST_WIRE_VERSION).build()
def payload = new SplittablePayload(INSERT, [new BsonDocument('a', new BsonBinary(new byte[900]))]
.withIndex().collect { doc, i -> new WriteRequestWithIndex(new InsertRequest(doc), i) })
def message = new CommandMessage(namespace, command, fieldNameValidator, ReadPreference.primary(), messageSettings,
Expand All @@ -326,25 +324,6 @@ class CommandMessageSpecification extends Specification {
thrown(BsonMaximumSizeExceededException)
}

def 'should throw if wire version does not support transactions'() {
given:
def messageSettings = MessageSettings.builder().maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
def payload = new SplittablePayload(INSERT, [new BsonDocument('a', new BsonInt32(1))])
def message = new CommandMessage(namespace, command, fieldNameValidator, ReadPreference.primary(), messageSettings,
false, payload, fieldNameValidator, ClusterConnectionMode.MULTIPLE, null)
def output = new BasicOutputBuffer()
def sessionContext = Stub(SessionContext) {
getReadConcern() >> ReadConcern.DEFAULT
hasActiveTransaction() >> true
}

when:
message.encode(output, sessionContext)

then:
thrown(MongoClientException)
}

def 'should throw if wire version and sharded cluster does not support transactions'() {
given:
def messageSettings = MessageSettings.builder().serverType(ServerType.SHARD_ROUTER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import static com.mongodb.connection.ConnectionDescription.getDefaultMaxWriteBat
import static com.mongodb.connection.ServerDescription.getDefaultMaxDocumentSize
import static com.mongodb.internal.connection.MessageHelper.LEGACY_HELLO
import static com.mongodb.internal.connection.MessageHelper.LEGACY_HELLO_LOWER
import static com.mongodb.internal.operation.ServerVersionHelper.THREE_DOT_SIX_WIRE_VERSION
import static com.mongodb.internal.operation.ServerVersionHelper.LATEST_WIRE_VERSION
import static java.util.concurrent.TimeUnit.NANOSECONDS
import static java.util.concurrent.TimeUnit.SECONDS

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

def connectionDescription = new ConnectionDescription(connectionId, 3,
ServerType.STANDALONE, getDefaultMaxWriteBatchSize(), getDefaultMaxDocumentSize(), getDefaultMaxMessageSize(), [])
Expand Down
Loading