Skip to content

Commit e168f53

Browse files
committed
Merge branch 'main' into JAVA-6122
# Conflicts: # driver-core/src/main/com/mongodb/MongoClientSettings.java # driver-kotlin-sync/src/main/kotlin/com/mongodb/kotlin/client/MongoCluster.kt # driver-kotlin-sync/src/main/kotlin/com/mongodb/kotlin/client/MongoCollection.kt # driver-kotlin-sync/src/main/kotlin/com/mongodb/kotlin/client/MongoDatabase.kt # driver-sync/src/main/com/mongodb/client/MongoCluster.java # driver-sync/src/main/com/mongodb/client/MongoCollection.java # driver-sync/src/main/com/mongodb/client/MongoDatabase.java
2 parents 4cadad6 + f5e7383 commit e168f53

File tree

44 files changed

+306
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+306
-424
lines changed

.evergreen/.evg.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,23 +2507,14 @@ buildvariants:
25072507
tasks:
25082508
- name: ".ocsp"
25092509

2510-
- matrix_name: "scala-tests-2"
2510+
- matrix_name: "scala-tests"
25112511
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: [ "jdk8", "jdk17", "jdk21" ], version: [ "7.0" ], topology: "replicaset",
2512-
scala: ["2.11", "2.12", "2.13"] , os: "ubuntu" }
2512+
scala: "*" , os: "ubuntu" }
25132513
display_name: "${scala} ${jdk} ${version} ${topology} ${os}"
25142514
tags: [ "test-scala-variant" ]
25152515
tasks:
25162516
- name: "scala-test-task"
25172517

2518-
- matrix_name: "scala-tests-3"
2519-
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: [ "jdk17", "jdk21" ], version: [ "8.0" ], topology: "replicaset",
2520-
scala: "3", os: "ubuntu" }
2521-
display_name: "${scala} ${jdk} ${version} ${topology} ${os}"
2522-
tags: [ "test-scala-variant" ]
2523-
tasks:
2524-
- name: "scala-test-task"
2525-
2526-
25272518
- matrix_name: "kotlin-tests"
25282519
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: [ "jdk8", "jdk17", "jdk21" ], version: [ "7.0" ], topology: "replicaset", os: "ubuntu" }
25292520
display_name: "Kotlin: ${jdk} ${version} ${topology} ${os}"

