Skip to content

Commit 1a3e3a8

Browse files
authored
Deprecate options: maxTimeMS, maxCommitTimeMS for CRUD methods. (#1277)
JAVA-5264
1 parent 8d2b5c8 commit 1a3e3a8

File tree

59 files changed

+418
-47
lines changed

Some content is hidden

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

59 files changed

+418
-47
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,20 @@ public Builder readPreference(@Nullable final ReadPreference readPreference) {
219219
* @return this
220220
* @mongodb.server.release 4.2
221221
* @since 3.11
222+
*
223+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
224+
*
225+
* <ul>
226+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
227+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
228+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
229+
* <li>{@code ClientSession}</li>
230+
* </ul>
231+
*
232+
* When executing a commit transaction operation, any explicitly set timeout at these levels takes precedence, rendering this
233+
* commit time irrelevant. If no timeout is specified at these levels, the maximum execution time will be used.
222234
*/
235+
@Deprecated
223236
public Builder maxCommitTime(@Nullable final Long maxCommitTime, final TimeUnit timeUnit) {
224237
if (maxCommitTime == null) {
225238
this.maxCommitTimeMS = null;

driver-core/src/main/com/mongodb/client/model/CountOptions.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,20 @@ public CountOptions skip(final int skip) {
133133
*
134134
* @param timeUnit the time unit to return the result in
135135
* @return the maximum execution time in the given time unit
136+
*
137+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
138+
*
139+
* <ul>
140+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
141+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
142+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
143+
* <li>{@code ClientSession}</li>
144+
* </ul>
145+
*
146+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
147+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
136148
*/
149+
@Deprecated
137150
public long getMaxTime(final TimeUnit timeUnit) {
138151
notNull("timeUnit", timeUnit);
139152
return timeUnit.convert(maxTimeMS, TimeUnit.MILLISECONDS);
@@ -145,7 +158,20 @@ public long getMaxTime(final TimeUnit timeUnit) {
145158
* @param maxTime the max time
146159
* @param timeUnit the time unit, which may not be null
147160
* @return this
161+
*
162+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
163+
*
164+
* <ul>
165+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
166+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
167+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
168+
* <li>{@code ClientSession}</li>
169+
* </ul>
170+
*
171+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
172+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
148173
*/
174+
@Deprecated
149175
public CountOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
150176
notNull("timeUnit", timeUnit);
151177
this.maxTimeMS = TimeUnit.MILLISECONDS.convert(maxTime, timeUnit);

driver-core/src/main/com/mongodb/client/model/EstimatedDocumentCountOptions.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,20 @@ public class EstimatedDocumentCountOptions {
3939
*
4040
* @param timeUnit the time unit to return the result in
4141
* @return the maximum execution time in the given time unit
42+
*
43+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
44+
*
45+
* <ul>
46+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
47+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
48+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
49+
* <li>{@code ClientSession}</li>
50+
* </ul>
51+
*
52+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
53+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
4254
*/
55+
@Deprecated
4356
public long getMaxTime(final TimeUnit timeUnit) {
4457
notNull("timeUnit", timeUnit);
4558
return timeUnit.convert(maxTimeMS, TimeUnit.MILLISECONDS);
@@ -51,7 +64,20 @@ public long getMaxTime(final TimeUnit timeUnit) {
5164
* @param maxTime the max time
5265
* @param timeUnit the time unit, which may not be null
5366
* @return this
67+
*
68+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
69+
*
70+
* <ul>
71+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
72+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
73+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
74+
* <li>{@code ClientSession}</li>
75+
* </ul>
76+
*
77+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
78+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
5479
*/
80+
@Deprecated
5581
public EstimatedDocumentCountOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
5682
notNull("timeUnit", timeUnit);
5783
this.maxTimeMS = TimeUnit.MILLISECONDS.convert(maxTime, timeUnit);

driver-core/src/main/com/mongodb/client/model/FindOneAndDeleteOptions.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,20 @@ public FindOneAndDeleteOptions sort(@Nullable final Bson sort) {
9696
* @param maxTime the max time
9797
* @param timeUnit the time unit, which may not be null
9898
* @return this
99+
*
100+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
101+
*
102+
* <ul>
103+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
104+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
105+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
106+
* <li>{@code ClientSession}</li>
107+
* </ul>
108+
*
109+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
110+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
99111
*/
112+
@Deprecated
100113
public FindOneAndDeleteOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
101114
notNull("timeUnit", timeUnit);
102115
this.maxTimeMS = MILLISECONDS.convert(maxTime, timeUnit);
@@ -108,7 +121,20 @@ public FindOneAndDeleteOptions maxTime(final long maxTime, final TimeUnit timeUn
108121
*
109122
* @param timeUnit the time unit for the result
110123
* @return the max time
124+
*
125+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
126+
*
127+
* <ul>
128+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
129+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
130+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
131+
* <li>{@code ClientSession}</li>
132+
* </ul>
133+
*
134+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
135+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
111136
*/
137+
@Deprecated
112138
public long getMaxTime(final TimeUnit timeUnit) {
113139
return timeUnit.convert(maxTimeMS, MILLISECONDS);
114140
}

driver-core/src/main/com/mongodb/client/model/FindOneAndReplaceOptions.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,20 @@ public FindOneAndReplaceOptions returnDocument(final ReturnDocument returnDocume
139139
* @param maxTime the max time
140140
* @param timeUnit the time unit, which may not be null
141141
* @return this
142+
*
143+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
144+
*
145+
* <ul>
146+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
147+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
148+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
149+
* <li>{@code ClientSession}</li>
150+
* </ul>
151+
*
152+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
153+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
142154
*/
155+
@Deprecated
143156
public FindOneAndReplaceOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
144157
notNull("timeUnit", timeUnit);
145158
this.maxTimeMS = MILLISECONDS.convert(maxTime, timeUnit);
@@ -151,7 +164,20 @@ public FindOneAndReplaceOptions maxTime(final long maxTime, final TimeUnit timeU
151164
*
152165
* @param timeUnit the time unit for the result
153166
* @return the max time
167+
*
168+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
169+
*
170+
* <ul>
171+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
172+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
173+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
174+
* <li>{@code ClientSession}</li>
175+
* </ul>
176+
*
177+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
178+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
154179
*/
180+
@Deprecated
155181
public long getMaxTime(final TimeUnit timeUnit) {
156182
return timeUnit.convert(maxTimeMS, MILLISECONDS);
157183
}

driver-core/src/main/com/mongodb/client/model/FindOneAndUpdateOptions.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,20 @@ public FindOneAndUpdateOptions returnDocument(final ReturnDocument returnDocumen
142142
* @param maxTime the max time
143143
* @param timeUnit the time unit, which may not be null
144144
* @return this
145+
*
146+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
147+
*
148+
* <ul>
149+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
150+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
151+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
152+
* <li>{@code ClientSession}</li>
153+
* </ul>
154+
*
155+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
156+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
145157
*/
158+
@Deprecated
146159
public FindOneAndUpdateOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
147160
notNull("timeUnit", timeUnit);
148161
this.maxTimeMS = MILLISECONDS.convert(maxTime, timeUnit);
@@ -154,7 +167,20 @@ public FindOneAndUpdateOptions maxTime(final long maxTime, final TimeUnit timeUn
154167
*
155168
* @param timeUnit the time unit for the result
156169
* @return the max time
170+
*
171+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
172+
*
173+
* <ul>
174+
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
175+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
176+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
177+
* <li>{@code ClientSession}</li>
178+
* </ul>
179+
*
180+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
181+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
157182
*/
183+
@Deprecated
158184
public long getMaxTime(final TimeUnit timeUnit) {
159185
return timeUnit.convert(maxTimeMS, MILLISECONDS);
160186
}

driver-core/src/main/com/mongodb/internal/client/model/FindOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ public FindOptions skip(final int skip) {
149149
* @param timeUnit the time unit to return the result in
150150
* @return the maximum execution time in the given time unit
151151
* @mongodb.driver.manual reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
152+
* @deprecated This option is deprecated in favor of global operation timeout.
152153
*/
154+
@Deprecated
153155
public long getMaxTime(final TimeUnit timeUnit) {
154156
notNull("timeUnit", timeUnit);
155157
return timeUnit.convert(maxTimeMS, TimeUnit.MILLISECONDS);
@@ -162,7 +164,9 @@ public long getMaxTime(final TimeUnit timeUnit) {
162164
* @param timeUnit the time unit, which may not be null
163165
* @return this
164166
* @mongodb.driver.manual reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
167+
* @deprecated This option is deprecated in favor of global operation timeout.
165168
*/
169+
@Deprecated
166170
public FindOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
167171
notNull("timeUnit", timeUnit);
168172
isTrueArgument("maxTime > = 0", maxTime >= 0);

driver-core/src/main/com/mongodb/internal/operation/Operations.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public TimeoutSettings getTimeoutSettings() {
153153
}
154154

155155
CountDocumentsOperation countDocuments(final Bson filter, final CountOptions options) {
156+
@SuppressWarnings("deprecation")
156157
CountDocumentsOperation operation = new CountDocumentsOperation(
157158
timeoutSettings.withMaxTimeMS(options.getMaxTime(MILLISECONDS)), assertNotNull(namespace))
158159
.retryReads(retryReads)
@@ -169,6 +170,7 @@ CountDocumentsOperation countDocuments(final Bson filter, final CountOptions opt
169170
return operation;
170171
}
171172

173+
@SuppressWarnings("deprecation")
172174
EstimatedDocumentCountOperation estimatedDocumentCount(final EstimatedDocumentCountOptions options) {
173175
return new EstimatedDocumentCountOperation(timeoutSettings.withMaxTimeMS(options.getMaxTime(MILLISECONDS)),
174176
assertNotNull(namespace))
@@ -193,6 +195,7 @@ <TResult> FindOperation<TResult> find(final MongoNamespace findNamespace, @Nulla
193195

194196
private <TResult> FindOperation<TResult> createFindOperation(final MongoNamespace findNamespace, @Nullable final Bson filter,
195197
final Class<TResult> resultClass, final FindOptions options) {
198+
@SuppressWarnings("deprecation")
196199
FindOperation<TResult> operation = new FindOperation<>(
197200
timeoutSettings.withMaxTimeAndMaxAwaitTimeMS(options.getMaxTime(MILLISECONDS), options.getMaxAwaitTime(MILLISECONDS)),
198201
findNamespace, codecRegistry.get(resultClass))
@@ -297,6 +300,7 @@ <TResult> MapReduceWithInlineResultsOperation<TResult> mapReduce(final String ma
297300
@Nullable final String finalizeFunction, final Class<TResult> resultClass, final Bson filter, final int limit,
298301
final long maxTimeMS, final boolean jsMode, final Bson scope, final Bson sort, final boolean verbose,
299302
final Collation collation) {
303+
@SuppressWarnings("deprecation")
300304
MapReduceWithInlineResultsOperation<TResult> operation =
301305
new MapReduceWithInlineResultsOperation<>(timeoutSettings.withMaxTimeMS(maxTimeMS),
302306
assertNotNull(namespace), new BsonJavaScript(mapFunction), new BsonJavaScript(reduceFunction),
@@ -314,6 +318,7 @@ <TResult> MapReduceWithInlineResultsOperation<TResult> mapReduce(final String ma
314318
return operation;
315319
}
316320

321+
@SuppressWarnings("deprecation")
317322
FindAndDeleteOperation<TDocument> findOneAndDelete(final Bson filter, final FindOneAndDeleteOptions options) {
318323
return new FindAndDeleteOperation<>(timeoutSettings.withMaxTimeMS(options.getMaxTime(MILLISECONDS)),
319324
assertNotNull(namespace), writeConcern, retryWrites, getCodec())
@@ -327,6 +332,7 @@ FindAndDeleteOperation<TDocument> findOneAndDelete(final Bson filter, final Find
327332
.let(toBsonDocument(options.getLet()));
328333
}
329334

335+
@SuppressWarnings("deprecation")
330336
FindAndReplaceOperation<TDocument> findOneAndReplace(final Bson filter, final TDocument replacement,
331337
final FindOneAndReplaceOptions options) {
332338
return new FindAndReplaceOperation<>(timeoutSettings.withMaxTimeMS(options.getMaxTime(MILLISECONDS)),
@@ -344,6 +350,7 @@ FindAndReplaceOperation<TDocument> findOneAndReplace(final Bson filter, final TD
344350
.let(toBsonDocument(options.getLet()));
345351
}
346352

353+
@SuppressWarnings("deprecation")
347354
FindAndUpdateOperation<TDocument> findOneAndUpdate(final Bson filter, final Bson update, final FindOneAndUpdateOptions options) {
348355
return new FindAndUpdateOperation<>(timeoutSettings.withMaxTimeMS(options.getMaxTime(MILLISECONDS)),
349356
assertNotNull(namespace), writeConcern, retryWrites, getCodec(), assertNotNull(toBsonDocument(update)))
@@ -361,6 +368,7 @@ FindAndUpdateOperation<TDocument> findOneAndUpdate(final Bson filter, final Bson
361368
.let(toBsonDocument(options.getLet()));
362369
}
363370

371+
@SuppressWarnings("deprecation")
364372
FindAndUpdateOperation<TDocument> findOneAndUpdate(final Bson filter, final List<? extends Bson> update,
365373
final FindOneAndUpdateOptions options) {
366374
return new FindAndUpdateOperation<>(timeoutSettings.withMaxTimeMS(options.getMaxTime(MILLISECONDS)),

driver-kotlin-coroutine/src/integration/kotlin/com/mongodb/kotlin/client/coroutine/syncadapter/SyncAggregateIterable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ data class SyncAggregateIterable<T : Any>(val wrapped: AggregateFlow<T>) :
3636
}
3737

3838
override fun maxTime(maxTime: Long, timeUnit: TimeUnit): SyncAggregateIterable<T> = apply {
39-
wrapped.maxTime(maxTime, timeUnit)
39+
@Suppress("DEPRECATION") wrapped.maxTime(maxTime, timeUnit)
4040
}
4141

4242
override fun maxAwaitTime(maxAwaitTime: Long, timeUnit: TimeUnit): SyncAggregateIterable<T> = apply {

driver-kotlin-coroutine/src/integration/kotlin/com/mongodb/kotlin/client/coroutine/syncadapter/SyncDistinctIterable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ data class SyncDistinctIterable<T : Any>(val wrapped: DistinctFlow<T>) :
2828
override fun batchSize(batchSize: Int): SyncDistinctIterable<T> = apply { wrapped.batchSize(batchSize) }
2929
override fun filter(filter: Bson?): SyncDistinctIterable<T> = apply { wrapped.filter(filter) }
3030
override fun maxTime(maxTime: Long, timeUnit: TimeUnit): SyncDistinctIterable<T> = apply {
31-
wrapped.maxTime(maxTime, timeUnit)
31+
@Suppress("DEPRECATION") wrapped.maxTime(maxTime, timeUnit)
3232
}
3333
override fun collation(collation: Collation?): SyncDistinctIterable<T> = apply { wrapped.collation(collation) }
3434
override fun comment(comment: String?): SyncDistinctIterable<T> = apply { wrapped.comment(comment) }

driver-kotlin-coroutine/src/integration/kotlin/com/mongodb/kotlin/client/coroutine/syncadapter/SyncFindIterable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ data class SyncFindIterable<T : Any>(val wrapped: FindFlow<T>) : JFindIterable<T
4040
}
4141

4242
override fun maxTime(maxTime: Long, timeUnit: TimeUnit): SyncFindIterable<T> = apply {
43-
wrapped.maxTime(maxTime, timeUnit)
43+
@Suppress("DEPRECATION") wrapped.maxTime(maxTime, timeUnit)
4444
}
4545

4646
override fun maxAwaitTime(maxAwaitTime: Long, timeUnit: TimeUnit): SyncFindIterable<T> = apply {

driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/AggregateFlow.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,23 @@ public class AggregateFlow<T : Any>(private val wrapped: AggregatePublisher<T>)
8181
/**
8282
* Sets the maximum execution time on the server for this operation.
8383
*
84+
* **NOTE**: The maximum execution time option is deprecated. Prefer using the operation execution timeout
85+
* configuration options available at the following levels:
86+
* - [com.mongodb.MongoClientSettings.Builder.timeout]
87+
* - [MongoDatabase.withTimeout]
88+
* - [MongoCollection.withTimeout]
89+
* - [ClientSession]
90+
*
91+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum
92+
* execution time irrelevant. If no timeout is specified at these levels, the maximum execution time will be used.
93+
*
8494
* @param maxTime the max time
8595
* @param timeUnit the time unit, defaults to Milliseconds
8696
* @return this
8797
* @see [Max Time](https://www.mongodb.com/docs/manual/reference/method/cursor.maxTimeMS/#cursor.maxTimeMS)
8898
*/
99+
@Deprecated("Prefer using the operation execution timeout configuration option", level = DeprecationLevel.WARNING)
100+
@Suppress("DEPRECATION")
89101
public fun maxTime(maxTime: Long, timeUnit: TimeUnit = TimeUnit.MILLISECONDS): AggregateFlow<T> = apply {
90102
wrapped.maxTime(maxTime, timeUnit)
91103
}

0 commit comments

Comments
 (0)