From a8619c28f459ca4f22de10d0714aec0d99bec4ca Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Wed, 5 Mar 2025 10:01:32 -0500 Subject: [PATCH 1/5] Remove support for MongoDB 4.0 * Remove branching code in the driver based on 4.0 version checks * Remove testing of 4.0 * Clean up tests JAVA-5831 --- .evergreen/.evg.yml | 65 ++----------------- .evergreen/run-kotlin-tests.sh | 5 +- .evergreen/run-mmapv1-storage-test.sh | 24 ------- .evergreen/run-scala-tests.sh | 5 +- .evergreen/run-tests.sh | 34 ++++------ .../mongodb/connection/ServerDescription.java | 4 +- .../internal/connection/CommandMessage.java | 12 +--- .../DefaultSdamServerDescriptionManager.java | 5 +- .../SdamServerDescriptionManager.java | 9 --- .../internal/operation/OperationHelper.java | 9 --- .../operation/ServerVersionHelper.java | 9 +-- .../CommandMessageSpecification.groovy | 27 +------- .../connection/CommandMessageTest.java | 5 +- .../ServerDiscoveryAndMonitoringTest.java | 10 +++ .../internal/crypt/CryptConnection.java | 9 +-- .../client/internal/CryptConnection.java | 8 +-- 16 files changed, 42 insertions(+), 198 deletions(-) delete mode 100755 .evergreen/run-mmapv1-storage-test.sh diff --git a/.evergreen/.evg.yml b/.evergreen/.evg.yml index 673b26b6068..476d614a028 100644 --- a/.evergreen/.evg.yml +++ b/.evergreen/.evg.yml @@ -285,7 +285,7 @@ functions: export AWS_TEMP_SESSION_TOKEN=$CSFLE_AWS_TEMP_SESSION_TOKEN export CRYPT_SHARED_LIB_PATH=${CRYPT_SHARED_LIB_PATH} - AUTH="${AUTH}" SSL="${SSL}" MONGODB_URI="${MONGODB_URI}" SAFE_FOR_MULTI_MONGOS="${SAFE_FOR_MULTI_MONGOS}" TOPOLOGY="${TOPOLOGY}" \ + AUTH="${AUTH}" SSL="${SSL}" MONGODB_URI="${MONGODB_URI}" TOPOLOGY="${TOPOLOGY}" \ COMPRESSOR="${COMPRESSOR}" JAVA_VERSION="${JAVA_VERSION}" REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \ TESTS="${TESTS}" .evergreen/run-tests.sh @@ -344,7 +344,7 @@ functions: working_dir: "src" script: | ${PREPARE_SHELL} - SCALA="${SCALA}" AUTH="${AUTH}" SSL="${SSL}" MONGODB_URI="${MONGODB_URI}" SAFE_FOR_MULTI_MONGOS="${SAFE_FOR_MULTI_MONGOS}" TOPOLOGY="${TOPOLOGY}" JAVA_VERSION="${JAVA_VERSION}" .evergreen/run-scala-tests.sh + SCALA="${SCALA}" AUTH="${AUTH}" SSL="${SSL}" MONGODB_URI="${MONGODB_URI}" TOPOLOGY="${TOPOLOGY}" JAVA_VERSION="${JAVA_VERSION}" .evergreen/run-scala-tests.sh "run kotlin tests": - command: shell.exec @@ -353,7 +353,7 @@ functions: working_dir: "src" script: | ${PREPARE_SHELL} - AUTH="${AUTH}" SSL="${SSL}" MONGODB_URI="${MONGODB_URI}" SAFE_FOR_MULTI_MONGOS="${SAFE_FOR_MULTI_MONGOS}" TOPOLOGY="${TOPOLOGY}" JAVA_VERSION="${JAVA_VERSION}" .evergreen/run-kotlin-tests.sh + AUTH="${AUTH}" SSL="${SSL}" MONGODB_URI="${MONGODB_URI}" TOPOLOGY="${TOPOLOGY}" JAVA_VERSION="${JAVA_VERSION}" .evergreen/run-kotlin-tests.sh "run socket tests": @@ -599,16 +599,6 @@ functions: LOGIN_CONTEXT_NAME=${LOGIN_CONTEXT_NAME} \ .evergreen/run-gssapi-auth-test.sh - "run mmapv1 storage test": - - command: shell.exec - type: test - params: - silent: true - working_dir: "src" - script: | - ${PREPARE_SHELL} - PROJECT_DIRECTORY=${PROJECT_DIRECTORY} JAVA_VERSION=${JAVA_VERSION} TOPOLOGY=${TOPOLOGY} STORAGE_ENGINE=${STORAGE_ENGINE} MONGODB_URI="${MONGODB_URI}" .evergreen/run-mmapv1-storage-test.sh - run socks5 tests: - command: shell.exec type: test @@ -1577,11 +1567,6 @@ tasks: TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/driver-lambda/ AWS_REGION: us-east-1 - - name: "mmapv1-storage-test" - commands: - - func: "bootstrap mongo-orchestration" - - func: "run mmapv1 storage test" - - name: "test-kms-tls-invalid-cert" tags: ["kms-tls"] commands: @@ -1717,55 +1702,30 @@ axes: display_name: "latest" variables: VERSION: "latest" - # Multiple mongos instances can be specified in the connection string - # for this version. - SAFE_FOR_MULTI_MONGOS: true - id: "8.0" display_name: "8.0" variables: VERSION: "8.0" - # Multiple mongos instances can be specified in the connection string - # for this version. - SAFE_FOR_MULTI_MONGOS: true - id: "7.0" display_name: "7.0" variables: VERSION: "7.0" - # Multiple mongos instances can be specified in the connection string - # for this version. - SAFE_FOR_MULTI_MONGOS: true - id: "6.0" display_name: "6.0" variables: VERSION: "6.0" - # Multiple mongos instances can be specified in the connection string - # for this version. - SAFE_FOR_MULTI_MONGOS: true - id: "5.0" display_name: "5.0" variables: VERSION: "5.0" - # Multiple mongos instances can be specified in the connection string - # for this version. - SAFE_FOR_MULTI_MONGOS: true - id: "4.4" display_name: "4.4" variables: VERSION: "4.4" - # Multiple mongos instances can be specified in the connection string - # for this version. - SAFE_FOR_MULTI_MONGOS: true - id: "4.2" display_name: "4.2" variables: VERSION: "4.2" - # Multiple mongos instances can be specified in the connection string - # for this version. - SAFE_FOR_MULTI_MONGOS: true - - id: "4.0" - display_name: "4.0" - variables: - VERSION: "4.0" - id: os display_name: OS values: @@ -1886,15 +1846,6 @@ axes: variables: SCALA: "2.13" - # Choice of MongoDB storage engine - - id: storage-engine - display_name: Storage - values: - - id: mmapv1 - display_name: MMAPv1 - variables: - STORAGE_ENGINE: "mmapv1" - - id: api-version display_name: API Version values: @@ -2201,7 +2152,7 @@ buildvariants: - name: "test-bson-and-crypt" - matrix_name: "tests-jdk8-unsecure" - matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk8", version: ["4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "latest"], + matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk8", version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "latest"], topology: "*", os: "linux" } display_name: "${version} ${topology} ${auth} ${ssl} ${jdk} ${os} " tags: ["tests-variant"] @@ -2213,7 +2164,7 @@ buildvariants: - matrix_name: "tests-jdk-secure" matrix_spec: { auth: "auth", ssl: "ssl", jdk: [ "jdk8", "jdk17", "jdk21"], - version: ["4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "latest" ], + version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "latest" ], topology: "*", os: "linux" } display_name: "${version} ${topology} ${auth} ${ssl} ${jdk} ${os} " tags: ["tests-variant"] @@ -2427,12 +2378,6 @@ buildvariants: tasks: - name: "publish-release" -- matrix_name: "tests-storage-engines" - matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk8", os: "linux", version: ["4.0"], topology: ["replicaset", "sharded-cluster"], storage-engine: "mmapv1" } - display_name: "${version} Storage ${storage-engine} ${jdk} ${os} ${topology}" - tasks: - - name: "mmapv1-storage-test" - - matrix_name: "kms-tls-test" matrix_spec: { os: "linux", version: [ "5.0" ], topology: ["standalone"] } display_name: "CSFLE KMS TLS" diff --git a/.evergreen/run-kotlin-tests.sh b/.evergreen/run-kotlin-tests.sh index a82c66e9e54..e240d7bc255 100755 --- a/.evergreen/run-kotlin-tests.sh +++ b/.evergreen/run-kotlin-tests.sh @@ -8,7 +8,6 @@ AUTH=${AUTH:-noauth} SSL=${SSL:-nossl} MONGODB_URI=${MONGODB_URI:-} TOPOLOGY=${TOPOLOGY:-standalone} -SAFE_FOR_MULTI_MONGOS=${SAFE_FOR_MULTI_MONGOS:-} ############################################ # Main Program # @@ -27,9 +26,7 @@ if [ "$AUTH" != "noauth" ]; then exit 1 fi -if [ "$SAFE_FOR_MULTI_MONGOS" == "true" ]; then - export MULTI_MONGOS_URI_SYSTEM_PROPERTY="-Dorg.mongodb.test.multi.mongos.uri=${MONGODB_URI}" -fi +export MULTI_MONGOS_URI_SYSTEM_PROPERTY="-Dorg.mongodb.test.multi.mongos.uri=${MONGODB_URI}" ./gradlew -version diff --git a/.evergreen/run-mmapv1-storage-test.sh b/.evergreen/run-mmapv1-storage-test.sh deleted file mode 100755 index 6061acff2d3..00000000000 --- a/.evergreen/run-mmapv1-storage-test.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -set -o errexit # Exit the script with error if any of the commands fail - -# Supported/used environment variables: -# MONGODB_URI Set the URI, including username/password to use to connect to the server via PLAIN authentication mechanism -# JDK Set the version of java to be used. Java versions can be set from the java toolchain /opt/java -# "jdk5", "jdk6", "jdk7", "jdk8", "jdk9" - -############################################ -# Main Program # -############################################ -RELATIVE_DIR_PATH="$(dirname "${BASH_SOURCE:-$0}")" -. "${RELATIVE_DIR_PATH}/javaConfig.bash" - -echo "Running MMAPv1 Storage Test" - -echo "Running tests with Java ${JAVA_VERSION}" -./gradlew -version -for PACKAGE in driver-sync driver-reactive-streams ; do - ./gradlew -PjavaVersion=${JAVA_VERSION} --stacktrace --info \ - -Dorg.mongodb.test.uri=${MONGODB_URI} \ - ${PACKAGE}:test --tests RetryableWritesProseTest -done diff --git a/.evergreen/run-scala-tests.sh b/.evergreen/run-scala-tests.sh index 7854650a687..e82bb5a56c9 100755 --- a/.evergreen/run-scala-tests.sh +++ b/.evergreen/run-scala-tests.sh @@ -8,7 +8,6 @@ AUTH=${AUTH:-noauth} SSL=${SSL:-nossl} MONGODB_URI=${MONGODB_URI:-} TOPOLOGY=${TOPOLOGY:-standalone} -SAFE_FOR_MULTI_MONGOS=${SAFE_FOR_MULTI_MONGOS:-} ############################################ # Main Program # @@ -27,9 +26,7 @@ if [ "$AUTH" != "noauth" ]; then exit 1 fi -if [ "$SAFE_FOR_MULTI_MONGOS" == "true" ]; then - export MULTI_MONGOS_URI_SYSTEM_PROPERTY="-Dorg.mongodb.test.multi.mongos.uri=${MONGODB_URI}" -fi +export MULTI_MONGOS_URI_SYSTEM_PROPERTY="-Dorg.mongodb.test.multi.mongos.uri=${MONGODB_URI}" echo "Running scala tests with Scala $SCALA" diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index f8e90977e36..84481f90ce5 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -68,14 +68,10 @@ provision_multi_mongos_uri_for_ssl () { # Arguments for auth + SSL if [ "$AUTH" != "noauth" ] || [ "$TOPOLOGY" == "replica_set" ]; then export MONGODB_URI="${MONGODB_URI}&ssl=true&sslInvalidHostNameAllowed=true" - if [ "$SAFE_FOR_MULTI_MONGOS" == "true" ]; then - export MULTI_MONGOS_URI="${MULTI_MONGOS_URI}&ssl=true&sslInvalidHostNameAllowed=true" - fi + export MULTI_MONGOS_URI="${MULTI_MONGOS_URI}&ssl=true&sslInvalidHostNameAllowed=true" else export MONGODB_URI="${MONGODB_URI}/?ssl=true&sslInvalidHostNameAllowed=true" - if [ "$SAFE_FOR_MULTI_MONGOS" == "true" ]; then - export MULTI_MONGOS_URI="${MULTI_MONGOS_URI}/?ssl=true&sslInvalidHostNameAllowed=true" - fi + export MULTI_MONGOS_URI="${MULTI_MONGOS_URI}/?ssl=true&sslInvalidHostNameAllowed=true" fi } @@ -85,13 +81,11 @@ provision_multi_mongos_uri_for_ssl () { # Provision the correct connection string and set up SSL if needed if [ "$TOPOLOGY" == "sharded_cluster" ]; then - if [ "$SAFE_FOR_MULTI_MONGOS" == "true" ]; then - if [ "$AUTH" = "auth" ]; then - export MULTI_MONGOS_URI="mongodb://bob:pwd123@localhost:27017,localhost:27018/?authSource=admin" - else - export MULTI_MONGOS_URI="${MONGODB_URI}" - fi - fi + if [ "$AUTH" = "auth" ]; then + export MULTI_MONGOS_URI="mongodb://bob:pwd123@localhost:27017,localhost:27018/?authSource=admin" + else + export MULTI_MONGOS_URI="${MONGODB_URI}" + fi if [ "$AUTH" = "auth" ]; then export MONGODB_URI="mongodb://bob:pwd123@localhost:27017/?authSource=admin" @@ -107,12 +101,10 @@ if [ "$COMPRESSOR" != "" ]; then export MONGODB_URI="${MONGODB_URI}/?compressors=${COMPRESSOR}" fi - if [ "$SAFE_FOR_MULTI_MONGOS" == "true" ]; then - if [[ "$MULTI_MONGOS_URI" == *"?"* ]]; then - export MULTI_MONGOS_URI="${MULTI_MONGOS_URI}&compressors=${COMPRESSOR}" - else - export MULTI_MONGOS_URI="${MULTI_MONGOS_URI}/?compressors=${COMPRESSOR}" - fi + if [[ "$MULTI_MONGOS_URI" == *"?"* ]]; then + export MULTI_MONGOS_URI="${MULTI_MONGOS_URI}&compressors=${COMPRESSOR}" + else + export MULTI_MONGOS_URI="${MULTI_MONGOS_URI}/?compressors=${COMPRESSOR}" fi fi @@ -123,9 +115,7 @@ if [ "$SSL" != "nossl" ]; then provision_multi_mongos_uri_for_ssl fi -if [ "$SAFE_FOR_MULTI_MONGOS" == "true" ]; then - export MULTI_MONGOS_URI_SYSTEM_PROPERTY="-Dorg.mongodb.test.multi.mongos.uri=${MULTI_MONGOS_URI}" -fi +export MULTI_MONGOS_URI_SYSTEM_PROPERTY="-Dorg.mongodb.test.multi.mongos.uri=${MULTI_MONGOS_URI}" # For now it's sufficient to hard-code the API version to "1", since it's the only API version if [ ! -z "$REQUIRE_API_VERSION" ]; then diff --git a/driver-core/src/main/com/mongodb/connection/ServerDescription.java b/driver-core/src/main/com/mongodb/connection/ServerDescription.java index f3de13006d1..2d675bce217 100644 --- a/driver-core/src/main/com/mongodb/connection/ServerDescription.java +++ b/driver-core/src/main/com/mongodb/connection/ServerDescription.java @@ -55,12 +55,12 @@ public class ServerDescription { * The minimum supported driver server version * @since 3.8 */ - public static final String MIN_DRIVER_SERVER_VERSION = "3.6"; + public static final String MIN_DRIVER_SERVER_VERSION = "4.2"; /** * The minimum supported driver wire version * @since 3.8 */ - public static final int MIN_DRIVER_WIRE_VERSION = 7; + public static final int MIN_DRIVER_WIRE_VERSION = 8; /** * The maximum supported driver wire version * @since 3.8 diff --git a/driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java b/driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java index 46eabab21bb..fa72eaf9959 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java +++ b/driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java @@ -60,8 +60,7 @@ import static com.mongodb.internal.connection.ByteBufBsonDocument.createList; import static com.mongodb.internal.connection.ByteBufBsonDocument.createOne; 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.EARLIEST_WIRE_VERSION; /** * A command message that uses OP_MSG or OP_QUERY to send the command. @@ -346,7 +345,6 @@ private List getExtraElements(final OperationContext operationConte assertFalse(sessionContext.hasActiveTransaction() && sessionContext.isSnapshot()); if (sessionContext.hasActiveTransaction()) { - checkServerVersionForTransactionSupport(); extraElements.add(new BsonElement("txnNumber", new BsonInt64(sessionContext.getTransactionNumber()))); if (firstMessageInTransaction) { extraElements.add(new BsonElement("startTransaction", BsonBoolean.TRUE)); @@ -381,12 +379,6 @@ private void addServerApiElements(final List extraElements) { } } - private void checkServerVersionForTransactionSupport() { - 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."); - } - } - private void addReadConcernDocument(final List extraElements, final SessionContext sessionContext) { BsonDocument readConcernDocument = getReadConcernDocument(sessionContext, getSettings().getMaxWireVersion()); @@ -416,7 +408,7 @@ private static OpCode getOpCode(final MessageSettings settings, final ClusterCon } private static boolean isServerVersionKnown(final MessageSettings settings) { - return settings.getMaxWireVersion() >= FOUR_DOT_ZERO_WIRE_VERSION; + return settings.getMaxWireVersion() >= EARLIEST_WIRE_VERSION; } @FunctionalInterface diff --git a/driver-core/src/main/com/mongodb/internal/connection/DefaultSdamServerDescriptionManager.java b/driver-core/src/main/com/mongodb/internal/connection/DefaultSdamServerDescriptionManager.java index 3e32d505641..6137afd3e6d 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/DefaultSdamServerDescriptionManager.java +++ b/driver-core/src/main/com/mongodb/internal/connection/DefaultSdamServerDescriptionManager.java @@ -119,7 +119,7 @@ private void handleException(final SdamIssue sdamIssue, final boolean beforeHand } if (sdamIssue.relatedToStateChange()) { updateDescription(sdamIssue.serverDescription()); - if (sdamIssue.serverIsLessThanVersionFourDotTwo() || sdamIssue.relatedToShutdown()) { + if (sdamIssue.relatedToShutdown()) { connectionPool.invalidate(sdamIssue.exception().orElse(null)); } serverMonitor.connect(); @@ -130,9 +130,6 @@ private void handleException(final SdamIssue sdamIssue, final boolean beforeHand serverMonitor.cancelCurrentCheck(); } else if (sdamIssue.relatedToWriteConcern() || !sdamIssue.specific()) { updateDescription(sdamIssue.serverDescription()); - if (sdamIssue.serverIsLessThanVersionFourDotTwo()) { - connectionPool.invalidate(sdamIssue.exception().orElse(null)); - } serverMonitor.connect(); } } diff --git a/driver-core/src/main/com/mongodb/internal/connection/SdamServerDescriptionManager.java b/driver-core/src/main/com/mongodb/internal/connection/SdamServerDescriptionManager.java index a7078b7cfb9..7db4085f1e2 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/SdamServerDescriptionManager.java +++ b/driver-core/src/main/com/mongodb/internal/connection/SdamServerDescriptionManager.java @@ -35,7 +35,6 @@ import static com.mongodb.assertions.Assertions.assertTrue; import static com.mongodb.internal.connection.ClusterableServer.SHUTDOWN_CODES; import static com.mongodb.internal.connection.ServerDescriptionHelper.unknownConnectingServerDescription; -import static com.mongodb.internal.operation.ServerVersionHelper.FOUR_DOT_TWO_WIRE_VERSION; /** * See the @@ -117,10 +116,6 @@ ServerDescription serverDescription() { return unknownConnectingServerDescription(context.serverId(), exception); } - boolean serverIsLessThanVersionFourDotTwo() { - return context.serverIsLessThanVersionFourDotTwo(); - } - boolean stale(final ConnectionPool connectionPool, final ServerDescription currentServerDescription) { return context.stale(connectionPool) || stale(exception, currentServerDescription); } @@ -192,10 +187,6 @@ static final class Context { this.serverMaxWireVersion = serverMaxWireVersion; } - private boolean serverIsLessThanVersionFourDotTwo() { - return serverMaxWireVersion < FOUR_DOT_TWO_WIRE_VERSION; - } - private boolean stale(final ConnectionPool connectionPool) { return connectionPoolGeneration < connectionPool.getGeneration(); } diff --git a/driver-core/src/main/com/mongodb/internal/operation/OperationHelper.java b/driver-core/src/main/com/mongodb/internal/operation/OperationHelper.java index b7a4997e639..f980d309a8a 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/OperationHelper.java +++ b/driver-core/src/main/com/mongodb/internal/operation/OperationHelper.java @@ -46,7 +46,6 @@ import static com.mongodb.assertions.Assertions.assertNotNull; import static com.mongodb.internal.operation.ServerVersionHelper.serverIsLessThanVersionFourDotFour; -import static com.mongodb.internal.operation.ServerVersionHelper.serverIsLessThanVersionFourDotTwo; import static java.lang.String.format; /** @@ -70,10 +69,6 @@ private static void validateArrayFilters(final WriteConcern writeConcern) { private static void validateWriteRequestHint(final ConnectionDescription connectionDescription, final WriteConcern writeConcern, final WriteRequest request) { if (!writeConcern.isAcknowledged()) { - if (request instanceof UpdateRequest && serverIsLessThanVersionFourDotTwo(connectionDescription)) { - throw new IllegalArgumentException(format("Hint not supported by wire version: %s", - connectionDescription.getMaxWireVersion())); - } if (request instanceof DeleteRequest && serverIsLessThanVersionFourDotFour(connectionDescription)) { throw new IllegalArgumentException(format("Hint not supported by wire version: %s", connectionDescription.getMaxWireVersion())); @@ -82,10 +77,6 @@ private static void validateWriteRequestHint(final ConnectionDescription connect } static void validateHintForFindAndModify(final ConnectionDescription connectionDescription, final WriteConcern writeConcern) { - if (serverIsLessThanVersionFourDotTwo(connectionDescription)) { - throw new IllegalArgumentException(format("Hint not supported by wire version: %s", - connectionDescription.getMaxWireVersion())); - } if (!writeConcern.isAcknowledged() && serverIsLessThanVersionFourDotFour(connectionDescription)) { throw new IllegalArgumentException(format("Hint not supported by wire version: %s", connectionDescription.getMaxWireVersion())); diff --git a/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java b/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java index 68a03410832..62f06e6c6a9 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java +++ b/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java @@ -25,22 +25,19 @@ public final class ServerVersionHelper { public static final int MIN_WIRE_VERSION = 0; - 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; public static final int SEVEN_DOT_ZERO_WIRE_VERSION = 21; - public static final int LATEST_WIRE_VERSION = SEVEN_DOT_ZERO_WIRE_VERSION; + public static final int EIGHT_DOT_ZERO_WIRE_VERSION = 21; + public static final int EARLIEST_WIRE_VERSION = FOUR_DOT_TWO_WIRE_VERSION; + public static final int LATEST_WIRE_VERSION = EIGHT_DOT_ZERO_WIRE_VERSION; public static boolean serverIsAtLeastVersionFourDotFour(final ConnectionDescription description) { return description.getMaxWireVersion() >= FOUR_DOT_FOUR_WIRE_VERSION; } - public static boolean serverIsLessThanVersionFourDotTwo(final ConnectionDescription description) { - return description.getMaxWireVersion() < FOUR_DOT_TWO_WIRE_VERSION; - } - public static boolean serverIsLessThanVersionFourDotFour(final ConnectionDescription description) { return description.getMaxWireVersion() < FOUR_DOT_FOUR_WIRE_VERSION; } diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageSpecification.groovy b/driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageSpecification.groovy index e3351e2eb0f..921ec31a697 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageSpecification.groovy +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageSpecification.groovy @@ -16,7 +16,7 @@ package com.mongodb.internal.connection -import com.mongodb.MongoClientException + import com.mongodb.MongoNamespace import com.mongodb.ReadConcern import com.mongodb.ReadPreference @@ -43,7 +43,6 @@ import spock.lang.Specification 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.LATEST_WIRE_VERSION /** @@ -360,30 +359,6 @@ class CommandMessageSpecification extends Specification { output.close() } - def 'should throw if wire version and sharded cluster does not support transactions'() { - given: - def messageSettings = MessageSettings.builder().serverType(ServerType.SHARD_ROUTER) - .maxWireVersion(FOUR_DOT_ZERO_WIRE_VERSION).build() - def payload = new SplittablePayload(INSERT, [new BsonDocument('a', new BsonInt32(1))], true, fieldNameValidator) - def message = new CommandMessage(namespace, command, fieldNameValidator, ReadPreference.primary(), messageSettings, - false, payload, ClusterConnectionMode.MULTIPLE, null) - def output = new ByteBufferBsonOutput(new SimpleBufferProvider()) - def sessionContext = Stub(SessionContext) { - getReadConcern() >> ReadConcern.DEFAULT - hasActiveTransaction() >> true - } - - when: - message.encode(output, new OperationContext(IgnorableRequestContext.INSTANCE, sessionContext, - Stub(TimeoutContext), null)) - - then: - thrown(MongoClientException) - - cleanup: - output.close() - } - private static BsonDocument getCommandDocument(ByteBufNIO byteBuf, ReplyHeader replyHeader) { new ReplyMessage(new ResponseBuffers(replyHeader, byteBuf), new BsonDocumentCodec(), 0).document } diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageTest.java b/driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageTest.java index 1388ffcef22..533e74f0d23 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageTest.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageTest.java @@ -48,7 +48,6 @@ import static com.mongodb.MongoClientSettings.getDefaultCodecRegistry; import static com.mongodb.client.model.bulk.ClientBulkWriteOptions.clientBulkWriteOptions; import static com.mongodb.internal.mockito.MongoMockito.mock; -import static com.mongodb.internal.operation.ServerVersionHelper.FOUR_DOT_ZERO_WIRE_VERSION; import static com.mongodb.internal.operation.ServerVersionHelper.LATEST_WIRE_VERSION; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; @@ -69,7 +68,7 @@ void encodeShouldThrowTimeoutExceptionWhenTimeoutContextIsCalled() { //given CommandMessage commandMessage = new CommandMessage(NAMESPACE, COMMAND, NoOpFieldNameValidator.INSTANCE, ReadPreference.primary(), MessageSettings.builder() - .maxWireVersion(FOUR_DOT_ZERO_WIRE_VERSION) + .maxWireVersion(LATEST_WIRE_VERSION) .serverType(ServerType.REPLICA_SET_SECONDARY) .sessionSupported(true) .build(), @@ -96,7 +95,7 @@ void encodeShouldNotAddExtraElementsFromTimeoutContextWhenConnectedToMongoCrypt( //given CommandMessage commandMessage = new CommandMessage(NAMESPACE, COMMAND, NoOpFieldNameValidator.INSTANCE, ReadPreference.primary(), MessageSettings.builder() - .maxWireVersion(FOUR_DOT_ZERO_WIRE_VERSION) + .maxWireVersion(LATEST_WIRE_VERSION) .serverType(ServerType.REPLICA_SET_SECONDARY) .sessionSupported(true) .cryptd(true) diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/ServerDiscoveryAndMonitoringTest.java b/driver-core/src/test/unit/com/mongodb/internal/connection/ServerDiscoveryAndMonitoringTest.java index 701e28d3664..d4737fe6d71 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/ServerDiscoveryAndMonitoringTest.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/ServerDiscoveryAndMonitoringTest.java @@ -23,6 +23,7 @@ import org.bson.BsonDocument; import org.bson.BsonNull; import org.bson.BsonValue; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -39,16 +40,25 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeFalse; // See https://github.com/mongodb/specifications/tree/master/source/server-discovery-and-monitoring/tests @RunWith(Parameterized.class) public class ServerDiscoveryAndMonitoringTest extends AbstractServerDiscoveryAndMonitoringTest { + private final String description; + public ServerDiscoveryAndMonitoringTest(final String description, final BsonDocument definition) { super(definition); + this.description = description; init(serverAddress -> NO_OP_SERVER_LISTENER, NO_OP_CLUSTER_LISTENER); } + @Before + public void setUp() { + assumeFalse(description.startsWith("pre-42")); + } + @Test public void shouldPassAllOutcomes() { for (BsonValue phase : getDefinition().getArray("phases")) { diff --git a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/crypt/CryptConnection.java b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/crypt/CryptConnection.java index 23c6a060749..c05bfb663f2 100644 --- a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/crypt/CryptConnection.java +++ b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/crypt/CryptConnection.java @@ -16,15 +16,14 @@ package com.mongodb.reactivestreams.client.internal.crypt; -import com.mongodb.MongoClientException; import com.mongodb.ReadPreference; import com.mongodb.connection.ConnectionDescription; import com.mongodb.internal.async.SingleResultCallback; import com.mongodb.internal.connection.AsyncConnection; import com.mongodb.internal.connection.Connection; -import com.mongodb.internal.connection.MessageSettings; import com.mongodb.internal.connection.MessageSequences; import com.mongodb.internal.connection.MessageSequences.EmptyMessageSequences; +import com.mongodb.internal.connection.MessageSettings; import com.mongodb.internal.connection.OperationContext; import com.mongodb.internal.connection.SplittablePayload; import com.mongodb.internal.connection.SplittablePayloadBsonWriter; @@ -54,7 +53,6 @@ import java.util.function.Function; import static com.mongodb.assertions.Assertions.fail; -import static com.mongodb.internal.operation.ServerVersionHelper.serverIsLessThanVersionFourDotTwo; import static com.mongodb.reactivestreams.client.internal.MongoOperationPublisher.sinkToCallback; import static org.bson.codecs.configuration.CodecRegistries.fromProviders; @@ -105,11 +103,6 @@ public void commandAsync(final String database, final BsonDocument command, final OperationContext operationContext, final boolean responseExpected, final MessageSequences sequences, final SingleResultCallback callback) { - if (serverIsLessThanVersionFourDotTwo(wrapped.getDescription())) { - callback.onResult(null, new MongoClientException("Auto-encryption requires a minimum MongoDB version of 4.2")); - return; - } - try { SplittablePayload payload = null; FieldNameValidator payloadFieldNameValidator = null; diff --git a/driver-sync/src/main/com/mongodb/client/internal/CryptConnection.java b/driver-sync/src/main/com/mongodb/client/internal/CryptConnection.java index a62aa68783e..803df89a6b6 100644 --- a/driver-sync/src/main/com/mongodb/client/internal/CryptConnection.java +++ b/driver-sync/src/main/com/mongodb/client/internal/CryptConnection.java @@ -16,13 +16,12 @@ package com.mongodb.client.internal; -import com.mongodb.MongoClientException; import com.mongodb.ReadPreference; import com.mongodb.connection.ConnectionDescription; import com.mongodb.internal.connection.Connection; -import com.mongodb.internal.connection.MessageSettings; import com.mongodb.internal.connection.MessageSequences; import com.mongodb.internal.connection.MessageSequences.EmptyMessageSequences; +import com.mongodb.internal.connection.MessageSettings; import com.mongodb.internal.connection.OperationContext; import com.mongodb.internal.connection.SplittablePayload; import com.mongodb.internal.connection.SplittablePayloadBsonWriter; @@ -50,7 +49,6 @@ import java.util.Map; import static com.mongodb.assertions.Assertions.fail; -import static com.mongodb.internal.operation.ServerVersionHelper.serverIsLessThanVersionFourDotTwo; import static org.bson.codecs.configuration.CodecRegistries.fromProviders; /** @@ -95,10 +93,6 @@ public T command(final String database, final BsonDocument command, final Fi @Nullable final ReadPreference readPreference, final Decoder commandResultDecoder, final OperationContext operationContext, final boolean responseExpected, final MessageSequences sequences) { - if (serverIsLessThanVersionFourDotTwo(wrapped.getDescription())) { - throw new MongoClientException("Auto-encryption requires a minimum MongoDB version of 4.2"); - } - SplittablePayload payload = null; FieldNameValidator payloadFieldNameValidator = null; if (sequences instanceof SplittablePayload) { From 5e14e04880b15074d7a5fdfe5a8b552a1da8a5a0 Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Fri, 28 Mar 2025 17:52:12 -0400 Subject: [PATCH 2/5] Fixed copy pasta --- .../com/mongodb/internal/operation/ServerVersionHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java b/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java index 62f06e6c6a9..4b4973f9b2f 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java +++ b/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java @@ -30,7 +30,7 @@ public final class ServerVersionHelper { public static final int FIVE_DOT_ZERO_WIRE_VERSION = 12; public static final int SIX_DOT_ZERO_WIRE_VERSION = 17; public static final int SEVEN_DOT_ZERO_WIRE_VERSION = 21; - public static final int EIGHT_DOT_ZERO_WIRE_VERSION = 21; + public static final int EIGHT_DOT_ZERO_WIRE_VERSION = 25; public static final int EARLIEST_WIRE_VERSION = FOUR_DOT_TWO_WIRE_VERSION; public static final int LATEST_WIRE_VERSION = EIGHT_DOT_ZERO_WIRE_VERSION; From 39aab4caa5b6105b647110ceb75c03b435d5fa93 Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Fri, 28 Mar 2025 17:55:20 -0400 Subject: [PATCH 3/5] Fixed an old error in 5.0 wire version --- .../com/mongodb/internal/operation/ServerVersionHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java b/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java index 4b4973f9b2f..71dd77a9c7e 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java +++ b/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java @@ -27,7 +27,7 @@ public final class ServerVersionHelper { public static final int MIN_WIRE_VERSION = 0; 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 FIVE_DOT_ZERO_WIRE_VERSION = 13; public static final int SIX_DOT_ZERO_WIRE_VERSION = 17; public static final int SEVEN_DOT_ZERO_WIRE_VERSION = 21; public static final int EIGHT_DOT_ZERO_WIRE_VERSION = 25; From fe9700721075eefbca979f455dbb9612cb78ab15 Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Mon, 31 Mar 2025 09:47:07 -0400 Subject: [PATCH 4/5] Removed EARLIEST_WIRE_VERSION Renamed MIN_WIRE_VERSION to UNKNOWN_WIRE_VERSION --- .../internal/connection/CommandMessage.java | 4 ++-- .../internal/connection/MessageSettings.java | 4 +++- .../internal/operation/AggregateOperation.java | 4 ++-- .../internal/operation/FindOperation.java | 4 ++-- .../internal/operation/ServerVersionHelper.java | 3 +-- .../AggregateOperationSpecification.groovy | 6 +++--- .../CountDocumentsOperationSpecification.groovy | 6 +++--- .../DistinctOperationSpecification.groovy | 6 +++--- .../operation/FindOperationSpecification.groovy | 10 +++++----- ...ithInlineResultsOperationSpecification.groovy | 6 +++--- ...perationReadConcernHelperSpecification.groovy | 16 ++++++++-------- .../ReadConcernHelperSpecification.groovy | 13 +++++++------ 12 files changed, 42 insertions(+), 40 deletions(-) diff --git a/driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java b/driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java index fa72eaf9959..12543e92ccb 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java +++ b/driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java @@ -60,7 +60,7 @@ import static com.mongodb.internal.connection.ByteBufBsonDocument.createList; import static com.mongodb.internal.connection.ByteBufBsonDocument.createOne; import static com.mongodb.internal.connection.ReadConcernHelper.getReadConcernDocument; -import static com.mongodb.internal.operation.ServerVersionHelper.EARLIEST_WIRE_VERSION; +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION; /** * A command message that uses OP_MSG or OP_QUERY to send the command. @@ -408,7 +408,7 @@ private static OpCode getOpCode(final MessageSettings settings, final ClusterCon } private static boolean isServerVersionKnown(final MessageSettings settings) { - return settings.getMaxWireVersion() >= EARLIEST_WIRE_VERSION; + return settings.getMaxWireVersion() != UNKNOWN_WIRE_VERSION; } @FunctionalInterface diff --git a/driver-core/src/main/com/mongodb/internal/connection/MessageSettings.java b/driver-core/src/main/com/mongodb/internal/connection/MessageSettings.java index 91fd862ce4b..51587e8f91d 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/MessageSettings.java +++ b/driver-core/src/main/com/mongodb/internal/connection/MessageSettings.java @@ -20,6 +20,8 @@ import com.mongodb.annotations.NotThreadSafe; import com.mongodb.connection.ServerType; +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION; + /** * The message settings * @@ -75,7 +77,7 @@ public static final class Builder { private int maxDocumentSize = DEFAULT_MAX_DOCUMENT_SIZE; private int maxMessageSize = DEFAULT_MAX_MESSAGE_SIZE; private int maxBatchCount = DEFAULT_MAX_BATCH_COUNT; - private int maxWireVersion; + private int maxWireVersion = UNKNOWN_WIRE_VERSION; private ServerType serverType; private boolean sessionSupported; private boolean cryptd; diff --git a/driver-core/src/main/com/mongodb/internal/operation/AggregateOperation.java b/driver-core/src/main/com/mongodb/internal/operation/AggregateOperation.java index f50304480b5..1f25bc87bf9 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/AggregateOperation.java +++ b/driver-core/src/main/com/mongodb/internal/operation/AggregateOperation.java @@ -34,7 +34,7 @@ import static com.mongodb.internal.connection.CommandHelper.applyMaxTimeMS; import static com.mongodb.internal.operation.ExplainHelper.asExplainCommand; -import static com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION; +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION; /** * An operation that executes an aggregation query. @@ -157,7 +157,7 @@ public AsyncReadOperation asAsyncExplainableOperation(@Nullable final Exp CommandReadOperation createExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder resultDecoder) { return new CommandReadOperation<>(getNamespace().getDatabaseName(), (operationContext, serverDescription, connectionDescription) -> { - BsonDocument command = wrapped.getCommand(operationContext, MIN_WIRE_VERSION); + BsonDocument command = wrapped.getCommand(operationContext, UNKNOWN_WIRE_VERSION); applyMaxTimeMS(operationContext.getTimeoutContext(), command); return asExplainCommand(command, verbosity); }, resultDecoder); diff --git a/driver-core/src/main/com/mongodb/internal/operation/FindOperation.java b/driver-core/src/main/com/mongodb/internal/operation/FindOperation.java index 4ef5c2907e1..4f834bee349 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/FindOperation.java +++ b/driver-core/src/main/com/mongodb/internal/operation/FindOperation.java @@ -56,7 +56,7 @@ import static com.mongodb.internal.operation.OperationHelper.canRetryRead; import static com.mongodb.internal.operation.OperationHelper.setNonTailableCursorMaxTimeSupplier; import static com.mongodb.internal.operation.OperationReadConcernHelper.appendReadConcernToCommand; -import static com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION; +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION; import static com.mongodb.internal.operation.SyncOperationHelper.CommandReadTransformer; import static com.mongodb.internal.operation.SyncOperationHelper.createReadCommandAndExecute; import static com.mongodb.internal.operation.SyncOperationHelper.decorateReadWithRetries; @@ -366,7 +366,7 @@ public AsyncReadOperation asAsyncExplainableOperation(@Nullable final Exp CommandReadOperation createExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder resultDecoder) { return new CommandReadOperation<>(getNamespace().getDatabaseName(), (operationContext, serverDescription, connectionDescription) -> { - BsonDocument command = getCommand(operationContext, MIN_WIRE_VERSION); + BsonDocument command = getCommand(operationContext, UNKNOWN_WIRE_VERSION); applyMaxTimeMS(operationContext.getTimeoutContext(), command); return asExplainCommand(command, verbosity); }, resultDecoder); diff --git a/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java b/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java index 71dd77a9c7e..093d48e3781 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java +++ b/driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java @@ -24,14 +24,13 @@ */ public final class ServerVersionHelper { - public static final int MIN_WIRE_VERSION = 0; + public static final int UNKNOWN_WIRE_VERSION = 0; 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 = 13; public static final int SIX_DOT_ZERO_WIRE_VERSION = 17; public static final int SEVEN_DOT_ZERO_WIRE_VERSION = 21; public static final int EIGHT_DOT_ZERO_WIRE_VERSION = 25; - public static final int EARLIEST_WIRE_VERSION = FOUR_DOT_TWO_WIRE_VERSION; public static final int LATEST_WIRE_VERSION = EIGHT_DOT_ZERO_WIRE_VERSION; public static boolean serverIsAtLeastVersionFourDotFour(final ConnectionDescription description) { diff --git a/driver-core/src/test/functional/com/mongodb/internal/operation/AggregateOperationSpecification.groovy b/driver-core/src/test/functional/com/mongodb/internal/operation/AggregateOperationSpecification.groovy index a3e309a1f5f..b06c080e185 100644 --- a/driver-core/src/test/functional/com/mongodb/internal/operation/AggregateOperationSpecification.groovy +++ b/driver-core/src/test/functional/com/mongodb/internal/operation/AggregateOperationSpecification.groovy @@ -65,7 +65,7 @@ import static com.mongodb.ExplainVerbosity.QUERY_PLANNER import static com.mongodb.connection.ServerType.STANDALONE import static com.mongodb.internal.connection.ServerHelper.waitForLastRelease import static com.mongodb.internal.operation.OperationReadConcernHelper.appendReadConcernToCommand -import static com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION class AggregateOperationSpecification extends OperationFunctionalSpecification { @@ -386,7 +386,7 @@ class AggregateOperationSpecification extends OperationFunctionalSpecification { def commandDocument = new BsonDocument('aggregate', new BsonString(getCollectionName())) .append('pipeline', new BsonArray()) .append('cursor', new BsonDocument()) - appendReadConcernToCommand(operationContext.getSessionContext(), MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(operationContext.getSessionContext(), UNKNOWN_WIRE_VERSION, commandDocument) def operation = new AggregateOperation(getNamespace(), [], new DocumentCodec()) @@ -427,7 +427,7 @@ class AggregateOperationSpecification extends OperationFunctionalSpecification { def commandDocument = new BsonDocument('aggregate', new BsonString(getCollectionName())) .append('pipeline', new BsonArray()) .append('cursor', new BsonDocument()) - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new AggregateOperation(getNamespace(), [], new DocumentCodec()) diff --git a/driver-core/src/test/functional/com/mongodb/internal/operation/CountDocumentsOperationSpecification.groovy b/driver-core/src/test/functional/com/mongodb/internal/operation/CountDocumentsOperationSpecification.groovy index 26d7d11bc6e..564b2f96e26 100644 --- a/driver-core/src/test/functional/com/mongodb/internal/operation/CountDocumentsOperationSpecification.groovy +++ b/driver-core/src/test/functional/com/mongodb/internal/operation/CountDocumentsOperationSpecification.groovy @@ -50,7 +50,7 @@ import static com.mongodb.ClusterFixture.getBinding import static com.mongodb.ClusterFixture.serverVersionAtLeast import static com.mongodb.connection.ServerType.STANDALONE import static com.mongodb.internal.operation.OperationReadConcernHelper.appendReadConcernToCommand -import static com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION class CountDocumentsOperationSpecification extends OperationFunctionalSpecification { @@ -274,7 +274,7 @@ class CountDocumentsOperationSpecification extends OperationFunctionalSpecificat def commandDocument = new BsonDocument('aggregate', new BsonString(getCollectionName())) .append('pipeline', pipeline) .append('cursor', new BsonDocument()) - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new CountDocumentsOperation(getNamespace()) @@ -314,7 +314,7 @@ class CountDocumentsOperationSpecification extends OperationFunctionalSpecificat def commandDocument = new BsonDocument('aggregate', new BsonString(getCollectionName())) .append('pipeline', pipeline) .append('cursor', new BsonDocument()) - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new CountDocumentsOperation(getNamespace()) diff --git a/driver-core/src/test/functional/com/mongodb/internal/operation/DistinctOperationSpecification.groovy b/driver-core/src/test/functional/com/mongodb/internal/operation/DistinctOperationSpecification.groovy index 587e05e1d0c..27f9507def4 100644 --- a/driver-core/src/test/functional/com/mongodb/internal/operation/DistinctOperationSpecification.groovy +++ b/driver-core/src/test/functional/com/mongodb/internal/operation/DistinctOperationSpecification.groovy @@ -56,7 +56,7 @@ import static com.mongodb.ClusterFixture.executeAsync import static com.mongodb.ClusterFixture.serverVersionLessThan import static com.mongodb.connection.ServerType.STANDALONE import static com.mongodb.internal.operation.OperationReadConcernHelper.appendReadConcernToCommand -import static com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION import static org.bson.codecs.configuration.CodecRegistries.fromProviders class DistinctOperationSpecification extends OperationFunctionalSpecification { @@ -240,7 +240,7 @@ class DistinctOperationSpecification extends OperationFunctionalSpecification { source.operationContext >> operationContext def commandDocument = new BsonDocument('distinct', new BsonString(getCollectionName())) .append('key', new BsonString('str')) - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new DistinctOperation(getNamespace(), 'str', new StringCodec()) @@ -279,7 +279,7 @@ class DistinctOperationSpecification extends OperationFunctionalSpecification { source.retain() >> source def commandDocument = new BsonDocument('distinct', new BsonString(getCollectionName())) .append('key', new BsonString('str')) - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new DistinctOperation(getNamespace(), 'str', new StringCodec()) diff --git a/driver-core/src/test/functional/com/mongodb/internal/operation/FindOperationSpecification.groovy b/driver-core/src/test/functional/com/mongodb/internal/operation/FindOperationSpecification.groovy index f70cac7b6ad..df1fae76bc4 100644 --- a/driver-core/src/test/functional/com/mongodb/internal/operation/FindOperationSpecification.groovy +++ b/driver-core/src/test/functional/com/mongodb/internal/operation/FindOperationSpecification.groovy @@ -67,7 +67,7 @@ import static com.mongodb.CursorType.Tailable import static com.mongodb.CursorType.TailableAwait import static com.mongodb.connection.ServerType.STANDALONE import static com.mongodb.internal.operation.OperationReadConcernHelper.appendReadConcernToCommand -import static com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION import static org.junit.Assert.assertEquals class FindOperationSpecification extends OperationFunctionalSpecification { @@ -498,7 +498,7 @@ class FindOperationSpecification extends OperationFunctionalSpecification { source.retain() >> source source.operationContext >> operationContext def commandDocument = new BsonDocument('find', new BsonString(getCollectionName())) - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new FindOperation(getNamespace(), new DocumentCodec()) @@ -538,7 +538,7 @@ class FindOperationSpecification extends OperationFunctionalSpecification { source.getConnection(_) >> { it[0].onResult(connection, null) } source.retain() >> source def commandDocument = new BsonDocument('find', new BsonString(getCollectionName())) - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new FindOperation(getNamespace(), new DocumentCodec()) @@ -579,7 +579,7 @@ class FindOperationSpecification extends OperationFunctionalSpecification { source.retain() >> source source.operationContext >> operationContext def commandDocument = new BsonDocument('find', new BsonString(getCollectionName())).append('allowDiskUse', BsonBoolean.TRUE) - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new FindOperation(getNamespace(), new DocumentCodec()).allowDiskUse(true) @@ -619,7 +619,7 @@ class FindOperationSpecification extends OperationFunctionalSpecification { source.getConnection(_) >> { it[0].onResult(connection, null) } source.retain() >> source def commandDocument = new BsonDocument('find', new BsonString(getCollectionName())).append('allowDiskUse', BsonBoolean.TRUE) - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new FindOperation(getNamespace(), new DocumentCodec()).allowDiskUse(true) diff --git a/driver-core/src/test/functional/com/mongodb/internal/operation/MapReduceWithInlineResultsOperationSpecification.groovy b/driver-core/src/test/functional/com/mongodb/internal/operation/MapReduceWithInlineResultsOperationSpecification.groovy index 3289f10f578..ece8045c578 100644 --- a/driver-core/src/test/functional/com/mongodb/internal/operation/MapReduceWithInlineResultsOperationSpecification.groovy +++ b/driver-core/src/test/functional/com/mongodb/internal/operation/MapReduceWithInlineResultsOperationSpecification.groovy @@ -50,7 +50,7 @@ import static com.mongodb.ClusterFixture.executeAsync import static com.mongodb.ClusterFixture.serverVersionLessThan import static com.mongodb.connection.ServerType.STANDALONE import static com.mongodb.internal.operation.OperationReadConcernHelper.appendReadConcernToCommand -import static com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION class MapReduceWithInlineResultsOperationSpecification extends OperationFunctionalSpecification { private final bsonDocumentCodec = new BsonDocumentCodec() @@ -234,7 +234,7 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction "reduce" : { "$code" : "function(key, values){ }" }, "out" : { "inline" : 1 }, }''') - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new MapReduceWithInlineResultsOperation(helper.namespace, new BsonJavaScript('function(){ }'), new BsonJavaScript('function(key, values){ }'), bsonDocumentCodec) @@ -283,7 +283,7 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction "reduce" : { "$code" : "function(key, values){ }" }, "out" : { "inline" : 1 }, }''') - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) def operation = new MapReduceWithInlineResultsOperation(helper.namespace, new BsonJavaScript('function(){ }'), new BsonJavaScript('function(key, values){ }'), bsonDocumentCodec) diff --git a/driver-core/src/test/functional/com/mongodb/internal/operation/OperationReadConcernHelperSpecification.groovy b/driver-core/src/test/functional/com/mongodb/internal/operation/OperationReadConcernHelperSpecification.groovy index 75358db9e9c..331690a830b 100644 --- a/driver-core/src/test/functional/com/mongodb/internal/operation/OperationReadConcernHelperSpecification.groovy +++ b/driver-core/src/test/functional/com/mongodb/internal/operation/OperationReadConcernHelperSpecification.groovy @@ -24,14 +24,14 @@ import org.bson.BsonTimestamp import spock.lang.Specification import static com.mongodb.internal.operation.OperationReadConcernHelper.appendReadConcernToCommand -import static com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION class OperationReadConcernHelperSpecification extends Specification { def 'should throw IllegalArgumentException if command document is null'() { when: - appendReadConcernToCommand(Stub(SessionContext), MIN_WIRE_VERSION, null) + appendReadConcernToCommand(Stub(SessionContext), UNKNOWN_WIRE_VERSION, null) then: thrown(IllegalArgumentException) @@ -39,7 +39,7 @@ class OperationReadConcernHelperSpecification extends Specification { def 'should throw IllegalArgumentException if session context is null'() { when: - appendReadConcernToCommand(null, MIN_WIRE_VERSION, new BsonDocument()) + appendReadConcernToCommand(null, UNKNOWN_WIRE_VERSION, new BsonDocument()) then: thrown(IllegalArgumentException) @@ -56,7 +56,7 @@ class OperationReadConcernHelperSpecification extends Specification { def commandDocument = new BsonDocument() when: - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) then: commandDocument == new BsonDocument('readConcern', @@ -74,7 +74,7 @@ class OperationReadConcernHelperSpecification extends Specification { def commandDocument = new BsonDocument() when: - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) then: commandDocument == new BsonDocument('readConcern', @@ -91,7 +91,7 @@ class OperationReadConcernHelperSpecification extends Specification { def commandDocument = new BsonDocument() when: - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) then: commandDocument == new BsonDocument('readConcern', @@ -107,7 +107,7 @@ class OperationReadConcernHelperSpecification extends Specification { def commandDocument = new BsonDocument() when: - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) then: commandDocument == new BsonDocument() @@ -123,7 +123,7 @@ class OperationReadConcernHelperSpecification extends Specification { def commandDocument = new BsonDocument() when: - appendReadConcernToCommand(sessionContext, MIN_WIRE_VERSION, commandDocument) + appendReadConcernToCommand(sessionContext, UNKNOWN_WIRE_VERSION, commandDocument) then: commandDocument == new BsonDocument('readConcern', diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/ReadConcernHelperSpecification.groovy b/driver-core/src/test/unit/com/mongodb/internal/connection/ReadConcernHelperSpecification.groovy index 3d52d7fff03..924f8dee4d6 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/ReadConcernHelperSpecification.groovy +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/ReadConcernHelperSpecification.groovy @@ -24,13 +24,13 @@ import org.bson.BsonTimestamp import spock.lang.Specification import static com.mongodb.internal.connection.ReadConcernHelper.getReadConcernDocument -import static com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION class ReadConcernHelperSpecification extends Specification { def 'should throw IllegalArgumentException if session context is null'() { when: - getReadConcernDocument(null, MIN_WIRE_VERSION) + getReadConcernDocument(null, UNKNOWN_WIRE_VERSION) then: thrown(IllegalArgumentException) @@ -46,7 +46,7 @@ class ReadConcernHelperSpecification extends Specification { } expect: - getReadConcernDocument(sessionContext, MIN_WIRE_VERSION) == new BsonDocument('level', new BsonString('majority')) + getReadConcernDocument(sessionContext, UNKNOWN_WIRE_VERSION) == new BsonDocument('level', new BsonString('majority')) .append('afterClusterTime', operationTime) } @@ -60,7 +60,8 @@ class ReadConcernHelperSpecification extends Specification { } expect: - getReadConcernDocument(sessionContext, MIN_WIRE_VERSION) == new BsonDocument(new BsonDocument('afterClusterTime', operationTime)) + getReadConcernDocument(sessionContext, UNKNOWN_WIRE_VERSION) == + new BsonDocument(new BsonDocument('afterClusterTime', operationTime)) } def 'should not add afterClusterTime to ReadConcern when session is not causally consistent'() { @@ -72,7 +73,7 @@ class ReadConcernHelperSpecification extends Specification { } expect: - getReadConcernDocument(sessionContext, MIN_WIRE_VERSION) == new BsonDocument('level', new BsonString('majority')) + getReadConcernDocument(sessionContext, UNKNOWN_WIRE_VERSION) == new BsonDocument('level', new BsonString('majority')) } def 'should not add afterClusterTime to ReadConcern when operation time is null'() { @@ -84,6 +85,6 @@ class ReadConcernHelperSpecification extends Specification { } expect: - getReadConcernDocument(sessionContext, MIN_WIRE_VERSION) == new BsonDocument('level', new BsonString('majority')) + getReadConcernDocument(sessionContext, UNKNOWN_WIRE_VERSION) == new BsonDocument('level', new BsonString('majority')) } } From 34e0511d9dfc4cb3fab8d5e71c6ad46664d3b733 Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Mon, 31 Mar 2025 10:31:04 -0400 Subject: [PATCH 5/5] Replace numeric literal with constant --- .../src/main/com/mongodb/connection/ConnectionDescription.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/driver-core/src/main/com/mongodb/connection/ConnectionDescription.java b/driver-core/src/main/com/mongodb/connection/ConnectionDescription.java index 8b68cd6f9c2..c8c213398b7 100644 --- a/driver-core/src/main/com/mongodb/connection/ConnectionDescription.java +++ b/driver-core/src/main/com/mongodb/connection/ConnectionDescription.java @@ -29,6 +29,7 @@ import static com.mongodb.assertions.Assertions.notNull; import static com.mongodb.connection.ServerDescription.getDefaultMaxDocumentSize; +import static com.mongodb.internal.operation.ServerVersionHelper.UNKNOWN_WIRE_VERSION; /** * A description of a connection to a MongoDB server. @@ -57,7 +58,7 @@ public class ConnectionDescription { * @param serverId the server address */ public ConnectionDescription(final ServerId serverId) { - this(new ConnectionId(serverId), 0, ServerType.UNKNOWN, DEFAULT_MAX_WRITE_BATCH_SIZE, + this(new ConnectionId(serverId), UNKNOWN_WIRE_VERSION, ServerType.UNKNOWN, DEFAULT_MAX_WRITE_BATCH_SIZE, getDefaultMaxDocumentSize(), DEFAULT_MAX_MESSAGE_SIZE, Collections.emptyList()); }