Skip to content

Commit 3ba95b0

Browse files
authored
Remove TimeoutSettings from Operations (#1309)
The OperationExecutor is now in charge of TimeoutContext. Paves the way for multiple operations using the same TimeoutContext. JAVA-5176
1 parent 5966e95 commit 3ba95b0

File tree

152 files changed

+1599
-1847
lines changed

Some content is hidden

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

152 files changed

+1599
-1847
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: 9 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;
@@ -55,7 +54,6 @@ class AggregateOperationImpl<T> implements AsyncReadOperation<AsyncBatchCursor<T
5554
private static final String CURSOR = "cursor";
5655
private static final String FIRST_BATCH = "firstBatch";
5756
private static final List<String> FIELD_NAMES_WITH_RESULT = Arrays.asList(RESULT, FIRST_BATCH);
58-
private final TimeoutSettings timeoutSettings;
5957
private final MongoNamespace namespace;
6058
private final List<BsonDocument> pipeline;
6159
private final Decoder<T> decoder;
@@ -71,18 +69,17 @@ class AggregateOperationImpl<T> implements AsyncReadOperation<AsyncBatchCursor<T
7169
private BsonDocument variables;
7270
private TimeoutMode timeoutMode;
7371

74-
AggregateOperationImpl(final TimeoutSettings timeoutSettings, final MongoNamespace namespace,
72+
AggregateOperationImpl(final MongoNamespace namespace,
7573
final List<BsonDocument> pipeline, final Decoder<T> decoder, final AggregationLevel aggregationLevel) {
76-
this(timeoutSettings, namespace, pipeline, decoder,
74+
this(namespace, pipeline, decoder,
7775
defaultAggregateTarget(notNull("aggregationLevel", aggregationLevel),
7876
notNull("namespace", namespace).getCollectionName()),
7977
defaultPipelineCreator(pipeline));
8078
}
8179

82-
AggregateOperationImpl(final TimeoutSettings timeoutSettings, final MongoNamespace namespace,
80+
AggregateOperationImpl(final MongoNamespace namespace,
8381
final List<BsonDocument> pipeline, final Decoder<T> decoder, final AggregateTarget aggregateTarget,
8482
final PipelineCreator pipelineCreator) {
85-
this.timeoutSettings = timeoutSettings;
8683
this.namespace = notNull("namespace", namespace);
8784
this.pipeline = notNull("pipeline", pipeline);
8885
this.decoder = notNull("decoder", decoder);
@@ -158,13 +155,7 @@ BsonValue getHint() {
158155
return hint;
159156
}
160157

161-
@Override
162-
public TimeoutSettings getTimeoutSettings() {
163-
return timeoutSettings;
164-
}
165-
166158
public AggregateOperationImpl<T> timeoutMode(@Nullable final TimeoutMode timeoutMode) {
167-
isTrueArgument("timeoutMode requires timeoutMS.", timeoutMode == null || timeoutSettings.getTimeoutMS() != null);
168159
if (timeoutMode != null) {
169160
this.timeoutMode = timeoutMode;
170161
}
@@ -229,14 +220,14 @@ BsonDocument getCommand(final OperationContext operationContext, final int maxWi
229220

230221
private CommandReadTransformer<BsonDocument, CommandBatchCursor<T>> transformer() {
231222
return (result, source, connection) ->
232-
new CommandBatchCursor<>(getTimeoutMode(), result, batchSize != null ? batchSize : 0, getMaxTimeForCursor(), decoder,
233-
comment, source, connection);
223+
new CommandBatchCursor<>(getTimeoutMode(), result, batchSize != null ? batchSize : 0,
224+
getMaxTimeForCursor(source.getOperationContext()), decoder, comment, source, connection);
234225
}
235226

236227
private CommandReadTransformerAsync<BsonDocument, AsyncBatchCursor<T>> asyncTransformer() {
237228
return (result, source, connection) ->
238-
new AsyncCommandBatchCursor<>(getTimeoutMode(), result, batchSize != null ? batchSize : 0, getMaxTimeForCursor(), decoder,
239-
comment, source, connection);
229+
new AsyncCommandBatchCursor<>(getTimeoutMode(), result, batchSize != null ? batchSize : 0,
230+
getMaxTimeForCursor(source.getOperationContext()), decoder, comment, source, connection);
240231
}
241232

242233
private TimeoutMode getTimeoutMode() {
@@ -247,8 +238,8 @@ private TimeoutMode getTimeoutMode() {
247238
return localTimeoutMode;
248239
}
249240

250-
private long getMaxTimeForCursor() {
251-
return timeoutSettings.getMaxAwaitTimeMS();
241+
private long getMaxTimeForCursor(final OperationContext operationContext) {
242+
return operationContext.getTimeoutContext().getMaxAwaitTimeMS();
252243
}
253244

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