-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-3552: CSOT: Transactions #1745
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
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.
Proposed changes prototyped here:
https://github.com/rstam/mongo-csharp-driver/tree/chsarp3552-0807
namespace MongoDB.Driver.Core.Bindings | ||
{ | ||
// TODO: CSOT: Make it public when CSOT will be ready for GA | ||
internal static class ICoreSessionExtensions |
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 recommend creating a new ICoreSessionInternal
interface to hold the new methods we hope to eventually add to ICoreSession
.
These extension methods are useful to make it "look" (to us) like the new methods are already part of ICoreSession
.
These extension methods should cast session
to ICoreSessionInternal
instead of to an open ended set of concrete implementations.
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.
All classes that implement ICoreSession
(directly or indirectly) should also now implement ICoreSessionInternal
.
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. Thank you!
{ | ||
if (options == null || session.Options.DefaultTransactionOptions?.Timeout == options.Timeout) | ||
{ | ||
session.AbortTransaction(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.
Forwarding the new method to the old method doesn't seem necessary but it also doesn't do any real harm other than adding more lines of code that probably aren't needed.
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've decided to have this forwarding, just in case there are any external implementation of ICoreSession, this forwarding might reduce risk of breaking client's code.
@@ -182,17 +182,25 @@ public ICoreSession Wrapped | |||
|
|||
// public methods | |||
/// <inheritdoc /> | |||
public virtual void AbortTransaction(CancellationToken cancellationToken = default(CancellationToken)) | |||
public virtual void AbortTransaction(CancellationToken cancellationToken = default) | |||
=> AbortTransaction(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.
I would have left this method unchanged and forwarded to:
_wrapped.AbortTransaction(cancellationToken);
Let the wrapped class decide whether to forward to the new method or not.
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.
} | ||
|
||
/// <inheritdoc /> | ||
public virtual Task AbortTransactionAsync(CancellationToken cancellationToken = default(CancellationToken)) | ||
public virtual Task AbortTransactionAsync(CancellationToken cancellationToken = default) | ||
=> AbortTransactionAsync(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.
Same here.
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.
@@ -223,17 +231,25 @@ public long AdvanceTransactionNumber() | |||
} | |||
|
|||
/// <inheritdoc /> | |||
public virtual void CommitTransaction(CancellationToken cancellationToken = default(CancellationToken)) | |||
public virtual void CommitTransaction(CancellationToken cancellationToken = default) | |||
=> CommitTransaction(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.
Same here.
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.
|
||
namespace MongoDB.Driver.Core.Misc | ||
{ | ||
internal sealed class SystemWatch : IWatch |
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 think this class should be called SystemStopwatch
.
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.
{ | ||
public static ReadPreference GetEffectiveReadPreference(this IClientSession session, ReadPreference defaultReadPreference) | ||
// TODO: CSOT: Make it public when CSOT will be ready for GA | ||
internal static class IClientSessionExtensions |
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 recommend adding an interface called IClientSessionInternal
to hold all the internal methods that we plan to eventually move to IClientSession
.
These extension methods should be casting session
to IClientSessionInternal
instead of to an unknown number of concrete implementations. (Yes there is only one implementation now, but that's not the point).
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. Thank you!
@@ -85,7 +85,11 @@ public CancellationToken CombinedCancellationToken | |||
return _combinedCancellationTokenSource.Token; | |||
} | |||
} | |||
private Stopwatch Stopwatch { get; } | |||
private IWatch Watch { get; } |
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 think this property should be called Stopwatch
.
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.
public IWatch StartWatch() | ||
{ | ||
var startTime = _utcNow; | ||
var mock = new Mock<IWatch>(); |
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 renaming mock
to mockStopwatch
.
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.
@@ -734,8 +699,11 @@ private Mock<IClock> CreateClockMock(DateTime now, bool[] isRetryAttemptsWithTim | |||
} | |||
|
|||
var mockClock = new Mock<IClock>(); | |||
var watchMock = new Mock<IWatch>(); |
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 renaming watchMock
to mockStopwatch
.
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.
Same in other places like this.
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.
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. Will provide next review in a bit
public Task CommitTransactionAsync(CancellationToken cancellationToken = default) | ||
=> CommitTransactionAsync(null, cancellationToken); | ||
|
||
// TODO: CSOT: Make it public when CSOT will be ready for GA | ||
internal async Task CommitTransactionAsync(CommitTransactionOptions options, CancellationToken cancellationToken = default(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.
Inconsistent default parameter syntax for cancellationToken for both methods. Standardize on either default
or default(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.
Done.
=> CommitTransactionAsync(null, cancellationToken); | ||
|
||
// TODO: CSOT: Make it public when CSOT will be ready for GA | ||
internal virtual Task CommitTransactionAsync(CommitTransactionOptions options, CancellationToken cancellationToken = default(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.
should be cancellationToken = default
for consistency
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.
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.
Why doesn't abortTransaction also override its createCommand method?
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.
Simply because base class is doing everything what it needs.
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 also need to a With()
overload that takes the timeout parameter?
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.
We might, but not sure if we want to keep this With pattern. We might want to add it for consistency. @BorisDog WDYT?
internal sealed class AbortTransactionOptions | ||
{ | ||
public AbortTransactionOptions() | ||
{} |
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 a new line for this?
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 suppose we do not need the parameter less constructor at all here. Thank you for bringing attention to this.
internal sealed class CommitTransactionOptions | ||
{ | ||
public CommitTransactionOptions() | ||
{} |
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.
same no need for a new line?
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 suppose we do not need the parameter less constructor at all here. Thank you for bringing attention to this.
No description provided.