-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Remove TimeoutSettings from Operations #1309
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
Conversation
The OperationExecutor is now in charge of TimeoutContext. Paves the way for multiple operations using the same TimeoutContext. JAVA-5176
There is an existing patch(es) for this commit SHA: Please note that the status that is posted is not in the context of this PR but rather the (latest) existing patch and that may affect some tests that may depend on the particular PR. If your tests do not rely on any PR-specific values (like base or head branch name) then your tests will report the same status. If you would like a patch to run in the context of this PR and abort the other(s), comment 'evergreen retry'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall! I have just a couple of suggestions.
@@ -225,6 +216,7 @@ private CommandReadTransformerAsync<BsonDocument, AsyncBatchCursor<T>> asyncTran | |||
|
|||
private CommandCreator getCommandCreator() { | |||
return (operationContext, serverDescription, connectionDescription) -> { | |||
validateTimeoutMode(operationContext, timeoutMode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation defers validation until a CommandCreator
is executed. This approach means we've already selected the server and checked out a connection from the pool before realizing that the operation should not proceed due to invalid inputs. By validating inputs earlier, we can avoid unnecessary overhead.
I propose moving the validation to:
- The execute/executeAsync method to preemptively reject the execution of operations with invalid inputs.
- Preferably, in the
timeoutMode()
method of anIterable
. This placement allows us to inform the user about invalid inputs immediately. SinceTimeoutSetting
is accessible within anIterable
andtimeoutMS
cannot be overridden once anIterable
created, we can safely perform the validation here.
This aligns with our existing validation logic in AggregateIterableImpl.java#L213.
For example:
@Override
public ListIndexesIterable<TResult> timeoutMode(final TimeoutMode timeoutMode) {
if (getTimeoutSettings().getTimeoutMS() == null) {
throw new IllegalArgumentException("TimeoutMode requires timeoutMS to be set.");
}
super.timeoutMode(timeoutMode);
return this;
}
This comment also applies to the following commands, as they currently include validateTimeoutMode
in their CommandCreators
:
- ListIndexOperations
- ListCollectionsOperations
- FindOperation
- AggregateOperation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -81,11 +79,9 @@ public class ListCollectionsOperation<T> implements AsyncReadOperation<AsyncBatc | |||
private boolean nameOnly; | |||
private boolean authorizedCollections; | |||
private BsonValue comment; | |||
private TimeoutMode timeoutMode = TimeoutMode.CURSOR_LIFETIME; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the specification, the default value for a non-tailable cursor should be CURSOR_LIFETIME
.
Currently, if a user does not specify any timeout mode, a null value will be passed down to CommandBatchCursor
.
While using null does not change functionality, to maintain code clarity, I suggest continuing to use TimeoutMode.CURSOR_LIFETIME
as the explicit default value in our codebase, as it was before this change.
-
Moving the
validateTimeoutMode
to a higher level within theIterable
interface, as suggested in this discussion_r1493611453, would allow us to maintain this explicit default value inOperation
s or evenIterable
s itself. -
Alternatively, if
validateTimeoutMode
remains withinOperation
, I propose explicitly passingCURSOR_LIFETIME
as the default toCommandBatchCursor
:
private CommandReadTransformer<BsonDocument, BatchCursor<T>> transformer() {
return (result, source, connection) ->
cursorDocumentToBatchCursor(defaultIfNull(timeoutMode, TimeoutMode.CURSOR_LIFETIME), result, batchSize, decoder, comment, source, connection);
}
This comment also applies to the following commands:
- ListIndexOperations
- ListCollectionsOperations
- AggregateOperation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated & ready for review - thanks @vbabanin
iterable.batchSize(cur.getValue().asNumber().intValue()); | ||
break; | ||
case "timeoutMode": | ||
setTimeoutMode(iterable, cur); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the timeout mode can now throw an exception - so running in the resultOf block.
Decoupled Operations from TimeoutSettings.
Added
OperationExecutor#withTimeoutSettings
to pass in timeout settings.JAVA-5176