Skip to content

Deprecate options: maxTimeMS, maxCommitTimeMS for CRUD methods. #1277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions driver-core/src/main/com/mongodb/TransactionOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,20 @@ public Builder readPreference(@Nullable final ReadPreference readPreference) {
* @return this
* @mongodb.server.release 4.2
* @since 3.11
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing a commit transaction operation, any explicitly set timeout at these levels takes precedence, rendering this
* commit time irrelevant. If no timeout is specified at these levels, the maximum execution time will be used.
*/
@Deprecated
public Builder maxCommitTime(@Nullable final Long maxCommitTime, final TimeUnit timeUnit) {
if (maxCommitTime == null) {
this.maxCommitTimeMS = null;
Expand Down
26 changes: 26 additions & 0 deletions driver-core/src/main/com/mongodb/client/model/CountOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,20 @@ public CountOptions skip(final int skip) {
*
* @param timeUnit the time unit to return the result in
* @return the maximum execution time in the given time unit
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
*/
@Deprecated
public long getMaxTime(final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
return timeUnit.convert(maxTimeMS, TimeUnit.MILLISECONDS);
Expand All @@ -145,7 +158,20 @@ public long getMaxTime(final TimeUnit timeUnit) {
* @param maxTime the max time
* @param timeUnit the time unit, which may not be null
* @return this
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
*/
@Deprecated
public CountOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
this.maxTimeMS = TimeUnit.MILLISECONDS.convert(maxTime, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,20 @@ public class EstimatedDocumentCountOptions {
*
* @param timeUnit the time unit to return the result in
* @return the maximum execution time in the given time unit
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
*/
@Deprecated
public long getMaxTime(final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
return timeUnit.convert(maxTimeMS, TimeUnit.MILLISECONDS);
Expand All @@ -51,7 +64,20 @@ public long getMaxTime(final TimeUnit timeUnit) {
* @param maxTime the max time
* @param timeUnit the time unit, which may not be null
* @return this
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
*/
@Deprecated
public EstimatedDocumentCountOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
this.maxTimeMS = TimeUnit.MILLISECONDS.convert(maxTime, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,20 @@ public FindOneAndDeleteOptions sort(@Nullable final Bson sort) {
* @param maxTime the max time
* @param timeUnit the time unit, which may not be null
* @return this
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
*/
@Deprecated
public FindOneAndDeleteOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
this.maxTimeMS = MILLISECONDS.convert(maxTime, timeUnit);
Expand All @@ -108,7 +121,20 @@ public FindOneAndDeleteOptions maxTime(final long maxTime, final TimeUnit timeUn
*
* @param timeUnit the time unit for the result
* @return the max time
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
*/
@Deprecated
public long getMaxTime(final TimeUnit timeUnit) {
return timeUnit.convert(maxTimeMS, MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,20 @@ public FindOneAndReplaceOptions returnDocument(final ReturnDocument returnDocume
* @param maxTime the max time
* @param timeUnit the time unit, which may not be null
* @return this
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
*/
@Deprecated
public FindOneAndReplaceOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
this.maxTimeMS = MILLISECONDS.convert(maxTime, timeUnit);
Expand All @@ -151,7 +164,20 @@ public FindOneAndReplaceOptions maxTime(final long maxTime, final TimeUnit timeU
*
* @param timeUnit the time unit for the result
* @return the max time
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
*/
@Deprecated
public long getMaxTime(final TimeUnit timeUnit) {
return timeUnit.convert(maxTimeMS, MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,20 @@ public FindOneAndUpdateOptions returnDocument(final ReturnDocument returnDocumen
* @param maxTime the max time
* @param timeUnit the time unit, which may not be null
* @return this
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
*/
@Deprecated
public FindOneAndUpdateOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
this.maxTimeMS = MILLISECONDS.convert(maxTime, timeUnit);
Expand All @@ -154,7 +167,20 @@ public FindOneAndUpdateOptions maxTime(final long maxTime, final TimeUnit timeUn
*
* @param timeUnit the time unit for the result
* @return the max time
*
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
*
* <ul>
* <li>{@code MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
* <li>{@code ClientSession}</li>
* </ul>
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used
*/
@Deprecated
public long getMaxTime(final TimeUnit timeUnit) {
return timeUnit.convert(maxTimeMS, MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public FindOptions skip(final int skip) {
* @param timeUnit the time unit to return the result in
* @return the maximum execution time in the given time unit
* @mongodb.driver.manual reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
* @deprecated This option is deprecated in favor of global operation timeout.
*/
@Deprecated
public long getMaxTime(final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
return timeUnit.convert(maxTimeMS, TimeUnit.MILLISECONDS);
Expand All @@ -162,7 +164,9 @@ public long getMaxTime(final TimeUnit timeUnit) {
* @param timeUnit the time unit, which may not be null
* @return this
* @mongodb.driver.manual reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
* @deprecated This option is deprecated in favor of global operation timeout.
*/
@Deprecated
public FindOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
isTrueArgument("maxTime > = 0", maxTime >= 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public TimeoutSettings getTimeoutSettings() {
}

CountDocumentsOperation countDocuments(final Bson filter, final CountOptions options) {
@SuppressWarnings("deprecation")
CountDocumentsOperation operation = new CountDocumentsOperation(
timeoutSettings.withMaxTimeMS(options.getMaxTime(MILLISECONDS)), assertNotNull(namespace))
.retryReads(retryReads)
Expand All @@ -169,6 +170,7 @@ CountDocumentsOperation countDocuments(final Bson filter, final CountOptions opt
return operation;
}

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

private <TResult> FindOperation<TResult> createFindOperation(final MongoNamespace findNamespace, @Nullable final Bson filter,
final Class<TResult> resultClass, final FindOptions options) {
@SuppressWarnings("deprecation")
FindOperation<TResult> operation = new FindOperation<>(
timeoutSettings.withMaxTimeAndMaxAwaitTimeMS(options.getMaxTime(MILLISECONDS), options.getMaxAwaitTime(MILLISECONDS)),
findNamespace, codecRegistry.get(resultClass))
Expand Down Expand Up @@ -297,6 +300,7 @@ <TResult> MapReduceWithInlineResultsOperation<TResult> mapReduce(final String ma
@Nullable final String finalizeFunction, final Class<TResult> resultClass, final Bson filter, final int limit,
final long maxTimeMS, final boolean jsMode, final Bson scope, final Bson sort, final boolean verbose,
final Collation collation) {
@SuppressWarnings("deprecation")
MapReduceWithInlineResultsOperation<TResult> operation =
new MapReduceWithInlineResultsOperation<>(timeoutSettings.withMaxTimeMS(maxTimeMS),
assertNotNull(namespace), new BsonJavaScript(mapFunction), new BsonJavaScript(reduceFunction),
Expand All @@ -314,6 +318,7 @@ <TResult> MapReduceWithInlineResultsOperation<TResult> mapReduce(final String ma
return operation;
}

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

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

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

@SuppressWarnings("deprecation")
FindAndUpdateOperation<TDocument> findOneAndUpdate(final Bson filter, final List<? extends Bson> update,
final FindOneAndUpdateOptions options) {
return new FindAndUpdateOperation<>(timeoutSettings.withMaxTimeMS(options.getMaxTime(MILLISECONDS)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ data class SyncAggregateIterable<T : Any>(val wrapped: AggregateFlow<T>) :
}

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

override fun maxAwaitTime(maxAwaitTime: Long, timeUnit: TimeUnit): SyncAggregateIterable<T> = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data class SyncDistinctIterable<T : Any>(val wrapped: DistinctFlow<T>) :
override fun batchSize(batchSize: Int): SyncDistinctIterable<T> = apply { wrapped.batchSize(batchSize) }
override fun filter(filter: Bson?): SyncDistinctIterable<T> = apply { wrapped.filter(filter) }
override fun maxTime(maxTime: Long, timeUnit: TimeUnit): SyncDistinctIterable<T> = apply {
wrapped.maxTime(maxTime, timeUnit)
@Suppress("DEPRECATION") wrapped.maxTime(maxTime, timeUnit)
}
override fun collation(collation: Collation?): SyncDistinctIterable<T> = apply { wrapped.collation(collation) }
override fun comment(comment: String?): SyncDistinctIterable<T> = apply { wrapped.comment(comment) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data class SyncFindIterable<T : Any>(val wrapped: FindFlow<T>) : JFindIterable<T
}

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

override fun maxAwaitTime(maxAwaitTime: Long, timeUnit: TimeUnit): SyncFindIterable<T> = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,23 @@ public class AggregateFlow<T : Any>(private val wrapped: AggregatePublisher<T>)
/**
* Sets the maximum execution time on the server for this operation.
*
* **NOTE**: The maximum execution time option is deprecated. Prefer using the operation execution timeout
* configuration options available at the following levels:
* - [com.mongodb.MongoClientSettings.Builder.timeout]
* - [MongoDatabase.withTimeout]
* - [MongoCollection.withTimeout]
* - [ClientSession]
*
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum
* execution time irrelevant. If no timeout is specified at these levels, the maximum execution time will be used.
*
* @param maxTime the max time
* @param timeUnit the time unit, defaults to Milliseconds
* @return this
* @see [Max Time](https://www.mongodb.com/docs/manual/reference/method/cursor.maxTimeMS/#cursor.maxTimeMS)
*/
@Deprecated("Prefer using the operation execution timeout configuration option", level = DeprecationLevel.WARNING)
@Suppress("DEPRECATION")
public fun maxTime(maxTime: Long, timeUnit: TimeUnit = TimeUnit.MILLISECONDS): AggregateFlow<T> = apply {
wrapped.maxTime(maxTime, timeUnit)
}
Expand Down
Loading