diff --git a/driver-core/src/main/com/mongodb/ClientEncryptionSettings.java b/driver-core/src/main/com/mongodb/ClientEncryptionSettings.java
index df4fa117ffd..4375d22676a 100644
--- a/driver-core/src/main/com/mongodb/ClientEncryptionSettings.java
+++ b/driver-core/src/main/com/mongodb/ClientEncryptionSettings.java
@@ -16,9 +16,7 @@
package com.mongodb;
-import com.mongodb.annotations.Alpha;
import com.mongodb.annotations.NotThreadSafe;
-import com.mongodb.annotations.Reason;
import com.mongodb.lang.Nullable;
import javax.net.ssl.SSLContext;
@@ -29,9 +27,7 @@
import static com.mongodb.assertions.Assertions.assertTrue;
import static com.mongodb.assertions.Assertions.notNull;
-import static com.mongodb.internal.TimeoutSettings.convertAndValidateTimeout;
import static java.util.Collections.unmodifiableMap;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
/**
* The client-side settings for data key creation and explicit encryption.
@@ -52,8 +48,6 @@ public final class ClientEncryptionSettings {
@Nullable
private final KmsConnectCallback kmsConnectCallback;
@Nullable
- private final Long timeoutMS;
- @Nullable
private final Long keyExpirationMS;
/**
@@ -70,8 +64,6 @@ public static final class Builder {
@Nullable
private KmsConnectCallback kmsConnectCallback;
@Nullable
- private Long timeoutMS;
- @Nullable
private Long keyExpirationMS;
/**
@@ -172,48 +164,6 @@ public Builder keyExpiration(@Nullable final Long keyExpiration, final TimeUnit
return this;
}
- /**
- * Sets the time limit for the full execution of an operation.
- *
- *
- *
{@code null} means that the timeout mechanism for operations will defer to using:
- *
- *
{@code waitQueueTimeoutMS}: The maximum wait time in milliseconds that a thread may wait for a connection to become
- * available
- *
{@code socketTimeoutMS}: How long a send or receive on a socket can take before timing out.
- *
{@code wTimeoutMS}: How long the server will wait for the write concern to be fulfilled before timing out.
- *
{@code maxTimeMS}: The cumulative time limit for processing operations on a cursor.
- * See: cursor.maxTimeMS.
- *
{@code maxCommitTimeMS}: The maximum amount of time to allow a single {@code commitTransaction} command to execute.
- * See: {@link TransactionOptions#getMaxCommitTime}.
- *
- *
- *
{@code 0} means infinite timeout.
- *
{@code > 0} The time limit to use for the full execution of an operation.
- *
- *
- *
Note:
- *
- *
The timeout set through this method overrides the timeout defined in the key vault client settings
- * specified in {@link #keyVaultMongoClientSettings(MongoClientSettings)}.
- * Essentially, for operations that require accessing the key vault, the remaining timeout from the initial operation
- * determines the duration allowed for key vault access.
- *
When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
- * operation might not be timed out when expected. This limitation does not apply to the reactive streams API.
- *
- *
- * @param timeout the timeout
- * @param timeUnit the time unit
- * @return this
- * @since 5.2
- * @see #getTimeout
- */
- @Alpha(Reason.CLIENT)
- public ClientEncryptionSettings.Builder timeout(final long timeout, final TimeUnit timeUnit) {
- this.timeoutMS = convertAndValidateTimeout(timeout, timeUnit);
- return this;
- }
-
/**
* Build an instance of {@code ClientEncryptionSettings}.
*
@@ -381,49 +331,6 @@ public Long getKeyExpiration(final TimeUnit timeUnit) {
return keyExpirationMS == null ? null : timeUnit.convert(keyExpirationMS, TimeUnit.MILLISECONDS);
}
- /**
- * The time limit for the full execution of an operation.
- *
- *
If set the following deprecated options will be ignored:
- * {@code waitQueueTimeoutMS}, {@code socketTimeoutMS}, {@code wTimeoutMS}, {@code maxTimeMS} and {@code maxCommitTimeMS}
- *
- *
- *
{@code null} means that the timeout mechanism for operations will defer to using:
- *
- *
{@code waitQueueTimeoutMS}: The maximum wait time in milliseconds that a thread may wait for a connection to become
- * available
- *
{@code socketTimeoutMS}: How long a send or receive on a socket can take before timing out.
- *
{@code wTimeoutMS}: How long the server will wait for the write concern to be fulfilled before timing out.
- *
{@code maxTimeMS}: The cumulative time limit for processing operations on a cursor.
- * See: cursor.maxTimeMS.
- *
{@code maxCommitTimeMS}: The maximum amount of time to allow a single {@code commitTransaction} command to execute.
- * See: {@link TransactionOptions#getMaxCommitTime}.
- *
- *
- *
{@code 0} means infinite timeout.
- *
{@code > 0} The time limit to use for the full execution of an operation.
- *
- *
- *
Note:
- *
- *
The timeout set through this method overrides the timeout defined in the key vault client settings
- * specified in {@link Builder#keyVaultMongoClientSettings(MongoClientSettings)}.
- * Essentially, for operations that require accessing the key vault, the remaining timeout from the initial operation
- * determines the duration allowed for key vault access.
- *
When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
- * operation might not be timed out when expected. This limitation does not apply to the reactive streams API.
- *
- *
- * @param timeUnit the time unit
- * @return the timeout in the given time unit
- * @since 5.2
- */
- @Alpha(Reason.CLIENT)
- @Nullable
- public Long getTimeout(final TimeUnit timeUnit) {
- return timeoutMS == null ? null : timeUnit.convert(timeoutMS, MILLISECONDS);
- }
-
private ClientEncryptionSettings(final Builder builder) {
this.keyVaultMongoClientSettings = notNull("keyVaultMongoClientSettings", builder.keyVaultMongoClientSettings);
this.keyVaultNamespace = notNull("keyVaultNamespace", builder.keyVaultNamespace);
@@ -431,7 +338,6 @@ private ClientEncryptionSettings(final Builder builder) {
this.kmsProviderPropertySuppliers = notNull("kmsProviderPropertySuppliers", builder.kmsProviderPropertySuppliers);
this.kmsProviderSslContextMap = notNull("kmsProviderSslContextMap", builder.kmsProviderSslContextMap);
this.kmsConnectCallback = builder.kmsConnectCallback;
- this.timeoutMS = builder.timeoutMS;
this.keyExpirationMS = builder.keyExpirationMS;
}
diff --git a/driver-core/src/main/com/mongodb/ClientSessionOptions.java b/driver-core/src/main/com/mongodb/ClientSessionOptions.java
index 0f2f6796db4..6d3d2b17167 100644
--- a/driver-core/src/main/com/mongodb/ClientSessionOptions.java
+++ b/driver-core/src/main/com/mongodb/ClientSessionOptions.java
@@ -16,19 +16,14 @@
package com.mongodb;
-import com.mongodb.annotations.Alpha;
import com.mongodb.annotations.Immutable;
import com.mongodb.annotations.NotThreadSafe;
-import com.mongodb.annotations.Reason;
import com.mongodb.lang.Nullable;
import com.mongodb.session.ClientSession;
import java.util.Objects;
-import java.util.concurrent.TimeUnit;
import static com.mongodb.assertions.Assertions.notNull;
-import static com.mongodb.internal.TimeoutSettings.convertAndValidateTimeout;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
/**
* The options to apply to a {@code ClientSession}.
@@ -43,7 +38,6 @@ public final class ClientSessionOptions {
private final Boolean causallyConsistent;
private final Boolean snapshot;
- private final Long defaultTimeoutMS;
private final TransactionOptions defaultTransactionOptions;
/**
@@ -83,30 +77,6 @@ public TransactionOptions getDefaultTransactionOptions() {
return defaultTransactionOptions;
}
- /**
- * Gets the default time limit for the following operations executed on the session:
- *
- *
- *
{@code commitTransaction}
- *
{@code abortTransaction}
- *
{@code withTransaction}
- *
{@code close}
- *
- *
- *
Note: When using synchronous API, this timeout does not limit socket writes, therefore
- * there is a possibility that the operation might not be timed out when expected. This limitation does not
- * apply to the reactive streams API.
- *
- * @param timeUnit the time unit
- * @return the default timeout
- * @since 5.2
- */
- @Alpha(Reason.CLIENT)
- @Nullable
- public Long getDefaultTimeout(final TimeUnit timeUnit) {
- return defaultTimeoutMS == null ? null : timeUnit.convert(defaultTimeoutMS, MILLISECONDS);
- }
-
@Override
public boolean equals(final Object o) {
if (this == o) {
@@ -118,13 +88,12 @@ public boolean equals(final Object o) {
final ClientSessionOptions that = (ClientSessionOptions) o;
return Objects.equals(causallyConsistent, that.causallyConsistent)
&& Objects.equals(snapshot, that.snapshot)
- && Objects.equals(defaultTimeoutMS, that.defaultTimeoutMS)
&& Objects.equals(defaultTransactionOptions, that.defaultTransactionOptions);
}
@Override
public int hashCode() {
- return Objects.hash(causallyConsistent, snapshot, defaultTimeoutMS, defaultTransactionOptions);
+ return Objects.hash(causallyConsistent, snapshot, defaultTransactionOptions);
}
@Override
@@ -132,7 +101,6 @@ public String toString() {
return "ClientSessionOptions{"
+ "causallyConsistent=" + causallyConsistent
+ ", snapshot=" + snapshot
- + ", defaultTimeoutMS=" + defaultTimeoutMS
+ ", defaultTransactionOptions=" + defaultTransactionOptions
+ '}';
}
@@ -159,7 +127,6 @@ public static Builder builder(final ClientSessionOptions options) {
builder.causallyConsistent = options.isCausallyConsistent();
builder.snapshot = options.isSnapshot();
builder.defaultTransactionOptions = options.getDefaultTransactionOptions();
- builder.defaultTimeoutMS = options.defaultTimeoutMS;
return builder;
}
@@ -170,7 +137,6 @@ public static Builder builder(final ClientSessionOptions options) {
public static final class Builder {
private Boolean causallyConsistent;
private Boolean snapshot;
- private Long defaultTimeoutMS;
private TransactionOptions defaultTransactionOptions = TransactionOptions.builder().build();
/**
@@ -219,32 +185,6 @@ public Builder defaultTransactionOptions(final TransactionOptions defaultTransac
return this;
}
- /**
- * Sets the default time limit for the following operations executed on the session:
- *
- *
- *
{@code commitTransaction}
- *
{@code abortTransaction}
- *
{@code withTransaction}
- *
{@code close}
- *
- *
- *
Note: When using synchronous API, this timeout does not limit socket writes, therefore
- * there is a possibility that the operation might not be timed out when expected. This limitation does not
- * apply to the reactive streams API.
- *
- * @param defaultTimeout the timeout
- * @param timeUnit the time unit
- * @return this
- * @since 5.2
- * @see #getDefaultTimeout
- */
- @Alpha(Reason.CLIENT)
- public Builder defaultTimeout(final long defaultTimeout, final TimeUnit timeUnit) {
- this.defaultTimeoutMS = convertAndValidateTimeout(defaultTimeout, timeUnit, "defaultTimeout");
- return this;
- }
-
/**
* Build the session options instance.
*
@@ -267,6 +207,5 @@ private ClientSessionOptions(final Builder builder) {
: Boolean.valueOf(!builder.snapshot);
this.snapshot = builder.snapshot;
this.defaultTransactionOptions = builder.defaultTransactionOptions;
- this.defaultTimeoutMS = builder.defaultTimeoutMS;
}
}
diff --git a/driver-core/src/main/com/mongodb/ConnectionString.java b/driver-core/src/main/com/mongodb/ConnectionString.java
index 356fd9ca2a8..e71a83bd78e 100644
--- a/driver-core/src/main/com/mongodb/ConnectionString.java
+++ b/driver-core/src/main/com/mongodb/ConnectionString.java
@@ -16,7 +16,6 @@
package com.mongodb;
-import com.mongodb.annotations.Alpha;
import com.mongodb.annotations.Beta;
import com.mongodb.annotations.Reason;
import com.mongodb.connection.ClusterSettings;
@@ -145,12 +144,9 @@
*
{@code sslInvalidHostNameAllowed=true|false}: Whether to allow invalid host names for TLS connections.
*
{@code tlsAllowInvalidHostnames=true|false}: Whether to allow invalid host names for TLS connections. Supersedes the
* sslInvalidHostNameAllowed option
- *
{@code timeoutMS=ms}: Time limit for the full execution of an operation. Note: This parameter is part of an {@linkplain Alpha Alpha API} and may be
- * subject to changes or even removal in future releases.
*
{@code connectTimeoutMS=ms}: How long a connection can take to be opened before timing out.
*
{@code socketTimeoutMS=ms}: How long a receive on a socket can take before timing out.
- * This option is the same as {@link SocketSettings#getReadTimeout(TimeUnit)}.
- * Deprecated, use {@code timeoutMS} instead.
+ * This option is the same as {@link SocketSettings#getReadTimeout(TimeUnit)}.
*
{@code maxIdleTimeMS=ms}: Maximum idle time of a pooled connection. A connection that exceeds this limit will be closed
*
{@code maxLifeTimeMS=ms}: Maximum life time of a pooled connection. A connection that exceeds this limit will be closed
*
@@ -170,7 +166,7 @@
*
{@code waitQueueTimeoutMS=ms}: The maximum duration to wait until either:
* an {@linkplain ConnectionCheckedOutEvent in-use connection} becomes {@linkplain ConnectionCheckedInEvent available},
* or a {@linkplain ConnectionCreatedEvent connection is created} and begins to be {@linkplain ConnectionReadyEvent established}.
- * See {@link #getMaxWaitTime()} for more details. . Deprecated, use {@code timeoutMS} instead.
+ * See {@link #getMaxWaitTime()} for more details.
*
{@code maxConnecting=n}: The maximum number of connections a pool may be establishing concurrently.
*
*
Write concern configuration:
@@ -198,7 +194,7 @@
*
{@code wtimeoutMS=ms}
*
*
The driver adds { wtimeout : ms } to all write commands. Implies {@code safe=true}.
- *
Used in combination with {@code w}. Deprecated, use {@code timeoutMS} instead
+ *
Used in combination with {@code w}.
*
*
*
@@ -339,7 +335,6 @@ public class ConnectionString {
private Integer maxConnectionLifeTime;
private Integer maxConnecting;
private Integer connectTimeout;
- private Long timeout;
private Integer socketTimeout;
private Boolean sslEnabled;
private Boolean sslInvalidHostnameAllowed;
@@ -584,7 +579,6 @@ private String createRedactedConnectionString(@Nullable final String userName, f
static {
GENERAL_OPTIONS_KEYS.add("minpoolsize");
GENERAL_OPTIONS_KEYS.add("maxpoolsize");
- GENERAL_OPTIONS_KEYS.add("timeoutms");
GENERAL_OPTIONS_KEYS.add("sockettimeoutms");
GENERAL_OPTIONS_KEYS.add("waitqueuetimeoutms");
GENERAL_OPTIONS_KEYS.add("connecttimeoutms");
@@ -712,9 +706,6 @@ private void translateOptions(final Map> optionsMap) {
case "sockettimeoutms":
socketTimeout = parseInteger(value, "sockettimeoutms");
break;
- case "timeoutms":
- timeout = parseLong(value, "timeoutms");
- break;
case "proxyhost":
proxyHost = value;
break;
@@ -1700,38 +1691,6 @@ public Integer getMaxConnecting() {
return maxConnecting;
}
- /**
- * The time limit for the full execution of an operation in milliseconds.
- *
- *
If set the following deprecated options will be ignored:
- * {@code waitQueueTimeoutMS}, {@code socketTimeoutMS}, {@code wTimeoutMS}, {@code maxTimeMS} and {@code maxCommitTimeMS}
- *
- *
- *
{@code null} means that the timeout mechanism for operations will defer to using:
- *
- *
{@code waitQueueTimeoutMS}: The maximum wait time in milliseconds that a thread may wait for a connection to become
- * available
- *
{@code socketTimeoutMS}: How long a send or receive on a socket can take before timing out.
- *
{@code wTimeoutMS}: How long the server will wait for the write concern to be fulfilled before timing out.
- *
{@code maxTimeMS}: The cumulative time limit for processing operations on a cursor.
- * See: cursor.maxTimeMS.
- *
{@code maxCommitTimeMS}: The maximum amount of time to allow a single {@code commitTransaction} command to execute.
- * See: {@link TransactionOptions#getMaxCommitTime}.
- *
- *
- *
{@code 0} means infinite timeout.
- *
{@code > 0} The time limit to use for the full execution of an operation.
- *
- *
- * @return the time limit for the full execution of an operation in milliseconds or null.
- * @since 5.2
- */
- @Alpha(Reason.CLIENT)
- @Nullable
- public Long getTimeout() {
- return timeout;
- }
-
/**
* Gets the socket connect timeout specified in the connection string.
* @return the socket connect timeout
@@ -1945,7 +1904,6 @@ public boolean equals(final Object o) {
&& Objects.equals(maxConnectionLifeTime, that.maxConnectionLifeTime)
&& Objects.equals(maxConnecting, that.maxConnecting)
&& Objects.equals(connectTimeout, that.connectTimeout)
- && Objects.equals(timeout, that.timeout)
&& Objects.equals(socketTimeout, that.socketTimeout)
&& Objects.equals(proxyHost, that.proxyHost)
&& Objects.equals(proxyPort, that.proxyPort)
@@ -1970,7 +1928,7 @@ public boolean equals(final Object o) {
public int hashCode() {
return Objects.hash(credential, isSrvProtocol, hosts, database, collection, directConnection, readPreference,
writeConcern, retryWrites, retryReads, maxAdaptiveRetries, enableOverloadRetargeting, readConcern, minConnectionPoolSize, maxConnectionPoolSize, maxWaitTime,
- maxConnectionIdleTime, maxConnectionLifeTime, maxConnecting, connectTimeout, timeout, socketTimeout, sslEnabled,
+ maxConnectionIdleTime, maxConnectionLifeTime, maxConnecting, connectTimeout, socketTimeout, sslEnabled,
sslInvalidHostnameAllowed, requiredReplicaSetName, serverSelectionTimeout, localThreshold, heartbeatFrequency,
serverMonitoringMode, applicationName, compressorList, uuidRepresentation, srvServiceName, srvMaxHosts,
srvAllowedHostsSuffix, proxyHost, proxyPort, proxyUsername, proxyPassword);
diff --git a/driver-core/src/main/com/mongodb/MongoClientSettings.java b/driver-core/src/main/com/mongodb/MongoClientSettings.java
index aab66c2dfd8..ca3471c5789 100644
--- a/driver-core/src/main/com/mongodb/MongoClientSettings.java
+++ b/driver-core/src/main/com/mongodb/MongoClientSettings.java
@@ -55,12 +55,9 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
-import java.util.concurrent.TimeUnit;
-import static com.mongodb.assertions.Assertions.isTrue;
import static com.mongodb.assertions.Assertions.isTrueArgument;
import static com.mongodb.assertions.Assertions.notNull;
-import static com.mongodb.internal.TimeoutSettings.convertAndValidateTimeout;
import static java.util.Arrays.asList;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.bson.codecs.configuration.CodecRegistries.fromProviders;
@@ -124,8 +121,6 @@ public final class MongoClientSettings {
private final DnsClient dnsClient;
private final InetAddressResolver inetAddressResolver;
private final ObservabilitySettings observabilitySettings;
- @Nullable
- private final Long timeoutMS;
/**
* Gets the default codec registry. It includes the following providers:
@@ -245,7 +240,6 @@ public static final class Builder {
private int heartbeatConnectTimeoutMS;
private int heartbeatSocketTimeoutMS;
- private Long timeoutMS;
private ContextProvider contextProvider;
private DnsClient dnsClient;
@@ -271,7 +265,6 @@ private Builder(final MongoClientSettings settings) {
uuidRepresentation = settings.getUuidRepresentation();
serverApi = settings.getServerApi();
dnsClient = settings.getDnsClient();
- timeoutMS = settings.getTimeout(MILLISECONDS);
inetAddressResolver = settings.getInetAddressResolver();
transportSettings = settings.getTransportSettings();
observabilitySettings = settings.getObservabilitySettings();
@@ -342,9 +335,6 @@ public Builder applyConnectionString(final ConnectionString connectionString) {
if (connectionString.getWriteConcern() != null) {
writeConcern = connectionString.getWriteConcern();
}
- if (connectionString.getTimeout() != null) {
- timeoutMS = connectionString.getTimeout();
- }
return this;
}
@@ -835,41 +825,6 @@ public Builder inetAddressResolver(@Nullable final InetAddressResolver inetAddre
}
- /**
- * Sets the time limit for the full execution of an operation.
- *
- *
- *
{@code null} means that the timeout mechanism for operations will defer to using:
- *
- *
{@code waitQueueTimeoutMS}: The maximum wait time in milliseconds that a thread may wait for a connection to become
- * available
- *
{@code socketTimeoutMS}: How long a send or receive on a socket can take before timing out.
- *
{@code wTimeoutMS}: How long the server will wait for the write concern to be fulfilled before timing out.
- *
{@code maxTimeMS}: The cumulative time limit for processing operations on a cursor.
- * See: cursor.maxTimeMS.
- *
{@code maxCommitTimeMS}: The maximum amount of time to allow a single {@code commitTransaction} command to execute.
- * See: {@link TransactionOptions#getMaxCommitTime}.
- *
- *
- *
{@code 0} means infinite timeout.
- *
{@code > 0} The time limit to use for the full execution of an operation.
- *
- *
- *
Note: When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
- * operation might not be timed out when expected. This limitation does not apply to the reactive streams API.
- *
- * @param timeout the timeout
- * @param timeUnit the time unit
- * @return this
- * @since 5.2
- * @see #getTimeout
- */
- @Alpha(Reason.CLIENT)
- public Builder timeout(final long timeout, final TimeUnit timeUnit) {
- this.timeoutMS = convertAndValidateTimeout(timeout, timeUnit);
- return this;
- }
-
// Package-private to provide interop with MongoClientOptions
Builder heartbeatConnectTimeoutMS(final int heartbeatConnectTimeoutMS) {
this.heartbeatConnectTimeoutMS = heartbeatConnectTimeoutMS;
@@ -1087,42 +1042,6 @@ public ServerApi getServerApi() {
return serverApi;
}
- /**
- * The time limit for the full execution of an operation.
- *
- *
If set the following deprecated options will be ignored:
- * {@code waitQueueTimeoutMS}, {@code socketTimeoutMS}, {@code wTimeoutMS}, {@code maxTimeMS} and {@code maxCommitTimeMS}
- *
- *
- *
{@code null} means that the timeout mechanism for operations will defer to using:
- *
- *
{@code waitQueueTimeoutMS}: The maximum wait time in milliseconds that a thread may wait for a connection to become
- * available
- *
{@code socketTimeoutMS}: How long a send or receive on a socket can take before timing out.
- *
{@code wTimeoutMS}: How long the server will wait for the write concern to be fulfilled before timing out.
- *
{@code maxTimeMS}: The cumulative time limit for processing operations on a cursor.
- * See: cursor.maxTimeMS.
- *
{@code maxCommitTimeMS}: The maximum amount of time to allow a single {@code commitTransaction} command to execute.
- * See: {@link TransactionOptions#getMaxCommitTime}.
- *
- *
- *
{@code 0} means infinite timeout.
- *
{@code > 0} The time limit to use for the full execution of an operation.
- *
- *
- *
Note: When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
- * operation might not be timed out when expected. This limitation does not apply to the reactive streams API.
- *
- * @param timeUnit the time unit
- * @return the timeout in the given time unit
- * @since 5.2
- */
- @Alpha(Reason.CLIENT)
- @Nullable
- public Long getTimeout(final TimeUnit timeUnit) {
- return timeoutMS == null ? null : timeUnit.convert(timeoutMS, MILLISECONDS);
- }
-
/**
* Gets the auto-encryption settings.
*
@@ -1287,8 +1206,7 @@ public boolean equals(final Object o) {
&& Objects.equals(autoEncryptionSettings, that.autoEncryptionSettings)
&& Objects.equals(dnsClient, that.dnsClient)
&& Objects.equals(inetAddressResolver, that.inetAddressResolver)
- && Objects.equals(contextProvider, that.contextProvider)
- && Objects.equals(timeoutMS, that.timeoutMS);
+ && Objects.equals(contextProvider, that.contextProvider);
}
@Override
@@ -1298,7 +1216,7 @@ public int hashCode() {
commandListeners, codecRegistry, loggerSettings, clusterSettings, socketSettings,
heartbeatSocketSettings, connectionPoolSettings, serverSettings, sslSettings, applicationName, compressorList,
uuidRepresentation, serverApi, autoEncryptionSettings, heartbeatSocketTimeoutSetExplicitly,
- heartbeatConnectTimeoutSetExplicitly, dnsClient, inetAddressResolver, contextProvider, timeoutMS);
+ heartbeatConnectTimeoutSetExplicitly, dnsClient, inetAddressResolver, contextProvider);
}
@@ -1331,12 +1249,10 @@ public String toString() {
+ ", dnsClient=" + dnsClient
+ ", inetAddressResolver=" + inetAddressResolver
+ ", contextProvider=" + contextProvider
- + ", timeoutMS=" + timeoutMS
+ '}';
}
private MongoClientSettings(final Builder builder) {
- isTrue("timeoutMS > 0 ", builder.timeoutMS == null || builder.timeoutMS >= 0);
readPreference = builder.readPreference;
writeConcern = builder.writeConcern;
retryWrites = builder.retryWrites;
@@ -1374,6 +1290,5 @@ private MongoClientSettings(final Builder builder) {
heartbeatSocketTimeoutSetExplicitly = builder.heartbeatSocketTimeoutMS != 0;
heartbeatConnectTimeoutSetExplicitly = builder.heartbeatConnectTimeoutMS != 0;
contextProvider = builder.contextProvider;
- timeoutMS = builder.timeoutMS;
}
}
diff --git a/driver-core/src/main/com/mongodb/MongoOperationTimeoutException.java b/driver-core/src/main/com/mongodb/MongoOperationTimeoutException.java
deleted file mode 100644
index 9d46814c3da..00000000000
--- a/driver-core/src/main/com/mongodb/MongoOperationTimeoutException.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2008-present MongoDB, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.mongodb;
-
-import com.mongodb.annotations.Alpha;
-import com.mongodb.annotations.Reason;
-import com.mongodb.lang.Nullable;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Exception thrown to indicate that a MongoDB operation has exceeded the specified timeout for
- * the full execution of operation.
- *
- *
The {@link MongoOperationTimeoutException} might provide information about the underlying
- * cause of the timeout, if available. For example, if retries are attempted due to transient failures,
- * and a timeout occurs in any of the attempts, the exception from one of the retries may be appended
- * as the cause to this {@link MongoOperationTimeoutException}.
- *
- *
The key difference between {@link MongoOperationTimeoutException} and {@link MongoExecutionTimeoutException}
- * lies in the nature of these exceptions. {@link MongoExecutionTimeoutException} indicates a server-side timeout
- * capped by a user-specified number. These server errors are transformed into the new {@link MongoOperationTimeoutException}.
- * On the other hand, {@link MongoOperationTimeoutException} denotes a timeout during the execution of the entire operation.
- *
- * @see MongoClientSettings.Builder#timeout(long, TimeUnit)
- * @see MongoClientSettings#getTimeout(TimeUnit)
- * @since 5.2
- */
-@Alpha(Reason.CLIENT)
-public final class MongoOperationTimeoutException extends MongoTimeoutException {
- private static final long serialVersionUID = 1L;
-
- /**
- * Construct a new instance.
- *
- * @param message the message
- */
- public MongoOperationTimeoutException(final String message) {
- super(message);
- }
-
- /**
- * Construct a new instance
- * @param message the message
- * @param cause the cause
- */
- public MongoOperationTimeoutException(final String message, @Nullable final Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/driver-core/src/main/com/mongodb/TransactionOptions.java b/driver-core/src/main/com/mongodb/TransactionOptions.java
index ed3c88ece60..edadb7b6200 100644
--- a/driver-core/src/main/com/mongodb/TransactionOptions.java
+++ b/driver-core/src/main/com/mongodb/TransactionOptions.java
@@ -16,9 +16,7 @@
package com.mongodb;
-import com.mongodb.annotations.Alpha;
import com.mongodb.annotations.Immutable;
-import com.mongodb.annotations.Reason;
import com.mongodb.lang.Nullable;
import java.util.Objects;
@@ -26,7 +24,6 @@
import static com.mongodb.assertions.Assertions.isTrueArgument;
import static com.mongodb.assertions.Assertions.notNull;
-import static com.mongodb.internal.TimeoutSettings.convertAndValidateTimeoutNullable;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
/**
@@ -45,7 +42,6 @@ public final class TransactionOptions {
private final WriteConcern writeConcern;
private final ReadPreference readPreference;
private final Long maxCommitTimeMS;
- private final Long timeoutMS;
/**
* Gets the read concern.
@@ -95,37 +91,6 @@ public Long getMaxCommitTime(final TimeUnit timeUnit) {
return timeUnit.convert(maxCommitTimeMS, MILLISECONDS);
}
- /**
- * The time limit for the full execution of the transaction.
- *
- *
If set the following deprecated options will be ignored:
- * {@code waitQueueTimeoutMS}, {@code socketTimeoutMS}, {@code wTimeoutMS}, {@code maxTimeMS} and {@code maxCommitTimeMS}
- *
- *
- *
{@code null} means that the timeout mechanism for operations will defer to using
- * {@link ClientSessionOptions#getDefaultTimeout(TimeUnit)} or {@link MongoClientSettings#getTimeout(TimeUnit)}
- *
- *
{@code 0} means infinite timeout.
- *
{@code > 0} The time limit to use for the full execution of an operation.
- *
- *
- *
Note: When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
- * operation might not be timed out when expected. This limitation does not apply to the reactive streams API.
- *
- * @param timeUnit the time unit
- * @return the timeout in the given time unit
- * @since 5.2
- */
- @Nullable
- @Alpha(Reason.CLIENT)
- public Long getTimeout(final TimeUnit timeUnit) {
- notNull("timeUnit", timeUnit);
- if (timeoutMS == null) {
- return null;
- }
- return timeUnit.convert(timeoutMS, MILLISECONDS);
- }
-
/**
* Gets an instance of a builder
*
@@ -155,9 +120,6 @@ public static TransactionOptions merge(final TransactionOptions options, final T
.maxCommitTime(options.getMaxCommitTime(MILLISECONDS) == null
? defaultOptions.getMaxCommitTime(MILLISECONDS) : options.getMaxCommitTime(MILLISECONDS),
MILLISECONDS)
- .timeout(options.getTimeout(MILLISECONDS) == null
- ? defaultOptions.getTimeout(MILLISECONDS) : options.getTimeout(MILLISECONDS),
- MILLISECONDS)
.build();
}
@@ -172,9 +134,6 @@ public boolean equals(final Object o) {
TransactionOptions that = (TransactionOptions) o;
- if (!Objects.equals(timeoutMS, that.timeoutMS)) {
- return false;
- }
if (!Objects.equals(maxCommitTimeMS, that.maxCommitTimeMS)) {
return false;
}
@@ -197,7 +156,6 @@ public int hashCode() {
result = 31 * result + (writeConcern != null ? writeConcern.hashCode() : 0);
result = 31 * result + (readPreference != null ? readPreference.hashCode() : 0);
result = 31 * result + (maxCommitTimeMS != null ? maxCommitTimeMS.hashCode() : 0);
- result = 31 * result + (timeoutMS != null ? timeoutMS.hashCode() : 0);
return result;
}
@@ -208,7 +166,6 @@ public String toString() {
+ ", writeConcern=" + writeConcern
+ ", readPreference=" + readPreference
+ ", maxCommitTimeMS=" + maxCommitTimeMS
- + ", timeoutMS=" + timeoutMS
+ '}';
}
@@ -220,8 +177,6 @@ public static final class Builder {
private WriteConcern writeConcern;
private ReadPreference readPreference;
private Long maxCommitTimeMS;
- @Nullable
- private Long timeoutMS;
/**
* Sets the read concern.
@@ -276,39 +231,6 @@ public Builder maxCommitTime(@Nullable final Long maxCommitTime, final TimeUnit
return this;
}
- /**
- * Sets the time limit for the full execution of the operations for this transaction.
- *
- *
- *
{@code null} means that the timeout mechanism for operations will defer to using:
- *
- *
{@code waitQueueTimeoutMS}: The maximum wait time in milliseconds that a thread may wait for a connection to become
- * available
- *
{@code socketTimeoutMS}: How long a send or receive on a socket can take before timing out.
- *
{@code wTimeoutMS}: How long the server will wait for the write concern to be fulfilled before timing out.
- *
{@code maxTimeMS}: The cumulative time limit for processing operations on a cursor.
- * See: cursor.maxTimeMS.
- *
{@code maxCommitTimeMS}: The maximum amount of time to allow a single {@code commitTransaction} command to execute.
- *
- *
- *
{@code 0} means infinite timeout.
- *
{@code > 0} The time limit to use for the full execution of an operation.
- *
- *
- *
Note: When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
- * operation might not be timed out when expected. This limitation does not apply to the reactive streams API.
- *
- * @param timeout the timeout
- * @param timeUnit the time unit
- * @return this
- * @since 5.2
- */
- @Alpha(Reason.CLIENT)
- public Builder timeout(@Nullable final Long timeout, final TimeUnit timeUnit) {
- this.timeoutMS = convertAndValidateTimeoutNullable(timeout, timeUnit);
- return this;
- }
-
/**
* Build the transaction options instance.
*
@@ -328,6 +250,5 @@ private TransactionOptions(final Builder builder) {
writeConcern = builder.writeConcern;
readPreference = builder.readPreference;
maxCommitTimeMS = builder.maxCommitTimeMS;
- timeoutMS = builder.timeoutMS;
}
}
diff --git a/driver-core/src/main/com/mongodb/client/cursor/TimeoutMode.java b/driver-core/src/main/com/mongodb/client/cursor/TimeoutMode.java
deleted file mode 100644
index cdaa92d4923..00000000000
--- a/driver-core/src/main/com/mongodb/client/cursor/TimeoutMode.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2008-present MongoDB, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.mongodb.client.cursor;
-
-import com.mongodb.annotations.Alpha;
-import com.mongodb.annotations.Reason;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * The timeout mode for a cursor
- *
- *
For operations that create cursors, {@code timeoutMS} can either cap the lifetime of the cursor or be applied separately to the
- * original operation and all next calls.
- *
- * @see com.mongodb.MongoClientSettings#getTimeout(TimeUnit)
- * @since 5.2
- */
-@Alpha(Reason.CLIENT)
-public enum TimeoutMode {
-
- /**
- * The timeout lasts for the lifetime of the cursor
- */
- CURSOR_LIFETIME,
-
- /**
- * The timeout is reset for each batch iteration of the cursor
- */
- ITERATION
-}
diff --git a/driver-core/src/main/com/mongodb/internal/ExceptionUtils.java b/driver-core/src/main/com/mongodb/internal/ExceptionUtils.java
index 6a0d08ba123..d787106bfcb 100644
--- a/driver-core/src/main/com/mongodb/internal/ExceptionUtils.java
+++ b/driver-core/src/main/com/mongodb/internal/ExceptionUtils.java
@@ -17,7 +17,6 @@
package com.mongodb.internal;
import com.mongodb.MongoCommandException;
-import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoSocketException;
import org.bson.BsonArray;
import org.bson.BsonDocument;
@@ -44,10 +43,6 @@ public static boolean isMongoSocketException(final Throwable e) {
return e instanceof MongoSocketException;
}
- public static boolean isOperationTimeoutFromSocketException(final Throwable e) {
- return e instanceof MongoOperationTimeoutException && e.getCause() instanceof MongoSocketException;
- }
-
/**
* We must always propagate {@link Error}s, instead of wrapping them in / replacing them with {@link Exception}s, or swallowing them.
*
diff --git a/driver-core/src/main/com/mongodb/internal/TimeoutContext.java b/driver-core/src/main/com/mongodb/internal/TimeoutContext.java
index 2e2917485a4..2e7f7aca1a5 100644
--- a/driver-core/src/main/com/mongodb/internal/TimeoutContext.java
+++ b/driver-core/src/main/com/mongodb/internal/TimeoutContext.java
@@ -15,8 +15,6 @@
*/
package com.mongodb.internal;
-import com.mongodb.MongoClientException;
-import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.internal.connection.CommandMessage;
import com.mongodb.internal.time.StartTime;
import com.mongodb.internal.time.Timeout;
@@ -26,12 +24,8 @@
import java.util.Objects;
import java.util.function.LongConsumer;
-import static com.mongodb.assertions.Assertions.assertNotNull;
-import static com.mongodb.assertions.Assertions.assertNull;
-import static com.mongodb.assertions.Assertions.assertTrue;
import static com.mongodb.assertions.Assertions.isTrue;
import static com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE;
-import static com.mongodb.internal.time.Timeout.ZeroSemantics.ZERO_DURATION_MEANS_INFINITE;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
/**
@@ -43,132 +37,52 @@ public class TimeoutContext {
public static final String DEFAULT_TIMEOUT_MESSAGE = "Operation exceeded the timeout limit.";
private static final int NO_ROUND_TRIP_TIME_MS = 0;
private final TimeoutSettings timeoutSettings;
- /**
- * Is {@code null} iff {@link #timeoutSettings}{@code .}{@link TimeoutSettings#getTimeoutMS() getTimeoutMS()} is {@code null}.
- */
- @Nullable
- private final Timeout timeout;
@Nullable
private final MaxTimeSupplier maxTimeSupplier;
private final boolean isMaintenanceContext;
private final long minRoundTripTimeMS;
- public static MongoOperationTimeoutException createMongoRoundTripTimeoutException() {
- return createMongoTimeoutException("Remaining timeoutMS is less than or equal to the server's minimum round trip time.");
- }
-
- public static MongoOperationTimeoutException createMongoTimeoutException(final String message) {
- return new MongoOperationTimeoutException(message);
- }
-
- public static T throwMongoTimeoutException(final String message) {
- throw new MongoOperationTimeoutException(message);
- }
- public static T throwMongoTimeoutException() {
- throw new MongoOperationTimeoutException(DEFAULT_TIMEOUT_MESSAGE);
- }
-
- public static MongoOperationTimeoutException createMongoTimeoutException(final Throwable cause) {
- return createMongoTimeoutException(DEFAULT_TIMEOUT_MESSAGE, cause);
- }
-
- public static MongoOperationTimeoutException createMongoTimeoutException(final String message, @Nullable final Throwable cause) {
- if (cause instanceof MongoOperationTimeoutException) {
- return (MongoOperationTimeoutException) cause;
- }
- return new MongoOperationTimeoutException(message, cause);
- }
-
- public static TimeoutContext createMaintenanceTimeoutContext(final TimeoutSettings timeoutSettings) {
- return new TimeoutContext(true, timeoutSettings, startTimeout(timeoutSettings.getTimeoutMS()));
- }
-
public static TimeoutContext createTimeoutContext(final ClientSession session, final TimeoutSettings timeoutSettings) {
TimeoutContext sessionTimeoutContext = session.getTimeoutContext();
if (sessionTimeoutContext != null) {
TimeoutSettings sessionTimeoutSettings = sessionTimeoutContext.timeoutSettings;
- if (timeoutSettings.getGenerationId() > sessionTimeoutSettings.getGenerationId()) {
- throw new MongoClientException("Cannot change the timeoutMS during a transaction.");
- }
- // Check for any legacy operation timeouts
- if (sessionTimeoutSettings.getTimeoutMS() == null) {
- if (timeoutSettings.getMaxTimeMS() != 0) {
- sessionTimeoutSettings = sessionTimeoutSettings.withMaxTimeMS(timeoutSettings.getMaxTimeMS());
- }
- if (timeoutSettings.getMaxAwaitTimeMS() != 0) {
- sessionTimeoutSettings = sessionTimeoutSettings.withMaxAwaitTimeMS(timeoutSettings.getMaxAwaitTimeMS());
- }
- if (timeoutSettings.getMaxCommitTimeMS() != null) {
- sessionTimeoutSettings = sessionTimeoutSettings.withMaxCommitMS(timeoutSettings.getMaxCommitTimeMS());
- }
- return new TimeoutContext(sessionTimeoutSettings);
+ if (timeoutSettings.getMaxTimeMS() != 0) {
+ sessionTimeoutSettings = sessionTimeoutSettings.withMaxTimeMS(timeoutSettings.getMaxTimeMS());
}
- return sessionTimeoutContext;
+ if (timeoutSettings.getMaxAwaitTimeMS() != 0) {
+ sessionTimeoutSettings = sessionTimeoutSettings.withMaxAwaitTimeMS(timeoutSettings.getMaxAwaitTimeMS());
+ }
+ if (timeoutSettings.getMaxCommitTimeMS() != null) {
+ sessionTimeoutSettings = sessionTimeoutSettings.withMaxCommitMS(timeoutSettings.getMaxCommitTimeMS());
+ }
+ return new TimeoutContext(sessionTimeoutSettings);
}
return new TimeoutContext(timeoutSettings);
}
public TimeoutContext(final TimeoutSettings timeoutSettings) {
- this(false, timeoutSettings, startTimeout(timeoutSettings.getTimeoutMS()));
+ this(false, timeoutSettings);
}
private TimeoutContext(final boolean isMaintenanceContext,
- final TimeoutSettings timeoutSettings,
- @Nullable final Timeout timeout) {
+ final TimeoutSettings timeoutSettings) {
this(isMaintenanceContext,
NO_ROUND_TRIP_TIME_MS,
timeoutSettings,
- null,
- timeout);
+ null
+ );
}
private TimeoutContext(final boolean isMaintenanceContext,
final long minRoundTripTimeMS,
final TimeoutSettings timeoutSettings,
@Nullable final MaxTimeSupplier maxTimeSupplier) {
- this(isMaintenanceContext,
- minRoundTripTimeMS,
- timeoutSettings,
- maxTimeSupplier,
- startTimeout(timeoutSettings.getTimeoutMS()));
- }
-
- private TimeoutContext(final boolean isMaintenanceContext,
- final long minRoundTripTimeMS,
- final TimeoutSettings timeoutSettings,
- @Nullable final MaxTimeSupplier maxTimeSupplier,
- @Nullable final Timeout timeout) {
- assertTrue((timeoutSettings.getTimeoutMS() == null) == (timeout == null));
this.isMaintenanceContext = isMaintenanceContext;
this.timeoutSettings = timeoutSettings;
this.minRoundTripTimeMS = minRoundTripTimeMS;
this.maxTimeSupplier = maxTimeSupplier;
- this.timeout = timeout;
- }
-
- /**
- * Allows for the differentiation between users explicitly setting a global operation timeout via {@code timeoutMS}.
- *
- * @return true iff {@link #getTimeoutSettings()}{@code .}{@link TimeoutSettings#getTimeoutMS() getTimeoutMS()} is not {@code null}.
- * @see #getTimeout()
- */
- public boolean hasTimeoutMS() {
- return timeoutSettings.getTimeoutMS() != null;
- }
-
- /**
- * Runs the runnable if the timeout is expired.
- * @param onExpired the runnable to run
- */
- public void onExpired(final Runnable onExpired) {
- Timeout.nullAsInfinite(timeout).onExpired(onExpired);
- }
-
- @Nullable
- public Timeout timeoutIncludingRoundTrip() {
- return timeout == null ? null : timeout.shortenBy(minRoundTripTimeMS, MILLISECONDS);
}
/**
@@ -180,29 +94,13 @@ public Timeout timeoutIncludingRoundTrip() {
*/
@VisibleForTesting(otherwise = PRIVATE)
public long timeoutOrAlternative(final long alternativeTimeoutMS) {
- if (timeout == null) {
return alternativeTimeoutMS;
- } else {
- return timeout.call(MILLISECONDS,
- () -> 0L,
- (ms) -> ms,
- () -> throwMongoTimeoutException());
- }
}
public TimeoutSettings getTimeoutSettings() {
return timeoutSettings;
}
- /**
- * @return {@code null} iff {@link #hasTimeoutMS()} is {@code false}.
- * @see #hasTimeoutMS()
- */
- @Nullable
- public Timeout getTimeout() {
- return timeout;
- }
-
public long getMaxAwaitTimeMS() {
return timeoutSettings.getMaxAwaitTimeMS();
}
@@ -227,10 +125,7 @@ public int getConnectTimeoutMs() {
return (int) connectTimeoutMS;
}
- return Math.toIntExact(Timeout.nullAsInfinite(timeout).call(MILLISECONDS,
- () -> connectTimeoutMS,
- (ms) -> connectTimeoutMS == 0 ? ms : Math.min(ms, connectTimeoutMS),
- () -> throwMongoTimeoutException()));
+ return Math.toIntExact(connectTimeoutMS);
}
/**
@@ -243,8 +138,7 @@ public TimeoutContext withMaxTimeAsMaxAwaitTimeOverride() {
isMaintenanceContext,
minRoundTripTimeMS,
timeoutSettings,
- timeoutSettings::getMaxAwaitTimeMS,
- timeout);
+ timeoutSettings::getMaxAwaitTimeMS);
}
/**
@@ -253,31 +147,26 @@ public TimeoutContext withMaxTimeAsMaxAwaitTimeOverride() {
* in {@link CommandMessage} as an extra element before we send it to the server.
*
* Suitable for static user-defined values only (i.e. {@code MaxAwaitTimeMS}),
- * not for running timeouts that adjust dynamically (CSOT).
- *
- * If remaining CSOT timeout is less than this static timeout, then CSOT timeout will be used.
+ * not for running timeouts that adjust dynamically.
*/
public TimeoutContext withMaxTimeOverride(final long maxTimeMS) {
return new TimeoutContext(
isMaintenanceContext,
minRoundTripTimeMS,
timeoutSettings,
- () -> maxTimeMS,
- timeout);
+ () -> maxTimeMS);
}
/**
* Creates {@link TimeoutContext} with the default maxTimeMS behaviour in {@link #runMaxTimeMS(LongConsumer)}:
- * - if timeoutMS is set, the remaining timeoutMS will be used as the maxTimeMS.
- * - if timeoutMS is not set, the {@link TimeoutSettings#getMaxTimeMS()} will be used.
+ * the {@link TimeoutSettings#getMaxTimeMS()} will be used.
*/
public TimeoutContext withDefaultMaxTime() {
return new TimeoutContext(
isMaintenanceContext,
minRoundTripTimeMS,
timeoutSettings,
- null,
- timeout);
+ null);
}
/**
@@ -289,8 +178,7 @@ public TimeoutContext withDisabledMaxTime() {
isMaintenanceContext,
minRoundTripTimeMS,
timeoutSettings,
- () -> 0,
- timeout);
+ () -> 0);
}
/**
@@ -302,8 +190,7 @@ public TimeoutContext withMaxTimeAsMaxCommitTime() {
isMaintenanceContext,
minRoundTripTimeMS,
timeoutSettings,
- () -> getMaxCommitTimeMS(),
- timeout);
+ () -> getMaxCommitTimeMS());
}
@@ -318,8 +205,7 @@ public TimeoutContext withMinRoundTripTime(final long minRoundTripTimeMS) {
isMaintenanceContext,
minRoundTripTimeMS,
timeoutSettings,
- maxTimeSupplier,
- timeout);
+ maxTimeSupplier);
}
/**
@@ -337,31 +223,12 @@ public TimeoutContext withNewlyStartedMaintenanceTimeout() {
maxTimeSupplier);
}
- /**
- * Returns the timeout context to use for the handshake process
- *
- * @return a new timeout context with the cached computed server selection timeout if available or this
- */
- public TimeoutContext withComputedServerSelectionTimeout() {
- if (this.hasTimeoutMS()) {
- Timeout serverSelectionTimeout = StartTime.now()
- .timeoutAfterOrInfiniteIfNegative(getTimeoutSettings().getServerSelectionTimeoutMS(), MILLISECONDS);
- if (isMaintenanceContext) {
- return new TimeoutContext(false, timeoutSettings, serverSelectionTimeout);
- }
- return new TimeoutContext(false, timeoutSettings, Timeout.earliest(serverSelectionTimeout, timeout));
- }
-
- return this;
- }
-
public TimeoutContext withMinRoundTripTimeMS(final long minRoundTripTimeMS) {
isTrue("'minRoundTripTimeMS' must be a positive number", minRoundTripTimeMS >= 0);
return new TimeoutContext(isMaintenanceContext,
minRoundTripTimeMS,
timeoutSettings,
- maxTimeSupplier,
- timeout);
+ maxTimeSupplier);
}
public TimeoutContext withNewlyStartedTimeout() {
@@ -373,9 +240,6 @@ public TimeoutContext withNewlyStartedTimeout() {
}
public TimeoutContext withAdditionalReadTimeout(final int additionalReadTimeout) {
- // Only used outside timeoutMS usage
- assertNull(timeout);
-
// Check existing read timeout is infinite
if (timeoutSettings.getReadTimeoutMS() == 0) {
return this;
@@ -390,7 +254,6 @@ public String toString() {
return "TimeoutContext{"
+ "isMaintenanceContext=" + isMaintenanceContext
+ ", timeoutSettings=" + timeoutSettings
- + ", timeout=" + timeout
+ ", minRoundTripTimeMS=" + minRoundTripTimeMS
+ '}';
}
@@ -406,21 +269,12 @@ public boolean equals(final Object o) {
final TimeoutContext that = (TimeoutContext) o;
return isMaintenanceContext == that.isMaintenanceContext
&& minRoundTripTimeMS == that.minRoundTripTimeMS
- && Objects.equals(timeoutSettings, that.timeoutSettings)
- && Objects.equals(timeout, that.timeout);
+ && Objects.equals(timeoutSettings, that.timeoutSettings);
}
@Override
public int hashCode() {
- return Objects.hash(isMaintenanceContext, timeoutSettings, timeout, minRoundTripTimeMS);
- }
-
- @Nullable
- public static Timeout startTimeout(@Nullable final Long timeoutMS) {
- if (timeoutMS != null) {
- return Timeout.expiresIn(timeoutMS, MILLISECONDS, ZERO_DURATION_MEANS_INFINITE);
- }
- return null;
+ return Objects.hash(isMaintenanceContext, timeoutSettings, minRoundTripTimeMS);
}
/**
@@ -429,24 +283,16 @@ public static Timeout startTimeout(@Nullable final Long timeoutMS) {
*
Caches the computed server selection timeout if:
*
*
not in a maintenance context
- *
there is a timeoutMS, so to keep the same legacy behavior.
*
the server selection timeout is less than the remaining overall timeout.
*
*
* @return the timeout context
*/
public Timeout computeServerSelectionTimeout() {
- if (hasTimeoutMS()) {
- return assertNotNull(timeout);
- }
-
return StartTime.now().timeoutAfterOrInfiniteIfNegative(getTimeoutSettings().getServerSelectionTimeoutMS(), MILLISECONDS);
}
public Timeout startMaxWaitTimeout(final StartTime checkoutStart) {
- if (hasTimeoutMS()) {
- return assertNotNull(timeout);
- }
final long ms = getTimeoutSettings().getMaxWaitTimeMS();
return checkoutStart.timeoutAfterOrInfiniteIfNegative(ms, MILLISECONDS);
}
@@ -455,38 +301,12 @@ public void runMaxTimeMS(final LongConsumer onRemaining) {
if (maxTimeSupplier != null) {
long maxTimeMS = maxTimeSupplier.get();
if (maxTimeMS > 0) {
- runMinTimeout(onRemaining, maxTimeMS);
+ onRemaining.accept(maxTimeMS);
}
return;
}
- if (timeout == null) {
- runWithFixedTimeout(timeoutSettings.getMaxTimeMS(), onRemaining);
- return;
- }
- assertNotNull(timeoutIncludingRoundTrip())
- .run(MILLISECONDS,
- () -> {},
- onRemaining,
- () -> {
- throw createMongoRoundTripTimeoutException();
- });
-
- }
+ runWithFixedTimeout(timeoutSettings.getMaxTimeMS(), onRemaining);
- private void runMinTimeout(final LongConsumer onRemaining, final long fixedMs) {
- Timeout timeout = timeoutIncludingRoundTrip();
- if (timeout != null) {
- timeout.run(MILLISECONDS, () -> {
- onRemaining.accept(fixedMs);
- },
- (remainingMs) -> {
- onRemaining.accept(Math.min(remainingMs, fixedMs));
- }, () -> {
- throwMongoTimeoutException();
- });
- } else {
- onRemaining.accept(fixedMs);
- }
}
private static void runWithFixedTimeout(final long ms, final LongConsumer onRemaining) {
diff --git a/driver-core/src/main/com/mongodb/internal/TimeoutSettings.java b/driver-core/src/main/com/mongodb/internal/TimeoutSettings.java
index e1f0bc0b795..6a6aa2a23e8 100644
--- a/driver-core/src/main/com/mongodb/internal/TimeoutSettings.java
+++ b/driver-core/src/main/com/mongodb/internal/TimeoutSettings.java
@@ -23,7 +23,6 @@
import java.util.concurrent.atomic.AtomicLong;
import static com.mongodb.assertions.Assertions.isTrueArgument;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
/**
* Timeout Settings.
@@ -35,8 +34,6 @@ public class TimeoutSettings {
private final long generationId;
private final long serverSelectionTimeoutMS;
private final long connectTimeoutMS;
- @Nullable
- private final Long timeoutMS;
// Deprecated configuration timeout options
private final long readTimeoutMS; // aka socketTimeoutMS
@@ -52,29 +49,12 @@ public class TimeoutSettings {
public static final TimeoutSettings DEFAULT = create(MongoClientSettings.builder().build());
- @Nullable
- public static Long convertAndValidateTimeoutNullable(@Nullable final Long timeout, final TimeUnit timeUnit) {
- return timeout == null ? null : convertAndValidateTimeout(timeout, timeUnit, "timeout");
- }
-
- public static long convertAndValidateTimeout(final long timeout, final TimeUnit timeUnit) {
- return convertAndValidateTimeout(timeout, timeUnit, "timeout");
- }
-
- public static long convertAndValidateTimeout(final long timeout, final TimeUnit timeUnit, final String fieldName) {
- return isTrueArgument(fieldName + " was too small. After conversion it was rounded to 0 milliseconds, "
- + " which would result in an unintended infinite timeout.",
- () -> MILLISECONDS.convert(timeout, timeUnit),
- (timeoutMS) -> timeout == 0 && timeoutMS == 0 || timeoutMS > 0);
- }
-
@SuppressWarnings("deprecation")
public static TimeoutSettings create(final MongoClientSettings settings) {
return new TimeoutSettings(
settings.getClusterSettings().getServerSelectionTimeout(TimeUnit.MILLISECONDS),
settings.getSocketSettings().getConnectTimeout(TimeUnit.MILLISECONDS),
settings.getSocketSettings().getReadTimeout(TimeUnit.MILLISECONDS),
- settings.getTimeout(TimeUnit.MILLISECONDS),
settings.getConnectionPoolSettings().getMaxWaitTime(TimeUnit.MILLISECONDS));
}
@@ -83,37 +63,25 @@ public static TimeoutSettings createHeartbeatSettings(final MongoClientSettings
settings.getClusterSettings().getServerSelectionTimeout(TimeUnit.MILLISECONDS),
settings.getHeartbeatSocketSettings().getConnectTimeout(TimeUnit.MILLISECONDS),
settings.getHeartbeatSocketSettings().getReadTimeout(TimeUnit.MILLISECONDS),
- settings.getTimeout(TimeUnit.MILLISECONDS),
settings.getConnectionPoolSettings().getMaxWaitTime(TimeUnit.MILLISECONDS));
}
public TimeoutSettings(final long serverSelectionTimeoutMS, final long connectTimeoutMS, final long readTimeoutMS,
- @Nullable final Long timeoutMS, final long maxWaitTimeMS) {
- this(-1, timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, 0, 0, null, null, maxWaitTimeMS);
- }
-
- TimeoutSettings(@Nullable final Long timeoutMS, final long serverSelectionTimeoutMS, final long connectTimeoutMS,
- final long readTimeoutMS, final long maxAwaitTimeMS, final long maxTimeMS, @Nullable final Long maxCommitTimeMS,
- @Nullable final Long wTimeoutMS, final long maxWaitTimeMS) {
- this(timeoutMS != null ? NEXT_ID.incrementAndGet() : -1, timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS,
- maxAwaitTimeMS, maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
+ final long maxWaitTimeMS) {
+ this(-1, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, 0, 0, null, null, maxWaitTimeMS);
}
- private TimeoutSettings(final long generationId, @Nullable final Long timeoutMS, final long serverSelectionTimeoutMS,
+ private TimeoutSettings(final long generationId, final long serverSelectionTimeoutMS,
final long connectTimeoutMS, final long readTimeoutMS, final long maxAwaitTimeMS, final long maxTimeMS,
@Nullable final Long maxCommitTimeMS, @Nullable final Long wTimeoutMS, final long maxWaitTimeMS) {
- isTrueArgument("timeoutMS must be >= 0", timeoutMS == null || timeoutMS >= 0);
isTrueArgument("maxAwaitTimeMS must be >= 0", maxAwaitTimeMS >= 0);
isTrueArgument("maxTimeMS must be >= 0", maxTimeMS >= 0);
- isTrueArgument("timeoutMS must be greater than maxAwaitTimeMS", timeoutMS == null || timeoutMS == 0
- || timeoutMS > maxAwaitTimeMS);
isTrueArgument("maxCommitTimeMS must be >= 0", maxCommitTimeMS == null || maxCommitTimeMS >= 0);
this.generationId = generationId;
this.serverSelectionTimeoutMS = serverSelectionTimeoutMS;
this.connectTimeoutMS = connectTimeoutMS;
- this.timeoutMS = timeoutMS;
this.maxAwaitTimeMS = maxAwaitTimeMS;
this.readTimeoutMS = readTimeoutMS;
this.maxTimeMS = maxTimeMS;
@@ -123,60 +91,51 @@ private TimeoutSettings(final long generationId, @Nullable final Long timeoutMS,
}
public TimeoutSettings connectionOnly() {
- return new TimeoutSettings(serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, null, maxWaitTimeMS);
- }
-
- public TimeoutSettings withTimeout(@Nullable final Long timeout, final TimeUnit timeUnit) {
- return withTimeoutMS(convertAndValidateTimeoutNullable(timeout, timeUnit));
- }
-
- TimeoutSettings withTimeoutMS(@Nullable final Long timeoutMS) {
- return new TimeoutSettings(timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
- maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
+ return new TimeoutSettings(serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxWaitTimeMS);
}
public TimeoutSettings withMaxTimeMS(final long maxTimeMS) {
- return new TimeoutSettings(generationId, timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
+ return new TimeoutSettings(generationId, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
}
public TimeoutSettings withMaxAwaitTimeMS(final long maxAwaitTimeMS) {
- return new TimeoutSettings(generationId, timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
+ return new TimeoutSettings(generationId, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
}
public TimeoutSettings withMaxTimeAndMaxAwaitTimeMS(final long maxTimeMS, final long maxAwaitTimeMS) {
- return new TimeoutSettings(generationId, timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
+ return new TimeoutSettings(generationId, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
}
public TimeoutSettings withMaxCommitMS(@Nullable final Long maxCommitTimeMS) {
- return new TimeoutSettings(generationId, timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
+ return new TimeoutSettings(generationId, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
}
public TimeoutSettings withWTimeoutMS(@Nullable final Long wTimeoutMS) {
- return new TimeoutSettings(timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
+ return new TimeoutSettings(generationId, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
}
public TimeoutSettings withReadTimeoutMS(final long readTimeoutMS) {
- return new TimeoutSettings(generationId, timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
+ return new TimeoutSettings(generationId, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
}
public TimeoutSettings withConnectTimeoutMS(final long connectTimeoutMS) {
- return new TimeoutSettings(generationId, timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
+ return new TimeoutSettings(generationId, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
}
public TimeoutSettings withServerSelectionTimeoutMS(final long serverSelectionTimeoutMS) {
- return new TimeoutSettings(timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
+ return new TimeoutSettings(generationId, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
}
public TimeoutSettings withMaxWaitTimeMS(final long maxWaitTimeMS) {
- return new TimeoutSettings(timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
+ return new TimeoutSettings(generationId, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
}
@@ -188,11 +147,6 @@ public long getConnectTimeoutMS() {
return connectTimeoutMS;
}
- @Nullable
- public Long getTimeoutMS() {
- return timeoutMS;
- }
-
public long getMaxAwaitTimeMS() {
return maxAwaitTimeMS;
}
@@ -235,7 +189,6 @@ public long getGenerationId() {
public String toString() {
return "TimeoutSettings{"
+ "generationId=" + generationId
- + ", timeoutMS=" + timeoutMS
+ ", serverSelectionTimeoutMS=" + serverSelectionTimeoutMS
+ ", connectTimeoutMS=" + connectTimeoutMS
+ ", readTimeoutMS=" + readTimeoutMS
@@ -258,13 +211,13 @@ public boolean equals(final Object o) {
final TimeoutSettings that = (TimeoutSettings) o;
return serverSelectionTimeoutMS == that.serverSelectionTimeoutMS && connectTimeoutMS == that.connectTimeoutMS
&& readTimeoutMS == that.readTimeoutMS && maxWaitTimeMS == that.maxWaitTimeMS && maxTimeMS == that.maxTimeMS
- && maxAwaitTimeMS == that.maxAwaitTimeMS && Objects.equals(timeoutMS, that.timeoutMS)
+ && maxAwaitTimeMS == that.maxAwaitTimeMS
&& Objects.equals(wTimeoutMS, that.wTimeoutMS) && Objects.equals(maxCommitTimeMS, that.maxCommitTimeMS);
}
@Override
public int hashCode() {
- return Objects.hash(generationId, serverSelectionTimeoutMS, connectTimeoutMS, timeoutMS, readTimeoutMS, maxWaitTimeMS, wTimeoutMS, maxTimeMS,
+ return Objects.hash(generationId, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxWaitTimeMS, wTimeoutMS, maxTimeMS,
maxAwaitTimeMS, maxCommitTimeMS);
}
}
diff --git a/driver-core/src/main/com/mongodb/internal/client/model/FindOptions.java b/driver-core/src/main/com/mongodb/internal/client/model/FindOptions.java
index 1c7f3ef9858..3a87434e9ed 100644
--- a/driver-core/src/main/com/mongodb/internal/client/model/FindOptions.java
+++ b/driver-core/src/main/com/mongodb/internal/client/model/FindOptions.java
@@ -17,9 +17,6 @@
package com.mongodb.internal.client.model;
import com.mongodb.CursorType;
-import com.mongodb.annotations.Alpha;
-import com.mongodb.annotations.Reason;
-import com.mongodb.client.cursor.TimeoutMode;
import com.mongodb.client.model.Collation;
import com.mongodb.lang.Nullable;
import org.bson.BsonString;
@@ -57,7 +54,6 @@ public final class FindOptions {
private boolean returnKey;
private boolean showRecordId;
private Boolean allowDiskUse;
- private TimeoutMode timeoutMode;
/**
* Construct a new instance.
@@ -70,8 +66,7 @@ public FindOptions() {
final int batchSize, final int limit, final Bson projection, final long maxTimeMS, final long maxAwaitTimeMS, final int skip,
final Bson sort, final CursorType cursorType, final boolean noCursorTimeout, final boolean partial,
final Collation collation, final BsonValue comment, final Bson hint, final String hintString, final Bson variables,
- final Bson max, final Bson min, final boolean returnKey, final boolean showRecordId, final Boolean allowDiskUse,
- final TimeoutMode timeoutMode) {
+ final Bson max, final Bson min, final boolean returnKey, final boolean showRecordId, final Boolean allowDiskUse) {
this.batchSize = batchSize;
this.limit = limit;
this.projection = projection;
@@ -92,13 +87,12 @@ public FindOptions() {
this.returnKey = returnKey;
this.showRecordId = showRecordId;
this.allowDiskUse = allowDiskUse;
- this.timeoutMode = timeoutMode;
}
//CHECKSTYLE:ON
public FindOptions withBatchSize(final int batchSize) {
return new FindOptions(batchSize, limit, projection, maxTimeMS, maxAwaitTimeMS, skip, sort, cursorType, noCursorTimeout,
- partial, collation, comment, hint, hintString, variables, max, min, returnKey, showRecordId, allowDiskUse, timeoutMode);
+ partial, collation, comment, hint, hintString, variables, max, min, returnKey, showRecordId, allowDiskUse);
}
/**
@@ -230,41 +224,6 @@ public FindOptions batchSize(final int batchSize) {
return this;
}
- /**
- * Sets the timeoutMode for the cursor.
- *
- *
- * Requires the {@code timeout} to be set, either in the {@link com.mongodb.MongoClientSettings},
- * via {@code MongoDatabase} or via {@code MongoCollection}
- *
- *
- * If the {@code timeout} is set then:
- *
- *
For non-tailable cursors, the default value of timeoutMode is {@link TimeoutMode#CURSOR_LIFETIME}
- *
For tailable cursors, the default value of timeoutMode is {@link TimeoutMode#ITERATION} and its an error
- * to configure it as: {@link TimeoutMode#CURSOR_LIFETIME}
This class is not part of the public API and may be removed or changed at any time
@@ -30,6 +29,6 @@ protected boolean shouldMarkSessionDirty(final Throwable e, final SessionContext
if (!sessionContext.hasSession()) {
return false;
}
- return isMongoSocketException(e) || isOperationTimeoutFromSocketException(e);
+ return isMongoSocketException(e);
}
}
diff --git a/driver-core/src/main/com/mongodb/internal/connection/BaseCluster.java b/driver-core/src/main/com/mongodb/internal/connection/BaseCluster.java
index e9dfccc3388..cf570fe3250 100644
--- a/driver-core/src/main/com/mongodb/internal/connection/BaseCluster.java
+++ b/driver-core/src/main/com/mongodb/internal/connection/BaseCluster.java
@@ -20,7 +20,6 @@
import com.mongodb.MongoException;
import com.mongodb.MongoIncompatibleDriverException;
import com.mongodb.MongoInterruptedException;
-import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoTimeoutException;
import com.mongodb.ServerAddress;
import com.mongodb.UnixServerAddress;
@@ -432,8 +431,7 @@ private void logAndThrowTimeoutException(
"Timed out while waiting for a server that matches %s. Client view of cluster state is %s",
serverSelector, clusterDescription.getShortDescription());
- MongoTimeoutException exception = operationContext.getTimeoutContext().hasTimeoutMS()
- ? new MongoOperationTimeoutException(message) : new MongoTimeoutException(message);
+ MongoTimeoutException exception = new MongoTimeoutException(message);
logServerSelectionFailed(operationContext, clusterId, exception, serverSelector, clusterDescription);
throw exception;
diff --git a/driver-core/src/main/com/mongodb/internal/connection/CommandHelper.java b/driver-core/src/main/com/mongodb/internal/connection/CommandHelper.java
index 51a6c5f0213..8ff42e0966f 100644
--- a/driver-core/src/main/com/mongodb/internal/connection/CommandHelper.java
+++ b/driver-core/src/main/com/mongodb/internal/connection/CommandHelper.java
@@ -125,15 +125,12 @@ private static CommandMessage getCommandMessage(final String database, final Bso
/**
- * Appends a user-defined maxTimeMS to the command if CSOT is not enabled.
+ * Appends a user-defined maxTimeMS to the command.
* This is necessary when maxTimeMS must be explicitly set on the command being explained,
- * rather than appending it lazily to the explain command in the {@link CommandMessage} via {@link TimeoutContext#setMaxTimeOverride(long)}.
- * This ensures backwards compatibility with pre-CSOT behavior.
+ * rather than appending it lazily to the explain command in the {@link CommandMessage}.
*/
public static void applyMaxTimeMS(final TimeoutContext timeoutContext, final BsonDocument command) {
- if (!timeoutContext.hasTimeoutMS()) {
- command.append("maxTimeMS", new BsonInt64(timeoutContext.getTimeoutSettings().getMaxTimeMS()));
- }
+ command.append("maxTimeMS", new BsonInt64(timeoutContext.getTimeoutSettings().getMaxTimeMS()));
}
private CommandHelper() {
diff --git a/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java b/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java
index a0a8bbe6e2d..5a1cd6ba102 100644
--- a/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java
+++ b/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java
@@ -42,7 +42,6 @@
import com.mongodb.event.ConnectionPoolListener;
import com.mongodb.event.ConnectionPoolReadyEvent;
import com.mongodb.event.ConnectionReadyEvent;
-import com.mongodb.internal.TimeoutContext;
import com.mongodb.internal.VisibleForTesting;
import com.mongodb.internal.async.SingleResultCallback;
import com.mongodb.internal.connection.SdamServerDescriptionManager.SdamIssue;
@@ -99,7 +98,6 @@
import static com.mongodb.event.ConnectionClosedEvent.Reason.ERROR;
import static com.mongodb.internal.Locks.lockInterruptibly;
import static com.mongodb.internal.Locks.withLock;
-import static com.mongodb.internal.TimeoutContext.createMongoTimeoutException;
import static com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE;
import static com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback;
import static com.mongodb.internal.connection.ConcurrentPool.INFINITE_SIZE;
@@ -195,7 +193,7 @@ public InternalConnection get(final OperationContext operationContext) {
Timeout maxWaitTimeout = operationContext.getTimeoutContext().startMaxWaitTimeout(checkoutStart);
try {
stateAndGeneration.throwIfClosedOrPaused();
- PooledConnection connection = getPooledConnection(maxWaitTimeout, checkoutStart, operationContext.getTimeoutContext());
+ PooledConnection connection = getPooledConnection(maxWaitTimeout, checkoutStart);
if (!connection.opened()) {
connection = openConcurrencyLimiter.openOrGetAvailable(operationContext, connection, maxWaitTimeout, checkoutStart);
}
@@ -227,13 +225,13 @@ public void getAsync(final OperationContext operationContext, final SingleResult
eventSendingCallback.onResult(null, e);
return;
}
- asyncWorkManager.enqueue(new Task(maxWaitTimeout, checkoutStart, operationContext.getTimeoutContext(), t -> {
+ asyncWorkManager.enqueue(new Task(maxWaitTimeout, checkoutStart, t -> {
if (t != null) {
eventSendingCallback.onResult(null, t);
} else {
PooledConnection connection;
try {
- connection = getPooledConnection(maxWaitTimeout, checkoutStart, operationContext.getTimeoutContext());
+ connection = getPooledConnection(maxWaitTimeout, checkoutStart);
} catch (Exception e) {
eventSendingCallback.onResult(null, e);
return;
@@ -333,8 +331,7 @@ public int getGeneration() {
}
private PooledConnection getPooledConnection(final Timeout maxWaitTimeout,
- final StartTime startTime,
- final TimeoutContext timeoutContext) throws MongoTimeoutException {
+ final StartTime startTime) throws MongoTimeoutException {
try {
UsageTrackingInternalConnection internalConnection = maxWaitTimeout.call(NANOSECONDS,
() -> pool.get(-1L, NANOSECONDS),
@@ -349,7 +346,7 @@ private PooledConnection getPooledConnection(final Timeout maxWaitTimeout,
}
return new PooledConnection(internalConnection);
} catch (MongoTimeoutException e) {
- throw createTimeoutException(startTime, e, timeoutContext);
+ throw createTimeoutException(startTime, e);
}
}
@@ -364,8 +361,7 @@ private PooledConnection getPooledConnectionImmediate() {
}
private MongoTimeoutException createTimeoutException(final StartTime startTime,
- @Nullable final MongoTimeoutException cause,
- final TimeoutContext timeoutContext) {
+ @Nullable final MongoTimeoutException cause) {
long elapsedMs = startTime.elapsed().toMillis();
int numPinnedToCursor = pinnedStatsManager.getNumPinnedToCursor();
int numPinnedToTransaction = pinnedStatsManager.getNumPinnedToTransaction();
@@ -410,7 +406,7 @@ private MongoTimeoutException createTimeoutException(final StartTime startTime,
numOtherInUse);
}
- return timeoutContext.hasTimeoutMS() ? createMongoTimeoutException(errorMessage, cause) : new MongoTimeoutException(errorMessage, cause);
+ return new MongoTimeoutException(errorMessage, cause);
}
@VisibleForTesting(otherwise = PRIVATE)
@@ -431,7 +427,7 @@ void doMaintenance() {
if (shouldEnsureMinSize()) {
pool.ensureMinSize(settings.getMinSize(), newConnection -> {
try {
- OperationContext operationContext = operationContextFactory.createMaintenanceContext();
+ OperationContext operationContext = operationContextFactory.create();
openConcurrencyLimiter.openImmediatelyAndTryHandOverOrRelease(operationContext, new PooledConnection(newConnection));
} catch (MongoException | MongoOpenConnectionInternalException e) {
RuntimeException actualException = e instanceof MongoOpenConnectionInternalException
@@ -975,8 +971,8 @@ private PooledConnection openWithConcurrencyLimit(final OperationContext operati
PooledConnection availableConnection;
try {//phase one
availableConnection = acquirePermitOrGetAvailableOpenedConnection(
- mode == OpenWithConcurrencyLimitMode.TRY_GET_AVAILABLE, maxWaitTimeout, startTime,
- operationContext.getTimeoutContext());
+ mode == OpenWithConcurrencyLimitMode.TRY_GET_AVAILABLE, maxWaitTimeout, startTime
+ );
} catch (Exception e) {
connection.closeSilently();
throw e;
@@ -1019,7 +1015,7 @@ void openWithConcurrencyLimitAsync(
PooledConnection availableConnection;
try {//phase one
availableConnection =
- acquirePermitOrGetAvailableOpenedConnection(true, maxWaitTimeout, startTime, operationContext.getTimeoutContext());
+ acquirePermitOrGetAvailableOpenedConnection(true, maxWaitTimeout, startTime);
} catch (Exception e) {
connection.closeSilently();
callback.onResult(null, e);
@@ -1050,8 +1046,7 @@ void openWithConcurrencyLimitAsync(
*/
@Nullable
private PooledConnection acquirePermitOrGetAvailableOpenedConnection(final boolean tryGetAvailable,
- final Timeout maxWaitTimeout, final StartTime startTime,
- final TimeoutContext timeoutContext)
+ final Timeout maxWaitTimeout, final StartTime startTime)
throws MongoTimeoutException, MongoInterruptedException {
PooledConnection availableConnection = null;
boolean expressedDesireToGetAvailableConnection = false;
@@ -1080,7 +1075,7 @@ private PooledConnection acquirePermitOrGetAvailableOpenedConnection(final boole
& (availableConnection = tryGetAvailable ? tryGetAvailableConnection() : null) == null) {
Timeout.onExistsAndExpired(maxWaitTimeout, () -> {
- throw createTimeoutException(startTime, null, timeoutContext);
+ throw createTimeoutException(startTime, null);
});
maxWaitTimeout.awaitOn(permitAvailableOrHandedOverOrClosedOrPausedCondition,
() -> "acquiring permit or getting available opened connection");
@@ -1401,15 +1396,12 @@ final class Task {
private final Timeout timeout;
private final StartTime startTime;
private final Consumer action;
- private final TimeoutContext timeoutContext;
private boolean completed;
Task(final Timeout timeout,
final StartTime startTime,
- final TimeoutContext timeoutContext,
final Consumer action) {
this.timeout = timeout;
- this.timeoutContext = timeoutContext;
this.startTime = startTime;
this.action = action;
}
@@ -1423,7 +1415,7 @@ void failAsClosed() {
}
void failAsTimedOut() {
- doComplete(() -> createTimeoutException(startTime, null, timeoutContext));
+ doComplete(() -> createTimeoutException(startTime, null));
}
private void doComplete(final Supplier failureSupplier) {
diff --git a/driver-core/src/main/com/mongodb/internal/connection/InternalOperationContextFactory.java b/driver-core/src/main/com/mongodb/internal/connection/InternalOperationContextFactory.java
index 851ca5a38ca..26f8e510700 100644
--- a/driver-core/src/main/com/mongodb/internal/connection/InternalOperationContextFactory.java
+++ b/driver-core/src/main/com/mongodb/internal/connection/InternalOperationContextFactory.java
@@ -16,7 +16,6 @@
package com.mongodb.internal.connection;
import com.mongodb.ServerApi;
-import com.mongodb.internal.TimeoutContext;
import com.mongodb.internal.TimeoutSettings;
import com.mongodb.internal.thread.AsyncClientExecutor;
import com.mongodb.lang.Nullable;
@@ -40,17 +39,9 @@ public InternalOperationContextFactory(
}
/**
- * @return a simple operation context without timeoutMS
+ * @return a simple operation context
*/
OperationContext create() {
return simpleOperationContext(timeoutSettings.connectionOnly(), serverApi, clientExecutor);
}
-
- /**
- * @return a simple operation context with timeoutMS if set at the MongoClientSettings level
- */
-
- OperationContext createMaintenanceContext() {
- return create().withTimeoutContext(TimeoutContext.createMaintenanceTimeoutContext(timeoutSettings));
- }
}
diff --git a/driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnection.java b/driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnection.java
index bdeba4211a4..614d42ea3c7 100644
--- a/driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnection.java
+++ b/driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnection.java
@@ -24,12 +24,10 @@
import com.mongodb.MongoExecutionTimeoutException;
import com.mongodb.MongoInternalException;
import com.mongodb.MongoInterruptedException;
-import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoSocketClosedException;
import com.mongodb.MongoSocketReadException;
import com.mongodb.MongoSocketReadTimeoutException;
import com.mongodb.MongoSocketWriteException;
-import com.mongodb.MongoSocketWriteTimeoutException;
import com.mongodb.ServerAddress;
import com.mongodb.annotations.NotThreadSafe;
import com.mongodb.connection.AsyncCompletionHandler;
@@ -52,7 +50,6 @@
import com.mongodb.internal.logging.StructuredLogger;
import com.mongodb.internal.observability.micrometer.Span;
import com.mongodb.internal.session.SessionContext;
-import com.mongodb.internal.time.Timeout;
import com.mongodb.lang.Nullable;
import com.mongodb.observability.micrometer.MongodbObservationContext;
import org.bson.BsonBinaryReader;
@@ -81,7 +78,6 @@
import static com.mongodb.assertions.Assertions.notNull;
import static com.mongodb.internal.ExceptionUtils.mapUnlessError;
import static com.mongodb.internal.ExceptionUtils.rethrowIfError;
-import static com.mongodb.internal.TimeoutContext.createMongoTimeoutException;
import static com.mongodb.internal.async.AsyncRunnable.beginAsync;
import static com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback;
import static com.mongodb.internal.connection.Authenticator.shouldAuthenticate;
@@ -171,18 +167,6 @@ public InternalStreamConnection(final ClusterConnectionMode clusterConnectionMod
LoggerSettings.builder().build(), commandListener, connectionInitializer, false);
}
- public InternalStreamConnection(final ClusterConnectionMode clusterConnectionMode,
- @Nullable final Authenticator authenticator,
- final boolean isMonitoringConnection,
- final ServerId serverId,
- final ConnectionGenerationSupplier connectionGenerationSupplier,
- final StreamFactory streamFactory, final List compressorList,
- final LoggerSettings loggerSettings,
- final CommandListener commandListener, final InternalConnectionInitializer connectionInitializer) {
- this(clusterConnectionMode, authenticator, isMonitoringConnection, serverId, connectionGenerationSupplier,
- streamFactory, compressorList, loggerSettings, commandListener, connectionInitializer, false);
- }
-
public InternalStreamConnection(final ClusterConnectionMode clusterConnectionMode,
@Nullable final Authenticator authenticator,
final boolean isMonitoringConnection,
@@ -555,9 +539,6 @@ private void sendCommandMessage(final CommandMessage message, final ByteBufferBs
private void trySendMessage(final CommandMessage message, final ByteBufferBsonOutput bsonOutput,
final OperationContext operationContext) {
- Timeout.onExistsAndExpired(operationContext.getTimeoutContext().timeoutIncludingRoundTrip(), () -> {
- throw TimeoutContext.createMongoRoundTripTimeoutException();
- });
List byteBuffers = bsonOutput.getByteBuffers();
try {
sendMessage(byteBuffers, message.getId(), operationContext);
@@ -608,13 +589,13 @@ private T processCommandResponse(final Decoder decoder, final ResponseBuf
updateSessionContext(operationContext.getSessionContext(), responseBuffers);
if (!isCommandOk(responseBuffers)) {
throw getCommandFailureException(responseBuffers.getResponseDocument(responseTo,
- new BsonDocumentCodec()), description.getServerAddress(), operationContext.getTimeoutContext());
+ new BsonDocumentCodec()), description.getServerAddress());
}
commandEventSender.sendSucceededEvent(responseBuffers);
commandSuccessful = true;
- T commandResult = getCommandResult(decoder, responseBuffers, responseTo, operationContext.getTimeoutContext());
+ T commandResult = getCommandResult(decoder, responseBuffers, responseTo);
hasMoreToCome = responseBuffers.getReplyHeader().hasMoreToCome();
if (hasMoreToCome) {
responseTo = responseBuffers.getReplyHeader().getRequestId();
@@ -646,8 +627,7 @@ private void recordTracingError(@Nullable final Span tracingSpan, final Throwabl
* Determines whether a failure raised while processing a command response leaves the connection
* reusable. This predicate is only ever applied to post-read failures — those raised after
* {@link #receiveResponseBuffers} (sync) or the {@code MessageHeaderCallback} (async) has fully read
- * the framed response off the wire. Read-path failures (including a CSOT read-timeout translated to
- * {@link MongoOperationTimeoutException}) are handled separately: the read path closes the connection
+ * the framed response off the wire. Read-path failures are handled separately: the read path closes the connection
* itself and never routes through this predicate, so no verdict here can leave a desynchronized stream
* in the pool. The types below are reusable because the stream remains synchronized:
*
@@ -655,8 +635,6 @@ private void recordTracingError(@Nullable final Span tracingSpan, final Throwabl
*
{@link MongoExecutionTimeoutException} — a server-side {@code MaxTimeMSExpired} ({@code ok: 0})
* error response; derived from the fully-read response body
*
{@link MongoWriteConcernWithResponseException} — a write concern error carrying the response
- *
{@link MongoOperationTimeoutException} — a write concern timeout, or a server-side
- * {@code MaxTimeMSExpired} ({@code ok: 0}) timeout wrapped for CSOT; both are derived from the response body
*
{@link BsonSerializationException} — a corrupt BSON body whose exact byte count was still consumed
*
* Any other failure (e.g. a responseTo mismatch or an unexpected error) may have left the stream
@@ -666,7 +644,6 @@ private static boolean connectionIsReusable(final Throwable failure) {
return failure instanceof MongoCommandException
|| failure instanceof MongoExecutionTimeoutException
|| failure instanceof MongoWriteConcernWithResponseException
- || failure instanceof MongoOperationTimeoutException
|| failure instanceof BsonSerializationException;
}
@@ -784,13 +761,6 @@ private void sendCommandMessageAsync(final int messageId, final Decoder d
final SingleResultCallback callback, final ByteBufferBsonOutput bsonOutput,
final CommandEventSender commandEventSender, final boolean responseExpected) {
boolean[] shouldReturn = {false};
- Timeout.onExistsAndExpired(operationContext.getTimeoutContext().timeoutIncludingRoundTrip(), () -> {
- bsonOutput.close();
- MongoOperationTimeoutException operationTimeoutException = TimeoutContext.createMongoRoundTripTimeoutException();
- commandEventSender.sendFailedEvent(operationTimeoutException);
- callback.onResult(null, operationTimeoutException);
- shouldReturn[0] = true;
- });
if (shouldReturn[0]) {
return;
}
@@ -825,12 +795,12 @@ private void sendCommandMessageAsync(final int messageId, final Decoder d
if (!commandOk) {
throw getCommandFailureException(
responseBuffers.getResponseDocument(messageId, new BsonDocumentCodec()),
- description.getServerAddress(), operationContext.getTimeoutContext());
+ description.getServerAddress());
}
commandEventSender.sendSucceededEvent(responseBuffers);
commandSuccessful = true;
- commandResult = getCommandResult(decoder, responseBuffers, messageId, operationContext.getTimeoutContext());
+ commandResult = getCommandResult(decoder, responseBuffers, messageId);
} catch (Throwable localThrowable) {
failure = localThrowable;
} finally {
@@ -865,15 +835,11 @@ private void assertResponseToMatches(final ResponseBuffers responseBuffers, fina
private T getCommandResult(final Decoder decoder,
final ResponseBuffers responseBuffers,
- final int messageId,
- final TimeoutContext timeoutContext) {
+ final int messageId) {
T result = new ReplyMessage<>(responseBuffers, decoder, messageId).getDocument();
MongoException writeConcernBasedError = createSpecialWriteConcernException(responseBuffers,
- description.getServerAddress(),
- timeoutContext);
- if (writeConcernBasedError instanceof MongoOperationTimeoutException) {
- throw writeConcernBasedError;
- }
+ description.getServerAddress()
+ );
if (writeConcernBasedError != null) {
throw new MongoWriteConcernWithResponseException(writeConcernBasedError, result);
}
@@ -890,7 +856,7 @@ public void sendMessage(final List byteBuffers, final int lastRequestId
stream.write(byteBuffers, operationContext);
} catch (Throwable t) {
close();
- throwTranslatedWriteException(t, operationContext);
+ throwTranslatedWriteException(t);
}
}
@@ -911,7 +877,7 @@ public void sendMessageAsync(
}, Throwable.class, (t, c) -> {
try {
close();
- throwTranslatedWriteException(t, operationContext);
+ throwTranslatedWriteException(t);
} catch (Throwable translatedException) {
c.completeExceptionally(translatedException);
}
@@ -964,12 +930,12 @@ public void completed(@Nullable final ByteBuf buffer) {
@Override
public void failed(final Throwable t) {
close();
- callback.onResult(null, mapUnlessError(t, e -> translateReadException(e, operationContext)));
+ callback.onResult(null, mapUnlessError(t, e -> translateReadException(e)));
}
});
} catch (Throwable t) {
close();
- callback.onResult(null, mapUnlessError(t, e -> translateReadException(e, operationContext)));
+ callback.onResult(null, mapUnlessError(t, e -> translateReadException(e)));
}
}
@@ -993,17 +959,8 @@ private void updateSessionContext(final SessionContext sessionContext, final Res
}
}
- private void throwTranslatedWriteException(final Throwable e, final OperationContext operationContext) {
+ private void throwTranslatedWriteException(final Throwable e) {
rethrowIfError(e);
- if (operationContext.getTimeoutContext().hasTimeoutMS()) {
- if (e instanceof MongoSocketWriteTimeoutException) {
- throw createMongoTimeoutException(e);
- } else if (e instanceof SocketTimeoutException) {
- // A blocking (SSL) write can surface the socket read-timeout as a bare SocketTimeoutException;
- // mirror translateReadException so it is reported as a timeout rather than a generic write error.
- throw createMongoTimeoutException(createWriteTimeoutException((SocketTimeoutException) e));
- }
- }
if (e instanceof MongoException) {
throw (MongoException) e;
@@ -1018,19 +975,7 @@ private void throwTranslatedWriteException(final Throwable e, final OperationCon
}
}
- private MongoSocketWriteTimeoutException createWriteTimeoutException(final SocketTimeoutException e) {
- return new MongoSocketWriteTimeoutException("Timeout while sending message", getServerAddress(), e);
- }
-
- private MongoException translateReadException(final Throwable e, final OperationContext operationContext) {
- if (operationContext.getTimeoutContext().hasTimeoutMS()) {
- if (e instanceof SocketTimeoutException) {
- return createMongoTimeoutException(createReadTimeoutException((SocketTimeoutException) e));
- } else if (e instanceof MongoSocketReadTimeoutException) {
- return createMongoTimeoutException((e));
- }
- }
-
+ private MongoException translateReadException(final Throwable e) {
if (e instanceof MongoException) {
return (MongoException) e;
}
@@ -1095,7 +1040,7 @@ private ResponseBuffers receiveResponseBuffers(final OperationContext operationC
}
close();
rethrowIfError(t);
- throw translateReadException(t, operationContext);
+ throw translateReadException(t);
}
}
diff --git a/driver-core/src/main/com/mongodb/internal/connection/LoadBalancedCluster.java b/driver-core/src/main/com/mongodb/internal/connection/LoadBalancedCluster.java
index 69c899396cf..0c86d1cb3ed 100644
--- a/driver-core/src/main/com/mongodb/internal/connection/LoadBalancedCluster.java
+++ b/driver-core/src/main/com/mongodb/internal/connection/LoadBalancedCluster.java
@@ -19,7 +19,6 @@
import com.mongodb.MongoClientException;
import com.mongodb.MongoException;
import com.mongodb.MongoInterruptedException;
-import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoTimeoutException;
import com.mongodb.ServerAddress;
import com.mongodb.annotations.ThreadSafe;
@@ -193,7 +192,7 @@ public ServersSnapshot getServersSnapshot(
final Timeout serverSelectionTimeout,
final TimeoutContext timeoutContext) {
isTrue("open", !isClosed());
- waitForSrv(serverSelectionTimeout, timeoutContext);
+ waitForSrv(serverSelectionTimeout);
ClusterableServer server = assertNotNull(this.server);
return serverAddress -> server;
}
@@ -219,7 +218,7 @@ public ClientMetadata getClientMetadata() {
public ServerTuple selectServer(final ServerSelector serverSelector, final OperationContext operationContext) {
isTrue("open", !isClosed());
Timeout computedServerSelectionTimeout = operationContext.getTimeoutContext().computeServerSelectionTimeout();
- waitForSrv(computedServerSelectionTimeout, operationContext.getTimeoutContext());
+ waitForSrv(computedServerSelectionTimeout);
if (srvRecordResolvedToMultipleHosts) {
throw createResolvedToMultipleHostsException();
}
@@ -231,7 +230,7 @@ public ServerTuple selectServer(final ServerSelector serverSelector, final Opera
return serverTuple;
}
- private void waitForSrv(final Timeout serverSelectionTimeout, final TimeoutContext timeoutContext) {
+ private void waitForSrv(final Timeout serverSelectionTimeout) {
if (initializationCompleted) {
return;
}
@@ -241,7 +240,7 @@ private void waitForSrv(final Timeout serverSelectionTimeout, final TimeoutConte
throw createShutdownException();
}
serverSelectionTimeout.onExpired(() -> {
- throw createTimeoutException(timeoutContext);
+ throw createTimeoutException();
});
serverSelectionTimeout.awaitOn(condition, () -> format("resolving SRV records for %s", settings.getSrvHost()));
}
@@ -324,7 +323,7 @@ private MongoClientException createResolvedToMultipleHostsException() {
+ "to multiple hosts");
}
- private MongoTimeoutException createTimeoutException(final TimeoutContext timeoutContext) {
+ private MongoTimeoutException createTimeoutException() {
MongoException localSrvResolutionException = srvResolutionException;
String message;
if (localSrvResolutionException == null) {
@@ -333,11 +332,11 @@ private MongoTimeoutException createTimeoutException(final TimeoutContext timeou
message = format("Timed out while waiting to resolve SRV records for %s. "
+ "Resolution exception was '%s'", settings.getSrvHost(), localSrvResolutionException);
}
- return createTimeoutException(timeoutContext, message);
+ return createTimeoutException(message);
}
- private static MongoTimeoutException createTimeoutException(final TimeoutContext timeoutContext, final String message) {
- return timeoutContext.hasTimeoutMS() ? new MongoOperationTimeoutException(message) : new MongoTimeoutException(message);
+ private static MongoTimeoutException createTimeoutException(final String message) {
+ return new MongoTimeoutException(message);
}
private void notifyWaitQueueHandler(final ServerSelectionRequest request) {
@@ -399,9 +398,7 @@ public void run() {
} finally {
lock.unlock();
}
- timeoutList.forEach(request -> request.onError(createTimeoutException(request
- .getOperationContext()
- .getTimeoutContext())));
+ timeoutList.forEach(request -> request.onError(createTimeoutException()));
timeoutList.clear();
}
diff --git a/driver-core/src/main/com/mongodb/internal/connection/OidcAuthenticator.java b/driver-core/src/main/com/mongodb/internal/connection/OidcAuthenticator.java
index 5920bbc8756..83a58eca495 100644
--- a/driver-core/src/main/com/mongodb/internal/connection/OidcAuthenticator.java
+++ b/driver-core/src/main/com/mongodb/internal/connection/OidcAuthenticator.java
@@ -47,12 +47,10 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Duration;
-import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.mongodb.AuthenticationMechanism.MONGODB_OIDC;
@@ -68,7 +66,6 @@
import static com.mongodb.assertions.Assertions.assertFalse;
import static com.mongodb.assertions.Assertions.assertNotNull;
import static com.mongodb.assertions.Assertions.assertTrue;
-import static com.mongodb.internal.TimeoutContext.throwMongoTimeoutException;
import static com.mongodb.internal.async.AsyncRunnable.beginAsync;
import static com.mongodb.internal.connection.OidcAuthenticator.OidcValidator.validateBeforeUse;
import static java.lang.String.format;
@@ -129,16 +126,6 @@ private Duration getCallbackTimeout(final TimeoutContext timeoutContext) {
if (isHumanCallback()) {
return HUMAN_CALLBACK_TIMEOUT;
}
-
- if (timeoutContext.hasTimeoutMS()) {
- return assertNotNull(timeoutContext.getTimeout()).call(TimeUnit.MILLISECONDS,
- () ->
- // we can get here if server selection timeout was set to infinite.
- ChronoUnit.FOREVER.getDuration(),
- (remainingMs) -> Duration.ofMillis(remainingMs),
- () -> throwMongoTimeoutException());
-
- }
return CALLBACK_TIMEOUT;
}
diff --git a/driver-core/src/main/com/mongodb/internal/connection/ProtocolHelper.java b/driver-core/src/main/com/mongodb/internal/connection/ProtocolHelper.java
index c6ad5f451a0..2389efac9e6 100644
--- a/driver-core/src/main/com/mongodb/internal/connection/ProtocolHelper.java
+++ b/driver-core/src/main/com/mongodb/internal/connection/ProtocolHelper.java
@@ -32,7 +32,6 @@
import com.mongodb.event.CommandStartedEvent;
import com.mongodb.event.CommandSucceededEvent;
import com.mongodb.internal.IgnorableRequestContext;
-import com.mongodb.internal.TimeoutContext;
import com.mongodb.internal.diagnostics.logging.Logger;
import com.mongodb.internal.diagnostics.logging.Loggers;
import com.mongodb.lang.Nullable;
@@ -86,13 +85,12 @@ static boolean isCommandOk(final ResponseBuffers responseBuffers) {
@Nullable
static MongoException createSpecialWriteConcernException(final ResponseBuffers responseBuffers,
- final ServerAddress serverAddress,
- final TimeoutContext timeoutContext) {
+ final ServerAddress serverAddress) {
BsonValue writeConcernError = getField(createBsonReader(responseBuffers), "writeConcernError");
if (writeConcernError == null) {
return null;
} else {
- return createSpecialException(writeConcernError.asDocument(), serverAddress, "errmsg", timeoutContext);
+ return createSpecialException(writeConcernError.asDocument(), serverAddress, "errmsg");
}
}
@@ -201,9 +199,8 @@ private static boolean isCommandOk(@Nullable final BsonValue okValue) {
}
}
- static MongoException getCommandFailureException(final BsonDocument response, final ServerAddress serverAddress,
- final TimeoutContext timeoutContext) {
- MongoException specialException = createSpecialException(response, serverAddress, "errmsg", timeoutContext);
+ static MongoException getCommandFailureException(final BsonDocument response, final ServerAddress serverAddress) {
+ MongoException specialException = createSpecialException(response, serverAddress, "errmsg");
if (specialException != null) {
return specialException;
}
@@ -218,9 +215,8 @@ static String getErrorMessage(final BsonDocument response, final String errorMes
return response.getString(errorMessageFieldName, new BsonString("")).getValue();
}
- static MongoException getQueryFailureException(final BsonDocument errorDocument, final ServerAddress serverAddress,
- final TimeoutContext timeoutContext) {
- MongoException specialException = createSpecialException(errorDocument, serverAddress, "$err", timeoutContext);
+ static MongoException getQueryFailureException(final BsonDocument errorDocument, final ServerAddress serverAddress) {
+ MongoException specialException = createSpecialException(errorDocument, serverAddress, "$err");
if (specialException != null) {
return specialException;
}
@@ -247,26 +243,21 @@ static MessageSettings getMessageSettings(final ConnectionDescription connection
@Nullable
public static MongoException createSpecialException(@Nullable final BsonDocument response,
final ServerAddress serverAddress,
- final String errorMessageFieldName,
- final TimeoutContext timeoutContext) {
+ final String errorMessageFieldName) {
if (response == null) {
return null;
}
int errorCode = getErrorCode(response);
String errorMessage = getErrorMessage(response, errorMessageFieldName);
if (ErrorCategory.fromErrorCode(errorCode) == ErrorCategory.EXECUTION_TIMEOUT) {
- MongoExecutionTimeoutException mongoExecutionTimeoutException = new MongoExecutionTimeoutException(errorCode, errorMessage, response);
- if (timeoutContext.hasTimeoutMS()) {
- return TimeoutContext.createMongoTimeoutException(mongoExecutionTimeoutException);
- }
- return mongoExecutionTimeoutException;
+ return new MongoExecutionTimeoutException(errorCode, errorMessage, response);
} else if (isNodeIsRecoveringError(errorCode, errorMessage)) {
return new MongoNodeIsRecoveringException(response, serverAddress);
} else if (isNotPrimaryError(errorCode, errorMessage)) {
return new MongoNotPrimaryException(response, serverAddress);
} else if (response.containsKey("writeConcernError")) {
MongoException writeConcernException = createSpecialException(response.getDocument("writeConcernError"), serverAddress,
- "errmsg", timeoutContext);
+ "errmsg");
if (writeConcernException != null && response.isArray("errorLabels")) {
for (BsonValue errorLabel : response.getArray("errorLabels")) {
writeConcernException.addLabel(errorLabel.asString().getValue());
diff --git a/driver-core/src/main/com/mongodb/internal/connection/SaslAuthenticator.java b/driver-core/src/main/com/mongodb/internal/connection/SaslAuthenticator.java
index 050a4862b17..f3a789ecfc4 100644
--- a/driver-core/src/main/com/mongodb/internal/connection/SaslAuthenticator.java
+++ b/driver-core/src/main/com/mongodb/internal/connection/SaslAuthenticator.java
@@ -20,7 +20,6 @@
import com.mongodb.MongoCredential;
import com.mongodb.MongoException;
import com.mongodb.MongoInterruptedException;
-import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoSecurityException;
import com.mongodb.ServerAddress;
import com.mongodb.ServerApi;
@@ -285,8 +284,6 @@ private void disposeOfSaslClient(final SaslClient saslClient) {
protected MongoException wrapException(final Throwable t) {
if (t instanceof MongoInterruptedException) {
return (MongoInterruptedException) t;
- } else if (t instanceof MongoOperationTimeoutException) {
- return (MongoOperationTimeoutException) t;
} else if (t instanceof MongoSecurityException) {
return (MongoSecurityException) t;
} else {
diff --git a/driver-core/src/main/com/mongodb/internal/connection/SocketStream.java b/driver-core/src/main/com/mongodb/internal/connection/SocketStream.java
index 764f41034f2..491093ce242 100644
--- a/driver-core/src/main/com/mongodb/internal/connection/SocketStream.java
+++ b/driver-core/src/main/com/mongodb/internal/connection/SocketStream.java
@@ -46,7 +46,6 @@
import static com.mongodb.assertions.Assertions.assertTrue;
import static com.mongodb.assertions.Assertions.notNull;
-import static com.mongodb.internal.TimeoutContext.throwMongoTimeoutException;
import static com.mongodb.internal.connection.ServerAddressHelper.getSocketAddresses;
import static com.mongodb.internal.connection.SocketStreamHelper.configureSocket;
import static com.mongodb.internal.connection.SslHelper.configureSslSocket;
@@ -204,9 +203,6 @@ public ByteBuf getBuffer(final int size) {
public void write(final List buffers, final OperationContext operationContext) throws IOException {
for (final ByteBuf cur : buffers) {
outputStream.write(cur.array(), 0, cur.limit());
- operationContext.getTimeoutContext().onExpired(() -> {
- throwMongoTimeoutException("Socket write exceeded the timeout limit.");
- });
}
}
diff --git a/driver-core/src/main/com/mongodb/internal/operation/AbstractWriteSearchIndexOperation.java b/driver-core/src/main/com/mongodb/internal/operation/AbstractWriteSearchIndexOperation.java
index 375280c90c7..1d0fb84efad 100644
--- a/driver-core/src/main/com/mongodb/internal/operation/AbstractWriteSearchIndexOperation.java
+++ b/driver-core/src/main/com/mongodb/internal/operation/AbstractWriteSearchIndexOperation.java
@@ -74,7 +74,7 @@ public Void execute(final WriteBinding binding, final OperationContext operation
try {
executeCommand(binding, operationContextWithMinRtt, namespace.getDatabaseName(), buildCommand(),
connection,
- writeConcernErrorTransformer(operationContextWithMinRtt.getTimeoutContext()));
+ writeConcernErrorTransformer());
} catch (MongoCommandException mongoCommandException) {
swallowOrThrow(mongoCommandException);
}
@@ -94,7 +94,7 @@ public void executeAsync(final AsyncWriteBinding binding, final OperationContext
withAsyncSourceAndConnection(binding::getWriteConnectionSource, false, operationContext, supplierCallback,
(connectionSource, connection, operationContextWithMinRtt, cb) ->
executeCommandAsync(binding, operationContextWithMinRtt, namespace.getDatabaseName(), buildCommand(),
- connection, writeConcernErrorTransformerAsync(operationContextWithMinRtt.getTimeoutContext()),
+ connection, writeConcernErrorTransformerAsync(),
(result, commandExecutionError) -> {
try {
swallowOrThrow(commandExecutionError);
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 07ce3ce62bb..bf47a7f662d 100644
--- a/driver-core/src/main/com/mongodb/internal/operation/AggregateOperation.java
+++ b/driver-core/src/main/com/mongodb/internal/operation/AggregateOperation.java
@@ -18,7 +18,6 @@
import com.mongodb.ExplainVerbosity;
import com.mongodb.MongoNamespace;
-import com.mongodb.client.cursor.TimeoutMode;
import com.mongodb.client.model.Collation;
import com.mongodb.internal.async.AsyncBatchCursor;
import com.mongodb.internal.async.SingleResultCallback;
@@ -132,11 +131,6 @@ public AggregateOperation hint(@Nullable final BsonValue hint) {
return this;
}
- public AggregateOperation timeoutMode(@Nullable final TimeoutMode timeoutMode) {
- wrapped.timeoutMode(timeoutMode);
- return this;
- }
-
@Override
public String getCommandName() {
return wrapped.getCommandName();
diff --git a/driver-core/src/main/com/mongodb/internal/operation/AggregateOperationImpl.java b/driver-core/src/main/com/mongodb/internal/operation/AggregateOperationImpl.java
index 0442571f41c..20e36886d5d 100644
--- a/driver-core/src/main/com/mongodb/internal/operation/AggregateOperationImpl.java
+++ b/driver-core/src/main/com/mongodb/internal/operation/AggregateOperationImpl.java
@@ -16,12 +16,9 @@
package com.mongodb.internal.operation;
-import com.mongodb.CursorType;
import com.mongodb.MongoNamespace;
-import com.mongodb.client.cursor.TimeoutMode;
import com.mongodb.client.model.Collation;
import com.mongodb.internal.TimeoutContext;
-import com.mongodb.internal.TimeoutSettings;
import com.mongodb.internal.async.AsyncBatchCursor;
import com.mongodb.internal.async.SingleResultCallback;
import com.mongodb.internal.binding.AsyncReadBinding;
@@ -47,7 +44,6 @@
import static com.mongodb.internal.operation.AsyncOperationHelper.executeRetryableReadAsync;
import static com.mongodb.internal.operation.CommandOperationHelper.CommandCreator;
import static com.mongodb.internal.operation.OperationHelper.LOGGER;
-import static com.mongodb.internal.operation.OperationHelper.applyTimeoutModeToOperationContext;
import static com.mongodb.internal.operation.OperationReadConcernHelper.appendReadConcernToCommand;
import static com.mongodb.internal.operation.SyncOperationHelper.CommandReadTransformer;
import static com.mongodb.internal.operation.SyncOperationHelper.executeRetryableRead;
@@ -73,8 +69,6 @@ class AggregateOperationImpl implements ReadOperationCursor {
private BsonValue comment;
private BsonValue hint;
private BsonDocument variables;
- private TimeoutMode timeoutMode;
- private CursorType cursorType;
AggregateOperationImpl(final MongoNamespace namespace,
final List pipeline, final Decoder decoder, final AggregationLevel aggregationLevel,
@@ -152,19 +146,6 @@ AggregateOperationImpl retryReads(final boolean retryReads) {
return this;
}
- /**
- * When {@link TimeoutContext#hasTimeoutMS()} then {@link TimeoutSettings#getMaxAwaitTimeMS()} usage in {@code getMore} commands
- * depends on the type of cursor. For {@link CursorType#TailableAwait} it is used, for others it is not.
- * {@link CursorType#TailableAwait} is used mainly for change streams in {@link AggregateOperationImpl}.
- *
- * @param cursorType
- * @return this
- */
- AggregateOperationImpl cursorType(final CursorType cursorType) {
- this.cursorType = cursorType;
- return this;
- }
-
boolean getRetryReads() {
return retryReads;
}
@@ -174,13 +155,6 @@ BsonValue getHint() {
return hint;
}
- public AggregateOperationImpl timeoutMode(@Nullable final TimeoutMode timeoutMode) {
- if (timeoutMode != null) {
- this.timeoutMode = timeoutMode;
- }
- return this;
- }
-
AggregateOperationImpl hint(@Nullable final BsonValue hint) {
isTrueArgument("BsonString or BsonDocument", hint == null || hint.isDocument() || hint.isString());
this.hint = hint;
@@ -199,7 +173,7 @@ public MongoNamespace getNamespace() {
@Override
public BatchCursor execute(final ReadBinding binding, final OperationContext operationContext) {
- return executeRetryableRead(binding, applyTimeoutModeToOperationContext(timeoutMode, operationContext), namespace.getDatabaseName(),
+ return executeRetryableRead(binding, operationContext, namespace.getDatabaseName(),
getCommandCreator(), CommandResultDocumentCodec.create(decoder, FIELD_NAMES_WITH_RESULT),
transformer(), retryReads, maxAdaptiveRetriesSetting);
}
@@ -207,7 +181,7 @@ public BatchCursor execute(final ReadBinding binding, final OperationContext
@Override
public void executeAsync(final AsyncReadBinding binding, final OperationContext operationContext, final SingleResultCallback> callback) {
SingleResultCallback> errHandlingCallback = errorHandlingCallback(callback, LOGGER);
- executeRetryableReadAsync(binding, applyTimeoutModeToOperationContext(timeoutMode, operationContext), namespace.getDatabaseName(),
+ executeRetryableReadAsync(binding, operationContext, namespace.getDatabaseName(),
getCommandCreator(), CommandResultDocumentCodec.create(decoder, FIELD_NAMES_WITH_RESULT),
asyncTransformer(), retryReads, maxAdaptiveRetriesSetting,
errHandlingCallback);
@@ -248,7 +222,7 @@ BsonDocument getCommand(final OperationContext operationContext, final int maxWi
private CommandReadTransformer> transformer() {
return (result, source, connection, operationContext) ->
- new CommandBatchCursor<>(getTimeoutMode(), getMaxTimeForCursor(operationContext.getTimeoutContext()), operationContext, new CommandCursor<>(
+ new CommandBatchCursor<>(getMaxTimeForCursor(operationContext.getTimeoutContext()), operationContext, new CommandCursor<>(
result, batchSize != null ? batchSize : 0,
decoder, comment, source, connection,
retryReads, maxAdaptiveRetriesSetting
@@ -257,27 +231,15 @@ private CommandReadTransformer> transformer(
private CommandReadTransformerAsync> asyncTransformer() {
return (result, source, connection, operationContext) ->
- new AsyncCommandBatchCursor<>(getTimeoutMode(), getMaxTimeForCursor(operationContext.getTimeoutContext()),
+ new AsyncCommandBatchCursor<>(getMaxTimeForCursor(operationContext.getTimeoutContext()),
operationContext, new AsyncCommandCursor<>(
result, batchSize != null ? batchSize : 0, decoder, comment, source, connection,
retryReads, maxAdaptiveRetriesSetting
));
}
- private TimeoutMode getTimeoutMode() {
- TimeoutMode localTimeoutMode = timeoutMode;
- if (localTimeoutMode == null) {
- localTimeoutMode = TimeoutMode.CURSOR_LIFETIME;
- }
- return localTimeoutMode;
- }
-
private long getMaxTimeForCursor(final TimeoutContext timeoutContext) {
- long maxAwaitTimeMS = timeoutContext.getMaxAwaitTimeMS();
- if (timeoutContext.hasTimeoutMS()){
- return CursorType.TailableAwait == cursorType ? maxAwaitTimeMS : 0;
- }
- return maxAwaitTimeMS;
+ return timeoutContext.getMaxAwaitTimeMS();
}
interface AggregateTarget {
diff --git a/driver-core/src/main/com/mongodb/internal/operation/AggregateToCollectionOperation.java b/driver-core/src/main/com/mongodb/internal/operation/AggregateToCollectionOperation.java
index 763c9d1a78f..e25a39d3658 100644
--- a/driver-core/src/main/com/mongodb/internal/operation/AggregateToCollectionOperation.java
+++ b/driver-core/src/main/com/mongodb/internal/operation/AggregateToCollectionOperation.java
@@ -20,7 +20,6 @@
import com.mongodb.ReadConcern;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
-import com.mongodb.client.cursor.TimeoutMode;
import com.mongodb.client.model.Collation;
import com.mongodb.internal.async.SingleResultCallback;
import com.mongodb.internal.binding.AsyncReadBinding;
@@ -162,11 +161,6 @@ public AggregateToCollectionOperation hint(@Nullable final BsonValue hint) {
return this;
}
- public AggregateToCollectionOperation timeoutMode(@Nullable final TimeoutMode timeoutMode) {
- isTrueArgument("timeoutMode cannot be ITERATION.", timeoutMode == null || timeoutMode.equals(TimeoutMode.CURSOR_LIFETIME));
- return this;
- }
-
@Override
public String getCommandName() {
return COMMAND_NAME;
@@ -249,7 +243,7 @@ private CommandOperationHelper.CommandCreator getCommandCreator() {
private static CommandReadTransformer transformer() {
return (result, source, connection, operationContext) -> {
throwOnWriteConcernError(result, connection.getDescription().getServerAddress(),
- connection.getDescription().getMaxWireVersion(), operationContext.getTimeoutContext());
+ connection.getDescription().getMaxWireVersion());
return null;
};
}
@@ -257,7 +251,7 @@ private static CommandReadTransformer transformer() {
private static CommandReadTransformerAsync asyncTransformer() {
return (result, source, connection, operationContext) -> {
throwOnWriteConcernError(result, connection.getDescription().getServerAddress(),
- connection.getDescription().getMaxWireVersion(), operationContext.getTimeoutContext());
+ connection.getDescription().getMaxWireVersion());
return null;
};
}
diff --git a/driver-core/src/main/com/mongodb/internal/operation/AsyncCommandBatchCursor.java b/driver-core/src/main/com/mongodb/internal/operation/AsyncCommandBatchCursor.java
index f390981694e..255d01c2a50 100644
--- a/driver-core/src/main/com/mongodb/internal/operation/AsyncCommandBatchCursor.java
+++ b/driver-core/src/main/com/mongodb/internal/operation/AsyncCommandBatchCursor.java
@@ -16,7 +16,6 @@
package com.mongodb.internal.operation;
-import com.mongodb.client.cursor.TimeoutMode;
import com.mongodb.internal.async.AsyncAggregateResponseBatchCursor;
import com.mongodb.internal.async.SingleResultCallback;
import com.mongodb.internal.connection.OperationContext;
@@ -28,25 +27,21 @@
public class AsyncCommandBatchCursor implements AsyncAggregateResponseBatchCursor {
- private final TimeoutMode timeoutMode;
private OperationContext operationContext;
private AsyncCursor wrapped;
AsyncCommandBatchCursor(
- final TimeoutMode timeoutMode,
final long maxTimeMs,
final OperationContext operationContext,
final AsyncCursor wrapped) {
this.operationContext = operationContext.withOverride(timeoutContext ->
timeoutContext.withMaxTimeOverride(maxTimeMs));
- this.timeoutMode = timeoutMode;
this.wrapped = wrapped;
}
@Override
public void next(final SingleResultCallback> callback) {
- resetTimeout();
wrapped.next(operationContext, callback);
}
@@ -96,12 +91,6 @@ public int getMaxWireVersion() {
return wrapped.getMaxWireVersion();
}
- private void resetTimeout() {
- if (timeoutMode == TimeoutMode.ITERATION) {
- operationContext = operationContext.withNewlyStartedTimeout();
- }
- }
-
AsyncCursor getWrapped() {
return wrapped;
}
diff --git a/driver-core/src/main/com/mongodb/internal/operation/AsyncCommandCursor.java b/driver-core/src/main/com/mongodb/internal/operation/AsyncCommandCursor.java
index 6a4ef41a43e..74320b5be85 100644
--- a/driver-core/src/main/com/mongodb/internal/operation/AsyncCommandCursor.java
+++ b/driver-core/src/main/com/mongodb/internal/operation/AsyncCommandCursor.java
@@ -20,7 +20,6 @@
import com.mongodb.MongoCommandException;
import com.mongodb.MongoException;
import com.mongodb.MongoNamespace;
-import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoSocketException;
import com.mongodb.ReadPreference;
import com.mongodb.ServerAddress;
@@ -323,9 +322,7 @@ void executeWithConnection(final OperationContext operationContext, final As
}
private void handleException(final AsyncConnection connection, final Throwable exception) {
- if (exception instanceof MongoOperationTimeoutException && exception.getCause() instanceof MongoSocketException) {
- onCorruptedConnection(connection, (MongoSocketException) exception.getCause());
- } else if (exception instanceof MongoSocketException) {
+ if (exception instanceof MongoSocketException) {
onCorruptedConnection(connection, (MongoSocketException) exception);
}
}
diff --git a/driver-core/src/main/com/mongodb/internal/operation/AsyncOperationHelper.java b/driver-core/src/main/com/mongodb/internal/operation/AsyncOperationHelper.java
index bbce5a1010a..59b2ff5eb38 100644
--- a/driver-core/src/main/com/mongodb/internal/operation/AsyncOperationHelper.java
+++ b/driver-core/src/main/com/mongodb/internal/operation/AsyncOperationHelper.java
@@ -20,10 +20,8 @@
import com.mongodb.MongoException;
import com.mongodb.ReadPreference;
import com.mongodb.assertions.Assertions;
-import com.mongodb.client.cursor.TimeoutMode;
import com.mongodb.connection.ConnectionDescription;
import com.mongodb.connection.ServerDescription;
-import com.mongodb.internal.TimeoutContext;
import com.mongodb.internal.async.AsyncBatchCursor;
import com.mongodb.internal.async.MutableValue;
import com.mongodb.internal.async.SingleResultCallback;
@@ -92,13 +90,12 @@ static void withAsyncReadConnectionSource(final AsyncReadBinding binding, final
}
static void withAsyncConnection(final AsyncWriteBinding binding,
- final OperationContext originalOperationContext,
+ final OperationContext operationContext,
final AsyncCallableWithConnection callable) {
- OperationContext serverSelectionOperationContext = originalOperationContext.withOverride(TimeoutContext::withComputedServerSelectionTimeout);
binding.getWriteConnectionSource(
- serverSelectionOperationContext,
+ operationContext,
errorHandlingCallback(
- new AsyncCallableWithConnectionCallback(callable, serverSelectionOperationContext, originalOperationContext),
+ new AsyncCallableWithConnectionCallback(callable, operationContext, operationContext),
OperationHelper.LOGGER));
}
@@ -113,18 +110,16 @@ static void withAsyncSourceAndConnection(
final AsyncCallbackTriFunction asyncFunction) {
SingleResultCallback errorHandlingCallback = errorHandlingCallback(callback, OperationHelper.LOGGER);
- OperationContext serverSelectionOperationContext =
- operationContext.withOverride(TimeoutContext::withComputedServerSelectionTimeout);
withAsyncSuppliedResource(
sourceAsyncFunction,
wrapConnectionSourceException,
- serverSelectionOperationContext,
+ operationContext,
errorHandlingCallback,
(source, sourceReleasingCallback) ->
withAsyncSuppliedResource(
source::getConnection,
wrapConnectionSourceException,
- serverSelectionOperationContext.withMinRoundTripTime(source.getServerDescription()),
+ operationContext.withMinRoundTripTime(source.getServerDescription()),
sourceReleasingCallback,
(connection, connectionAndSourceReleasingCallback) ->
asyncFunction.apply(
@@ -367,12 +362,12 @@ static AsyncCallbackSupplier decorateWithRetriesAsync(
};
}
- static CommandWriteTransformerAsync writeConcernErrorTransformerAsync(final TimeoutContext timeoutContext) {
+ static CommandWriteTransformerAsync writeConcernErrorTransformerAsync() {
return (result, connection) -> {
assertNotNull(result);
throwOnWriteConcernError(result, connection.getDescription().getServerAddress(),
- connection.getDescription().getMaxWireVersion(),
- timeoutContext);
+ connection.getDescription().getMaxWireVersion()
+ );
return null;
};
}
@@ -382,8 +377,7 @@ static CommandReadTransformerAsync> asyncS
new AsyncSingleBatchCursor<>(BsonDocumentWrapperHelper.toList(result, fieldName), 0);
}
- static AsyncBatchCursor cursorDocumentToAsyncBatchCursor(final TimeoutMode timeoutMode,
- final BsonDocument cursorDocument,
+ static AsyncBatchCursor cursorDocumentToAsyncBatchCursor(final BsonDocument cursorDocument,
final int batchSize,
final Decoder decoder,
@Nullable final BsonValue comment,
@@ -392,7 +386,7 @@ static AsyncBatchCursor cursorDocumentToAsyncBatchCursor(final TimeoutMod
final OperationContext operationContext,
final boolean retryReads,
@Nullable final Integer maxAdaptiveRetriesSetting) {
- return new AsyncCommandBatchCursor<>(timeoutMode, 0, operationContext, new AsyncCommandCursor<>(
+ return new AsyncCommandBatchCursor<>(0, operationContext, new AsyncCommandCursor<>(
cursorDocument, batchSize, decoder, comment, source, connection, retryReads, maxAdaptiveRetriesSetting
));
}
diff --git a/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamBatchCursor.java b/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamBatchCursor.java
index 21e90a989f8..42fe288f706 100644
--- a/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamBatchCursor.java
+++ b/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamBatchCursor.java
@@ -18,7 +18,6 @@
import com.mongodb.MongoChangeStreamException;
import com.mongodb.MongoException;
-import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.ReadPreference;
import com.mongodb.ServerAddress;
import com.mongodb.ServerCursor;
@@ -53,11 +52,6 @@
*
* If an error occurring during any of these method calls is not resumable, it is immediately propagated to the caller, and the {@link ChangeStreamBatchCursor}
* is closed and invalidated on the server. Server errors that occur during this invalidation process are not propagated to the caller.
- *
- * A {@link MongoOperationTimeoutException} does not invalidate the {@link ChangeStreamBatchCursor}, but is immediately propagated to the caller.
- * Subsequent method call will attempt to resume operation by establishing a new change stream on the server, without doing {@code getMore}
- * request first.
- *
*/
final class ChangeStreamBatchCursor implements AggregateResponseBatchCursor {
private ReadBinding binding;
@@ -71,13 +65,6 @@ final class ChangeStreamBatchCursor implements AggregateResponseBatchCursor changeStreamOperation,
final Cursor wrapped,
final ReadBinding binding,
@@ -93,7 +80,6 @@ final class ChangeStreamBatchCursor implements AggregateResponseBatchCursor getWrapped() {
@@ -224,17 +210,15 @@ R resumeableOperation(final BiFunction, OperationCon
OperationContext operationContextWithNewlyStartedTimeout = initialOperationContext.withNewlyStartedTimeout();
try {
R result = execute(function, operationContextWithNewlyStartedTimeout);
- lastOperationTimedOut = false;
return result;
} catch (Throwable exception) {
- lastOperationTimedOut = isTimeoutException(exception);
throw exception;
}
}
private R execute(final BiFunction, OperationContext, R> function,
final OperationContext operationContext) {
- boolean shouldBeResumed = hasPreviousNextTimedOut();
+ boolean shouldBeResumed = false;
while (true) {
if (shouldBeResumed) {
resumeChangeStream(operationContext);
@@ -266,14 +250,6 @@ private void resumeChangeStream(final OperationContext operationContext) {
binding.release(); // release the new change stream batch cursor's reference to the binding
}
- private boolean hasPreviousNextTimedOut() {
- return lastOperationTimedOut && !closed.get();
- }
-
- private static boolean isTimeoutException(final Throwable exception) {
- return exception instanceof MongoOperationTimeoutException;
- }
-
/**
* Does not retain wrapped {link @ReadBinding} as it serves as a wrapper only.
*/
diff --git a/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamBatchCursorHelper.java b/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamBatchCursorHelper.java
index 1bed2ed2b0f..922161cf9ee 100644
--- a/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamBatchCursorHelper.java
+++ b/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamBatchCursorHelper.java
@@ -22,7 +22,6 @@
import com.mongodb.MongoException;
import com.mongodb.MongoInterruptedException;
import com.mongodb.MongoNotPrimaryException;
-import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoSocketException;
import com.mongodb.internal.VisibleForTesting;
@@ -40,8 +39,7 @@ final class ChangeStreamBatchCursorHelper {
static final String RESUMABLE_CHANGE_STREAM_ERROR_LABEL = "ResumableChangeStreamError";
static boolean isResumableError(final Throwable t, final int maxWireVersion) {
- if (!(t instanceof MongoException) || (t instanceof MongoChangeStreamException) || (t instanceof MongoInterruptedException)
- || (t instanceof MongoOperationTimeoutException)) {
+ if (!(t instanceof MongoException) || (t instanceof MongoChangeStreamException) || (t instanceof MongoInterruptedException)) {
return false;
} else if (t instanceof MongoNotPrimaryException || t instanceof MongoCursorNotFoundException
|| t instanceof MongoSocketException | t instanceof MongoClientException) {
diff --git a/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamOperation.java b/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamOperation.java
index c94dccebf50..dee38851cae 100644
--- a/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamOperation.java
+++ b/driver-core/src/main/com/mongodb/internal/operation/ChangeStreamOperation.java
@@ -16,12 +16,10 @@
package com.mongodb.internal.operation;
-import com.mongodb.CursorType;
import com.mongodb.MongoNamespace;
import com.mongodb.client.model.Collation;
import com.mongodb.client.model.changestream.FullDocument;
import com.mongodb.client.model.changestream.FullDocumentBeforeChange;
-import com.mongodb.internal.TimeoutContext;
import com.mongodb.internal.VisibleForTesting;
import com.mongodb.internal.async.AsyncBatchCursor;
import com.mongodb.internal.async.SingleResultCallback;
@@ -46,7 +44,6 @@
import static com.mongodb.assertions.Assertions.assertNotNull;
import static com.mongodb.assertions.Assertions.notNull;
-import static com.mongodb.client.cursor.TimeoutMode.CURSOR_LIFETIME;
/**
* An operation that executes an {@code $changeStream} aggregation.
@@ -77,7 +74,7 @@ public ChangeStreamOperation(final MongoNamespace namespace, final FullDocument
final ChangeStreamLevel changeStreamLevel,
@Nullable final Integer maxAdaptiveRetriesSetting) {
this.wrapped = new AggregateOperationImpl<>(namespace, pipeline, RAW_BSON_DOCUMENT_CODEC, getAggregateTarget(),
- getPipelineCreator(), maxAdaptiveRetriesSetting).cursorType(CursorType.TailableAwait);
+ getPipelineCreator(), maxAdaptiveRetriesSetting);
this.fullDocument = notNull("fullDocument", fullDocument);
this.fullDocumentBeforeChange = notNull("fullDocumentBeforeChange", fullDocumentBeforeChange);
this.decoder = notNull("decoder", decoder);
@@ -173,28 +170,6 @@ public ChangeStreamOperation showExpandedEvents(final boolean showExpandedEve
return this;
}
- /**
- * Gets an aggregate operation with consideration for timeout settings.
- *
- * Change streams act similarly to tailable awaitData cursors, with identical timeoutMS option behavior.
- * Key distinctions include:
- * - The timeoutMS option must be applied at the start of the aggregate operation for change streams.
- * - Change streams support resumption on next() calls. The driver handles automatic resumption for transient errors.
- *