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 1 commit
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
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 @@ -31,20 +31,13 @@ public final class ServerVersionHelper {
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 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 serverIsLessThanVersionFourDotTwo(final ConnectionDescription description) {
return description.getMaxWireVersion() < FOUR_DOT_TWO_WIRE_VERSION;
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import spock.lang.Specification

import static com.mongodb.connection.ClusterConnectionMode.MULTIPLE
import static com.mongodb.connection.ClusterConnectionMode.SINGLE
import static com.mongodb.internal.operation.ServerVersionHelper.LATEST_WIRE_VERSION
import static com.mongodb.internal.operation.ServerVersionHelper.THREE_DOT_SIX_WIRE_VERSION
Copy link
Member

Choose a reason for hiding this comment

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

Is ServerVersionHelper.THREE_DOT_SIX_WIRE_VERSION needed anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was just used in a few tests, so I replaced all usages with LATEST_WIRE_VERSION and removed it.


class LoggingCommandEventSenderSpecification extends Specification {
Expand All @@ -49,7 +50,7 @@ class LoggingCommandEventSenderSpecification extends Specification {
given:
def connectionDescription = new ConnectionDescription(new ServerId(new ClusterId(), new ServerAddress()))
def namespace = new MongoNamespace('test.driver')
def messageSettings = MessageSettings.builder().maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
def messageSettings = MessageSettings.builder().maxWireVersion(LATEST_WIRE_VERSION).build()
def commandListener = new TestCommandListener()
def commandDocument = new BsonDocument('ping', new BsonInt32(1))
def replyDocument = new BsonDocument('ok', new BsonInt32(1))
Expand Down Expand Up @@ -95,7 +96,7 @@ class LoggingCommandEventSenderSpecification extends Specification {
def connectionDescription = new ConnectionDescription(serverId)
.withConnectionId(new ConnectionId(serverId, 42, 1000))
def namespace = new MongoNamespace('test.driver')
def messageSettings = MessageSettings.builder().maxWireVersion(THREE_DOT_SIX_WIRE_VERSION).build()
def messageSettings = MessageSettings.builder().maxWireVersion(LATEST_WIRE_VERSION).build()
def commandDocument = new BsonDocument('ping', new BsonInt32(1))
def replyDocument = new BsonDocument('ok', new BsonInt32(42))
def failureException = new MongoInternalException('failure!')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

import static com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException;
import static com.mongodb.internal.connection.ProtocolHelper.isCommandOk;
import static com.mongodb.internal.operation.ServerVersionHelper.THREE_DOT_SIX_WIRE_VERSION;
import static com.mongodb.internal.operation.ServerVersionHelper.LATEST_WIRE_VERSION;

class TestInternalConnection implements InternalConnection {

Expand All @@ -66,7 +66,7 @@ private static class Interaction {
}

TestInternalConnection(final ServerId serverId, final ServerType serverType) {
this.description = new ConnectionDescription(new ConnectionId(serverId), THREE_DOT_SIX_WIRE_VERSION, serverType, 0, 0, 0,
this.description = new ConnectionDescription(new ConnectionId(serverId), LATEST_WIRE_VERSION, serverType, 0, 0, 0,
Collections.emptyList());
this.bufferProvider = new SimpleBufferProvider();

Expand Down