Skip to content

Commit 2b00a83

Browse files
authored
Do various small timeout-related improvements (#1908)
1 parent 9ae84c9 commit 2b00a83

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

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/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/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)