Skip to content

Commit f7e566f

Browse files
committed
Remove TimeoutSettings from Operations
The OperationExecutor is now in charge of TimeoutContext. Paves the way for multiple operations using the same TimeoutContext. JAVA-5176
1 parent 144ce16 commit f7e566f

File tree

150 files changed

+1533
-1779
lines changed

Some content is hidden

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

150 files changed

+1533
-1779
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.mongodb.Function;
2020
import com.mongodb.WriteConcern;
21-
import com.mongodb.internal.TimeoutSettings;
2221
import com.mongodb.lang.Nullable;
2322
import org.bson.BsonDocument;
2423

@@ -32,8 +31,8 @@
3231
public class AbortTransactionOperation extends TransactionOperation {
3332
private BsonDocument recoveryToken;
3433

35-
public AbortTransactionOperation(final TimeoutSettings timeoutSettings, final WriteConcern writeConcern) {
36-
super(timeoutSettings, writeConcern);
34+
public AbortTransactionOperation(final WriteConcern writeConcern) {
35+
super(writeConcern);
3736
}
3837

3938
public AbortTransactionOperation recoveryToken(@Nullable final BsonDocument recoveryToken) {

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import com.mongodb.MongoCommandException;
2121
import com.mongodb.MongoNamespace;
22-
import com.mongodb.internal.TimeoutSettings;
2322
import com.mongodb.internal.async.SingleResultCallback;
2423
import com.mongodb.internal.binding.AsyncWriteBinding;
2524
import com.mongodb.internal.binding.WriteBinding;
@@ -39,19 +38,12 @@
3938
* <p>This class is not part of the public API and may be removed or changed at any time</p>
4039
*/
4140
abstract class AbstractWriteSearchIndexOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> {
42-
private final TimeoutSettings timeoutSettings;
4341
private final MongoNamespace namespace;
4442

45-
AbstractWriteSearchIndexOperation(final TimeoutSettings timeoutSettings, final MongoNamespace namespace) {
46-
this.timeoutSettings = timeoutSettings;
43+
AbstractWriteSearchIndexOperation(final MongoNamespace namespace) {
4744
this.namespace = namespace;
4845
}
4946

50-
@Override
51-
public TimeoutSettings getTimeoutSettings() {
52-
return timeoutSettings;
53-
}
54-
5547
@Override
5648
public Void execute(final WriteBinding binding) {
5749
return withConnection(binding, connection -> {

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.mongodb.MongoNamespace;
2121
import com.mongodb.client.cursor.TimeoutMode;
2222
import com.mongodb.client.model.Collation;
23-
import com.mongodb.internal.TimeoutSettings;
2423
import com.mongodb.internal.async.AsyncBatchCursor;
2524
import com.mongodb.internal.async.SingleResultCallback;
2625
import com.mongodb.internal.binding.AsyncReadBinding;
@@ -44,14 +43,13 @@
4443
public class AggregateOperation<T> implements AsyncExplainableReadOperation<AsyncBatchCursor<T>>, ExplainableReadOperation<BatchCursor<T>> {
4544
private final AggregateOperationImpl<T> wrapped;
4645

47-
public AggregateOperation(final TimeoutSettings timeoutSettings, final MongoNamespace namespace,
48-
final List<BsonDocument> pipeline, final Decoder<T> decoder) {
49-
this(timeoutSettings, namespace, pipeline, decoder, AggregationLevel.COLLECTION);
46+
public AggregateOperation(final MongoNamespace namespace, final List<BsonDocument> pipeline, final Decoder<T> decoder) {
47+
this(namespace, pipeline, decoder, AggregationLevel.COLLECTION);
5048
}
5149

52-
public AggregateOperation(final TimeoutSettings timeoutSettings, final MongoNamespace namespace,
53-
final List<BsonDocument> pipeline, final Decoder<T> decoder, final AggregationLevel aggregationLevel) {
54-
this.wrapped = new AggregateOperationImpl<>(timeoutSettings, namespace, pipeline, decoder, aggregationLevel);
50+
public AggregateOperation(final MongoNamespace namespace, final List<BsonDocument> pipeline, final Decoder<T> decoder,
51+
final AggregationLevel aggregationLevel) {
52+
this.wrapped = new AggregateOperationImpl<>(namespace, pipeline, decoder, aggregationLevel);
5553
}
5654

5755
public List<BsonDocument> getPipeline() {
@@ -131,11 +129,6 @@ public AggregateOperation<T> hint(@Nullable final BsonValue hint) {
131129
return this;
132130
}
133131

134-
@Override
135-
public TimeoutSettings getTimeoutSettings() {
136-
return wrapped.getTimeoutSettings();
137-
}
138-
139132
public AggregateOperation<T> timeoutMode(@Nullable final TimeoutMode timeoutMode) {
140133
wrapped.timeoutMode(timeoutMode);
141134
return this;
@@ -161,7 +154,7 @@ public <R> AsyncReadOperation<R> asAsyncExplainableOperation(@Nullable final Exp
161154
}
162155

163156
<R> CommandReadOperation<R> createExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder<R> resultDecoder) {
164-
return new CommandReadOperation<>(wrapped.getTimeoutSettings(), getNamespace().getDatabaseName(),
157+
return new CommandReadOperation<>(getNamespace().getDatabaseName(),
165158
(operationContext, serverDescription, connectionDescription) ->
166159
asExplainCommand(wrapped.getCommand(operationContext, MIN_WIRE_VERSION), verbosity), resultDecoder);
167160
}

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.mongodb.MongoNamespace;
2020
import com.mongodb.client.cursor.TimeoutMode;
2121
import com.mongodb.client.model.Collation;
22-
import com.mongodb.internal.TimeoutSettings;
2322
import com.mongodb.internal.async.AsyncBatchCursor;
2423
import com.mongodb.internal.async.SingleResultCallback;
2524
import com.mongodb.internal.binding.AsyncReadBinding;
@@ -46,6 +45,7 @@
4645
import static com.mongodb.internal.operation.CommandOperationHelper.CommandCreator;
4746
import static com.mongodb.internal.operation.OperationHelper.LOGGER;
4847
import static com.mongodb.internal.operation.OperationHelper.addMaxTimeMSToNonTailableCursor;
48+
import static com.mongodb.internal.operation.OperationHelper.validateTimeoutMode;
4949
import static com.mongodb.internal.operation.OperationReadConcernHelper.appendReadConcernToCommand;
5050
import static com.mongodb.internal.operation.SyncOperationHelper.CommandReadTransformer;
5151
import static com.mongodb.internal.operation.SyncOperationHelper.executeRetryableRead;
@@ -55,7 +55,6 @@ class AggregateOperationImpl<T> implements AsyncReadOperation<AsyncBatchCursor<T
5555
private static final String CURSOR = "cursor";
5656
private static final String FIRST_BATCH = "firstBatch";
5757
private static final List<String> FIELD_NAMES_WITH_RESULT = Arrays.asList(RESULT, FIRST_BATCH);
58-
private final TimeoutSettings timeoutSettings;
5958
private final MongoNamespace namespace;
6059
private final List<BsonDocument> pipeline;
6160
private final Decoder<T> decoder;
@@ -71,18 +70,17 @@ class AggregateOperationImpl<T> implements AsyncReadOperation<AsyncBatchCursor<T
7170
private BsonDocument variables;
7271
private TimeoutMode timeoutMode;
7372

74-
AggregateOperationImpl(final TimeoutSettings timeoutSettings, final MongoNamespace namespace,
73+
AggregateOperationImpl(final MongoNamespace namespace,
7574
final List<BsonDocument> pipeline, final Decoder<T> decoder, final AggregationLevel aggregationLevel) {
76-
this(timeoutSettings, namespace, pipeline, decoder,
75+
this(namespace, pipeline, decoder,
7776
defaultAggregateTarget(notNull("aggregationLevel", aggregationLevel),
7877
notNull("namespace", namespace).getCollectionName()),
7978
defaultPipelineCreator(pipeline));
8079
}
8180

82-
AggregateOperationImpl(final TimeoutSettings timeoutSettings, final MongoNamespace namespace,
81+
AggregateOperationImpl(final MongoNamespace namespace,
8382
final List<BsonDocument> pipeline, final Decoder<T> decoder, final AggregateTarget aggregateTarget,
8483
final PipelineCreator pipelineCreator) {
85-
this.timeoutSettings = timeoutSettings;
8684
this.namespace = notNull("namespace", namespace);
8785
this.pipeline = notNull("pipeline", pipeline);
8886
this.decoder = notNull("decoder", decoder);
@@ -158,13 +156,7 @@ BsonValue getHint() {
158156
return hint;
159157
}
160158

161-
@Override
162-
public TimeoutSettings getTimeoutSettings() {
163-
return timeoutSettings;
164-
}
165-
166159
public AggregateOperationImpl<T> timeoutMode(@Nullable final TimeoutMode timeoutMode) {
167-
isTrueArgument("timeoutMode requires timeoutMS.", timeoutMode == null || timeoutSettings.getTimeoutMS() != null);
168160
if (timeoutMode != null) {
169161
this.timeoutMode = timeoutMode;
170162
}
@@ -199,6 +191,7 @@ private CommandCreator getCommandCreator() {
199191
}
200192

201193
BsonDocument getCommand(final OperationContext operationContext, final int maxWireVersion) {
194+
validateTimeoutMode(operationContext, timeoutMode);
202195
BsonDocument commandDocument = new BsonDocument("aggregate", aggregateTarget.create());
203196
appendReadConcernToCommand(operationContext.getSessionContext(), maxWireVersion, commandDocument);
204197
commandDocument.put("pipeline", pipelineCreator.create());
@@ -229,14 +222,14 @@ BsonDocument getCommand(final OperationContext operationContext, final int maxWi
229222

230223
private CommandReadTransformer<BsonDocument, CommandBatchCursor<T>> transformer() {
231224
return (result, source, connection) ->
232-
new CommandBatchCursor<>(getTimeoutMode(), result, batchSize != null ? batchSize : 0, getMaxTimeForCursor(), decoder,
233-
comment, source, connection);
225+
new CommandBatchCursor<>(getTimeoutMode(), result, batchSize != null ? batchSize : 0,
226+
getMaxTimeForCursor(source.getOperationContext()), decoder, comment, source, connection);
234227
}
235228

236229
private CommandReadTransformerAsync<BsonDocument, AsyncBatchCursor<T>> asyncTransformer() {
237230
return (result, source, connection) ->
238-
new AsyncCommandBatchCursor<>(getTimeoutMode(), result, batchSize != null ? batchSize : 0, getMaxTimeForCursor(), decoder,
239-
comment, source, connection);
231+
new AsyncCommandBatchCursor<>(getTimeoutMode(), result, batchSize != null ? batchSize : 0,
232+
getMaxTimeForCursor(source.getOperationContext()), decoder, comment, source, connection);
240233
}
241234

242235
private TimeoutMode getTimeoutMode() {
@@ -247,8 +240,8 @@ private TimeoutMode getTimeoutMode() {
247240
return localTimeoutMode;
248241
}
249242

250-
private long getMaxTimeForCursor() {
251-
return timeoutSettings.getMaxAwaitTimeMS();
243+
private long getMaxTimeForCursor(final OperationContext operationContext) {
244+
return operationContext.getTimeoutContext().getMaxAwaitTimeMS();
252245
}
253246

254247
interface AggregateTarget {

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.mongodb.WriteConcern;
2323
import com.mongodb.client.cursor.TimeoutMode;
2424
import com.mongodb.client.model.Collation;
25-
import com.mongodb.internal.TimeoutSettings;
2625
import com.mongodb.internal.async.SingleResultCallback;
2726
import com.mongodb.internal.binding.AsyncReadBinding;
2827
import com.mongodb.internal.binding.ReadBinding;
@@ -57,7 +56,6 @@
5756
* <p>This class is not part of the public API and may be removed or changed at any time</p>
5857
*/
5958
public class AggregateToCollectionOperation implements AsyncReadOperation<Void>, ReadOperation<Void> {
60-
private final TimeoutSettings timeoutSettings;
6159
private final MongoNamespace namespace;
6260
private final List<BsonDocument> pipeline;
6361
private final WriteConcern writeConcern;
@@ -71,15 +69,13 @@ public class AggregateToCollectionOperation implements AsyncReadOperation<Void>,
7169
private BsonValue hint;
7270
private BsonDocument variables;
7371

74-
public AggregateToCollectionOperation(final TimeoutSettings timeoutSettings, final MongoNamespace namespace,
75-
final List<BsonDocument> pipeline, final ReadConcern readConcern, final WriteConcern writeConcern) {
76-
this(timeoutSettings, namespace, pipeline, readConcern, writeConcern, AggregationLevel.COLLECTION);
72+
public AggregateToCollectionOperation(final MongoNamespace namespace, final List<BsonDocument> pipeline, final ReadConcern readConcern,
73+
final WriteConcern writeConcern) {
74+
this(namespace, pipeline, readConcern, writeConcern, AggregationLevel.COLLECTION);
7775
}
7876

79-
public AggregateToCollectionOperation(final TimeoutSettings timeoutSettings, final MongoNamespace namespace,
80-
final List<BsonDocument> pipeline, @Nullable final ReadConcern readConcern, @Nullable final WriteConcern writeConcern,
81-
final AggregationLevel aggregationLevel) {
82-
this.timeoutSettings = timeoutSettings;
77+
public AggregateToCollectionOperation(final MongoNamespace namespace, final List<BsonDocument> pipeline,
78+
@Nullable final ReadConcern readConcern, @Nullable final WriteConcern writeConcern, final AggregationLevel aggregationLevel) {
8379
this.namespace = notNull("namespace", namespace);
8480
this.pipeline = notNull("pipeline", pipeline);
8581
this.writeConcern = writeConcern;
@@ -156,11 +152,6 @@ public AggregateToCollectionOperation timeoutMode(@Nullable final TimeoutMode ti
156152
return this;
157153
}
158154

159-
@Override
160-
public TimeoutSettings getTimeoutSettings() {
161-
return timeoutSettings;
162-
}
163-
164155
@Override
165156
public Void execute(final ReadBinding binding) {
166157
return executeRetryableRead(binding,

0 commit comments

Comments
 (0)