-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5887: Simplify retryable read and writes #1882
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |
|
|
||
| namespace MongoDB.Driver.Core.Operations | ||
| { | ||
| internal sealed class DistinctOperation<TValue> : IReadOperation<IAsyncCursor<TValue>> | ||
| internal sealed class DistinctOperation<TValue> : IReadOperation<IAsyncCursor<TValue>>, ICommandCreator | ||
| { | ||
| private Collation _collation; | ||
| private CollectionNamespace _collectionNamespace; | ||
|
|
@@ -111,7 +111,7 @@ public IAsyncCursor<TValue> Execute(OperationContext operationContext, IReadBind | |
| Ensure.IsNotNull(binding, nameof(binding)); | ||
|
|
||
| using (BeginOperation()) | ||
| using (var context = RetryableReadContext.Create(operationContext, binding, _retryRequested)) | ||
| using (var context = new RetryableReadContext(binding, _retryRequested)) | ||
| { | ||
| var operation = CreateOperation(operationContext, context); | ||
| var result = operation.Execute(operationContext, context); | ||
|
|
@@ -127,7 +127,7 @@ public async Task<IAsyncCursor<TValue>> ExecuteAsync(OperationContext operationC | |
| Ensure.IsNotNull(binding, nameof(binding)); | ||
|
|
||
| using (BeginOperation()) | ||
| using (var context = await RetryableReadContext.CreateAsync(operationContext, binding, _retryRequested).ConfigureAwait(false)) | ||
| using (var context = new RetryableReadContext(binding, _retryRequested)) | ||
| { | ||
| var operation = CreateOperation(operationContext, context); | ||
| var result = await operation.ExecuteAsync(operationContext, context).ConfigureAwait(false); | ||
|
|
@@ -153,14 +153,18 @@ public BsonDocument CreateCommand(OperationContext operationContext, ICoreSessio | |
| }; | ||
| } | ||
|
|
||
| private EventContext.OperationNameDisposer BeginOperation() => EventContext.BeginOperation(OperationName); | ||
| private EventContext.OperationIdDisposer BeginOperation() => EventContext.BeginOperation(null, OperationName); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something strange. If we use this overloads, then the name of the command gets set properly. |
||
|
|
||
| private ReadCommandOperation<DistinctResult> CreateOperation(OperationContext operationContext, RetryableReadContext context) | ||
| { | ||
| var command = CreateCommand(operationContext, context.Binding.Session, context.Channel.ConnectionDescription); | ||
| var serializer = new DistinctResultDeserializer(_valueSerializer); | ||
|
|
||
| return new ReadCommandOperation<DistinctResult>(_collectionNamespace.DatabaseNamespace, command, serializer, _messageEncoderSettings, OperationName) | ||
| return new ReadCommandOperation<DistinctResult>( | ||
| _collectionNamespace.DatabaseNamespace, | ||
| this, | ||
| serializer, | ||
| _messageEncoderSettings, | ||
| OperationName) | ||
| { | ||
| RetryRequested = _retryRequested // might be overridden by retryable read context | ||
| }; | ||
|
|
||
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.
This is used so that we can modify the command once the
ReadCommandOperationhas been created.This is done because some operations need to have the
operationContextto properly create the command, but now theoperationContextis not available until later.I'm not a fan of this implementation, to be honest.
We got two other possibilities in my opinion:
ReadCommandOperationequivalent toWriteCommandOperation, so it does not concern with retryability. Then we make a new class,RetryableReadCommandOperationthat has retryability and usesReadCommandOperationinsideI think nr1 is more desirable, but requires further much more refactoring.