-
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
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.
Fixed.
{ | ||
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?
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.
Fixed.
|
||
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
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'm OK with removing the class here. I've left it only to stress on the fact that it should be class, not struct. As changing to struct might affect its functionality (because of the copy-by-value nature of structs).
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.
yeah let's remove the class, record is by default a class and if someone tries to change it to struct then we can address it then in the PR containing that change.
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.
The idea was to hide the implicit session creation inside of the OperationExecutor. But for some corner cases (like Aggregate method) we should have access to the created session, so sometimes we have to create the implicit session from outside.
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.
Thank you for reporting this. I've converted rest of the methods and removed UsingImplicitSession
.
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
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.
partial review: minor comments so far.
@@ -58,6 +58,8 @@ private MongoCollectionImpl(IMongoDatabase database, CollectionNamespace collect | |||
_documentSerializer = Ensure.IsNotNull(documentSerializer, nameof(documentSerializer)); | |||
|
|||
_messageEncoderSettings = GetMessageEncoderSettings(); | |||
_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.
minor:
_readOperationOptions = new()
_writeOperationOptions = new(...)
Ensure.IsNotNullOrEmpty(name, nameof(name)); | ||
if (name == "*") | ||
{ | ||
throw new ArgumentException("Cannot specify '*' for the index name. Use DropAllAsync to drop all indexes.", "name"); |
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: mistake in the original code, should be DropAll
and DropAllAsync
.
@@ -50,6 +51,9 @@ public MongoDatabase(IMongoClient client, DatabaseNamespace databaseNamespace, M | |||
_settings = Ensure.IsNotNull(settings, nameof(settings)).Freeze(); | |||
_cluster = Ensure.IsNotNull(cluster, nameof(cluster)); | |||
_operationExecutor = Ensure.IsNotNull(operationExecutor, nameof(operationExecutor)); | |||
|
|||
_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.
minor: new(...)
?
|
||
private IReadWriteBindingHandle CreateReadWriteBinding(IClientSessionHandle session) | ||
{ | ||
// TODO: CreateReadWriteBinding from MongoClient did not used ChannelPinningHelper, double-check if it's OK to start using it |
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.
Need to address this TODO.
@@ -100,7 +104,7 @@ public MongoClient(string connectionString) | |||
internal MongoClient(IOperationExecutor operationExecutor, MongoClientSettings settings) | |||
: this(settings) | |||
{ | |||
_operationExecutor = operationExecutor; | |||
_operationExecutor = new OperationExecutorWrapper(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.
Consider using the Fork
approach.
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.
@BorisDog what is the Fork
approach?
{ | ||
[Theory] | ||
[ParameterAttributeData] | ||
public async Task StartImplicitSession_should_call_cluster([Values(true, false)]bool isAsync) |
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: _cluster_StartSession
|
||
namespace MongoDB.Driver | ||
{ | ||
internal record class 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.
remove class here too
No description provided.