-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5560: CSOT: Refactor IOperationExecutor to use operation context #1676
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?
Conversation
{ | ||
return operation.Execute(binding, cancellationToken); | ||
bool isOwnSession = session == null; |
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.
nit: use var?
here and other methods in this file
{ | ||
return _client.StartImplicitSessionAsync(cancellationToken); | ||
var options = new ClientSessionOptions { CausalConsistency = false, Snapshot = false }; | ||
ICoreSessionHandle coreSession = _client.GetClusterInternal().StartSession(options.ToCore(isImplicit: true)); |
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.
nit: use var?
|
||
namespace MongoDB.Driver | ||
{ | ||
internal record class ReadOperationOptions(ReadPreference ExplicitReadPreference = null, ReadPreference DefaultReadPreference = null); |
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.
no need for specifying class
? I believe record
is equivalent to record class
return UsingImplicitSession(session => BulkWrite(session, requests, options, cancellationToken), cancellationToken); | ||
using var session = OperationExecutor.StartImplicitSession(cancellationToken); | ||
return BulkWrite(session, requests, options, cancellationToken); |
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.
I noticed that for some of the other methods above (like AggregateToCollection
) you did not use OperationExecutor
to create the implicit session and just used the existing UsingImplicitSession
mechanism. Should we update all those use cases as well? or am I missing something?
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! left some minor comments
|
||
var lastStage = renderedPipeline.Documents.LastOrDefault(); | ||
var lastStageName = lastStage?.GetElement(0).Name; | ||
isAggregateToCollection = lastStage != null && (lastStageName == "$out" || lastStageName == "$merge"); |
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.
nit: lastStage != null
check is redundant?
@@ -66,6 +67,9 @@ public MongoClient(MongoClientSettings settings) | |||
|
|||
_cluster = _settings.ClusterSource.Get(_settings.ToClusterKey()); | |||
_operationExecutor = new OperationExecutor(this); | |||
_readOperationOptions = new ReadOperationOptions(DefaultReadPreference: _settings.ReadPreference); | |||
_writeOperationOptions = new WriteOperationOptions(); | |||
|
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.
nit: consider
_readOperationOptions = new (DefaultReadPreference: _settings.ReadPreference);
_writeOperationOptions = new WriteOperationOptions();
@@ -117,8 +121,6 @@ internal MongoClient(IOperationExecutor operationExecutor, MongoClientSettings s | |||
// internal methods | |||
internal void ConfigureAutoEncryptionMessageEncoderSettings(MessageEncoderSettings messageEncoderSettings) | |||
{ | |||
ThrowIfDisposed(); |
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.
No need?
{ | ||
return operation.Execute(binding, cancellationToken); | ||
bool isOwnSession = session == null; |
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.
nit: var
@@ -94,160 +98,117 @@ public override MongoCollectionSettings Settings | |||
} | |||
|
|||
// public methods | |||
public override IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options, CancellationToken cancellationToken = default(CancellationToken)) | |||
public override IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options, CancellationToken cancellationToken = default) | |||
{ | |||
return UsingImplicitSession(session => Aggregate(session, pipeline, options, cancellationToken), cancellationToken); |
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.
Do we want to reuse the newer pattern without UsingImplicitSession
here (like in MongoDatabase
)?
} | ||
|
||
// public properties | ||
public IMongoClient Client => _client; | ||
public DatabaseNamespace DatabaseNamespace => _databaseNamespace; | ||
private IOperationExecutor OperationExecutor => _operationExecutor; |
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.
Do we need this?
return UsingImplicitSession(session => ListCollectionNames(session, options, cancellationToken), cancellationToken); | ||
var cursor = OperationExecutor.ExecuteReadOperation(CreateListCollectionNamesOperation(options), | ||
_readOperationOptions with { DefaultReadPreference = ReadPreference.Primary }, | ||
null, cancellationToken); |
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.
minor: New line for each param?
@@ -778,9 +717,10 @@ private async Task<IWriteOperation<BsonDocument>> CreateDropCollectionOperationA | |||
}); | |||
} | |||
|
|||
private ListCollectionsOperation CreateListCollectionNamesOperation(ListCollectionNamesOptions options, RenderArgs<BsonDocument> renderArgs) | |||
private ListCollectionsOperation CreateListCollectionNamesOperation(ListCollectionNamesOptions options) |
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.
Maybe refactoring to
CreateDropCollectionOperation
GetEncryptedFieldsMap
GetEncryptedFieldsMapAsync
Would be cleaner.
|
||
namespace MongoDB.Driver.Tests | ||
{ | ||
public class ReadOperationOptionsTests |
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.
+1
|
||
[Theory] | ||
[MemberData(nameof(ImplicitSessionTestCases))] | ||
public async Task ExecuteReadOperationShouldStartAndDisposeImplicitSessionIfNeeded(bool shouldCreateSession, bool isAsync, IClientSessionHandle session) |
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.
Don't we use this format:
ExecuteReadOperation_should_start_and..
?
No description provided.