driver-core/src/main/com/mongodb/ClientEncryptionSettings.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,15 @@ public Builder keyExpiration(@Nullable final Long keyExpiration, final TimeUnit
172172
* <li>{@code > 0} The time limit to use for the full execution of an operation.</li>
173173
* </ul>
174174
*
175-
* <p><strong>Note:</strong> The timeout set through this method overrides the timeout defined in the key vault client settings
176-
* specified in {@link #keyVaultMongoClientSettings(MongoClientSettings)}.
177-
* Essentially, for operations that require accessing the key vault, the remaining timeout from the initial operation
178-
* determines the duration allowed for key vault access.</p>
175+
* <p>Note:
176+
* <ul>
177+
* <li>The timeout set through this method overrides the timeout defined in the key vault client settings
178+
* specified in {@link #keyVaultMongoClientSettings(MongoClientSettings)}.
179+
* Essentially, for operations that require accessing the key vault, the remaining timeout from the initial operation
180+
* determines the duration allowed for key vault access.</li>
181+
* <li>When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
182+
* operation might not be timed out when expected. This limitation does not apply to the reactive streams API.</li>
183+
* </ul>
179184
*
180185
* @param timeout the timeout
181186
* @param timeUnit the time unit
@@ -368,6 +373,16 @@ public Long getKeyExpiration(final TimeUnit timeUnit) {
368373
* <li>{@code > 0} The time limit to use for the full execution of an operation.</li>
369374
* </ul>
370375
*
376+
* <p>Note:
377+
* <ul>
378+
* <li>The timeout set through this method overrides the timeout defined in the key vault client settings
379+
* specified in {@link Builder#keyVaultMongoClientSettings(MongoClientSettings)}.
380+
* Essentially, for operations that require accessing the key vault, the remaining timeout from the initial operation
381+
* determines the duration allowed for key vault access.</li>
382+
* <li>When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
383+
* operation might not be timed out when expected. This limitation does not apply to the reactive streams API.</li>
384+
* </ul>
385+
*
371386
* @param timeUnit the time unit
372387
* @return the timeout in the given time unit
373388
* @since 5.2

driver-core/src/main/com/mongodb/ClientSessionOptions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public TransactionOptions getDefaultTransactionOptions() {
9292
* <li>{@code withTransaction}</li>
9393
* <li>{@code close}</li>
9494
* </ul>
95+
*
96+
* <p>Note: When using synchronous API, this timeout does not limit socket writes, therefore
97+
* there is a possibility that the operation might not be timed out when expected. This limitation does not
98+
* apply to the reactive streams API.
99+
*
95100
* @param timeUnit the time unit
96101
* @return the default timeout
97102
* @since 5.2
@@ -220,6 +225,11 @@ public Builder defaultTransactionOptions(final TransactionOptions defaultTransac
220225
* <li>{@code withTransaction}</li>
221226
* <li>{@code close}</li>
222227
* </ul>
228+
*
229+
* <p>Note: When using synchronous API, this timeout does not limit socket writes, therefore
230+
* there is a possibility that the operation might not be timed out when expected. This limitation does not
231+
* apply to the reactive streams API.
232+
*
223233
* @param defaultTimeout the timeout
224234
* @param timeUnit the time unit
225235
* @return this

driver-core/src/main/com/mongodb/ErrorCategory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public enum ErrorCategory {
4040
/**
4141
* An execution timeout error
4242
*
43+
* @see MongoExecutionTimeoutException
4344
* @mongodb.driver.manual reference/operator/meta/maxTimeMS/ maxTimeMS
4445
*/
4546
EXECUTION_TIMEOUT;

driver-core/src/main/com/mongodb/MongoClientSettings.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@ public Builder inetAddressResolver(@Nullable final InetAddressResolver inetAddre
738738
* <p>If {@linkplain #retryWrites(boolean) write} or {@linkplain #retryReads(boolean) read} retries are enabled,
739739
* the driver may retry multiple times until the timeout expires.
740740
*
741+
* <p>Note: When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
742+
* operation might not be timed out when expected. This limitation does not apply to the reactive streams API.
743+
*
741744
* @param timeout the timeout
742745
* @param timeUnit the time unit
743746
* @return this
@@ -974,6 +977,9 @@ public ServerApi getServerApi() {
974977
* <p>If {@linkplain #getRetryWrites() write} or {@linkplain #getRetryReads() read} retries are enabled,
975978
* the driver may retry multiple times until the timeout expires. Otherwise, at most one retry attempt is made.
976979
*
980+
* <p>Note: When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
981+
* operation might not be timed out when expected. This limitation does not apply to the reactive streams API.
982+
*
977983
* @param timeUnit the time unit
978984
* @return the timeout in the given time unit
979985
* @since 5.2

driver-core/src/main/com/mongodb/MongoExecutionTimeoutException.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,18 @@
1616

1717
package com.mongodb;
1818

19-
import com.mongodb.annotations.Alpha;
20-
import com.mongodb.annotations.Reason;
2119
import org.bson.BsonDocument;
2220

2321
/**
24-
* Exception indicating that the execution of the current operation timed out as a result of the maximum operation time being exceeded.
22+
* Exception indicating that the execution of the current command timed out by the server
23+
* as a result of the {@linkplain ErrorCategory#EXECUTION_TIMEOUT maximum operation time being exceeded}.
2524
*
25+
* @see MongoTimeoutException
2626
* @since 2.12
2727
*/
2828
public class MongoExecutionTimeoutException extends MongoException {
2929
private static final long serialVersionUID = 5955669123800274594L;
3030

31-
/**
32-
* Construct a new instance.
33-
*
34-
* @param message the error message
35-
* @since 5.2
36-
*/
37-
@Alpha(Reason.CLIENT)
38-
public MongoExecutionTimeoutException(final String message) {
39-
super(message);
40-
41-
}
42-
4331
/**
4432
* Construct a new instance.
4533
*

driver-core/src/main/com/mongodb/MongoOperationTimeoutException.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
* Exception thrown to indicate that a MongoDB operation has exceeded the specified timeout for
2626
* the full execution of operation.
2727
*
28-
* <p>The {@code MongoOperationTimeoutException} might provide information about the underlying
28+
* <p>The {@link MongoOperationTimeoutException} might provide information about the underlying
2929
* cause of the timeout, if available. For example, if retries are attempted due to transient failures,
3030
* and a timeout occurs in any of the attempts, the exception from one of the retries may be appended
31-
* as the cause to this {@code MongoOperationTimeoutException}.
31+
* as the cause to this {@link MongoOperationTimeoutException}.
3232
*
33-
* <p>The key difference between {@code MongoOperationTimeoutException} and {@code MongoExecutionTimeoutException}
34-
* lies in the nature of these exceptions. {@code MongoExecutionTimeoutException} indicates a server-side timeout
35-
* capped by a user-specified number. These server errors are transformed into the new {@code MongoOperationTimeoutException}.
36-
* On the other hand, {@code MongoOperationExecutionException} denotes a timeout during the execution of the entire operation.
33+
* <p>The key difference between {@link MongoOperationTimeoutException} and {@link MongoExecutionTimeoutException}
34+
* lies in the nature of these exceptions. {@link MongoExecutionTimeoutException} indicates a server-side timeout
35+
* capped by a user-specified number. These server errors are transformed into the new {@link MongoOperationTimeoutException}.
36+
* On the other hand, {@link MongoOperationTimeoutException} denotes a timeout during the execution of the entire operation.
3737
*
3838
* @see MongoClientSettings.Builder#timeout(long, TimeUnit)
3939
* @see MongoClientSettings#getTimeout(TimeUnit)

driver-core/src/main/com/mongodb/MongoTimeoutException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import com.mongodb.lang.Nullable;
2222

2323
/**
24-
* An exception indicating that the driver has timed out waiting for either a server or a connection to become available.
24+
* An exception indicating that the driver has timed out doing something.
25+
*
26+
* @see MongoExecutionTimeoutException
2527
*/
2628
public class MongoTimeoutException extends MongoClientException {
2729

driver-core/src/main/com/mongodb/TransactionOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public Long getMaxCommitTime(final TimeUnit timeUnit) {
109109
* <li>{@code > 0} The time limit to use for the full execution of an operation.</li>
110110
* </ul>
111111
*
112+
* <p>Note: When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
113+
* operation might not be timed out when expected. This limitation does not apply to the reactive streams API.
114+
*
112115
* @param timeUnit the time unit
113116
* @return the timeout in the given time unit
114117
* @since 5.2
@@ -292,6 +295,9 @@ public Builder maxCommitTime(@Nullable final Long maxCommitTime, final TimeUnit
292295
* <li>{@code > 0} The time limit to use for the full execution of an operation.</li>
293296
* </ul>
294297
*
298+
* <p>Note: When using synchronous API, this timeout does not limit socket writes, therefore there is a possibility that the
299+
* operation might not be timed out when expected. This limitation does not apply to the reactive streams API.
300+
*
295301
* @param timeout the timeout
296302
* @param timeUnit the time unit
297303
* @return this

driver-core/src/main/com/mongodb/internal/TimeoutContext.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import static com.mongodb.assertions.Assertions.assertNotNull;
3030
import static com.mongodb.assertions.Assertions.assertNull;
31+
import static com.mongodb.assertions.Assertions.assertTrue;
3132
import static com.mongodb.assertions.Assertions.isTrue;
3233
import static com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE;
3334
import static com.mongodb.internal.time.Timeout.ZeroSemantics.ZERO_DURATION_MEANS_INFINITE;
@@ -41,6 +42,9 @@
4142
public class TimeoutContext {
4243
private static final int NO_ROUND_TRIP_TIME_MS = 0;
4344
private final TimeoutSettings timeoutSettings;
45+
/**
46+
* Is {@code null} iff {@link #timeoutSettings}{@code .}{@link TimeoutSettings#getTimeoutMS() getTimeoutMS()} is {@code null}.
47+
*/
4448
@Nullable
4549
private final Timeout timeout;
4650
@Nullable
@@ -139,6 +143,7 @@ private TimeoutContext(final boolean isMaintenanceContext,
139143
final TimeoutSettings timeoutSettings,
140144
@Nullable final MaxTimeSupplier maxTimeSupplier,
141145
@Nullable final Timeout timeout) {
146+
assertTrue((timeoutSettings.getTimeoutMS() == null) == (timeout == null));
142147
this.isMaintenanceContext = isMaintenanceContext;
143148
this.timeoutSettings = timeoutSettings;
144149
this.minRoundTripTimeMS = minRoundTripTimeMS;
@@ -149,7 +154,8 @@ private TimeoutContext(final boolean isMaintenanceContext,
149154
/**
150155
* Allows for the differentiation between users explicitly setting a global operation timeout via {@code timeoutMS}.
151156
*
152-
* @return true if a timeout has been set.
157+
* @return true iff {@link #getTimeoutSettings()}{@code .}{@link TimeoutSettings#getTimeoutMS() getTimeoutMS()} is not {@code null}.
158+
* @see #getTimeout()
153159
*/
154160
public boolean hasTimeoutMS() {
155161
return timeoutSettings.getTimeoutMS() != null;
@@ -170,7 +176,6 @@ public Timeout timeoutIncludingRoundTrip() {
170176

171177
/**
172178
* Returns the remaining {@code timeoutMS} if set or the {@code alternativeTimeoutMS}.
173-
*
174179
* zero means infinite timeout.
175180
*
176181
* @param alternativeTimeoutMS the alternative timeout.
@@ -191,6 +196,10 @@ public TimeoutSettings getTimeoutSettings() {
191196
return timeoutSettings;
192197
}
193198

199+
/**
200+
* @return {@code null} iff {@link #hasTimeoutMS()} is {@code false}.
201+
* @see #hasTimeoutMS()
202+
*/
194203
@Nullable
195204
public Timeout getTimeout() {
196205
return timeout;

0 commit comments

Comments
 (0)