-
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* Copyright 2010-present MongoDB Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using MongoDB.Driver.Core.Misc; | ||
|
||
namespace MongoDB.Driver | ||
{ | ||
// TODO: CSOT: Make it public when CSOT will be ready for GA | ||
internal sealed class AbortTransactionOptions | ||
{ | ||
public AbortTransactionOptions(TimeSpan? timeout) | ||
{ | ||
Timeout = Ensure.IsNullOrValidTimeout(timeout, nameof(timeout)); | ||
} | ||
|
||
public TimeSpan? Timeout { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* Copyright 2010-present MongoDB Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using MongoDB.Driver.Core.Misc; | ||
|
||
namespace MongoDB.Driver | ||
{ | ||
// TODO: CSOT: Make it public when CSOT will be ready for GA | ||
internal sealed class CommitTransactionOptions | ||
{ | ||
public CommitTransactionOptions(TimeSpan? timeout) | ||
{ | ||
Timeout = Ensure.IsNullOrValidTimeout(timeout, nameof(timeout)); | ||
} | ||
|
||
public TimeSpan? Timeout { get; } | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* Copyright 2010-present MongoDB Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace MongoDB.Driver.Core.Bindings | ||
{ | ||
// TODO: CSOT: Make it public when CSOT will be ready for GA | ||
internal static class ICoreSessionExtensions | ||
{ | ||
// TODO: Merge these extension methods in ICoreSession interface on major release | ||
public static void AbortTransaction(this ICoreSession session, AbortTransactionOptions options, CancellationToken cancellationToken = default) | ||
{ | ||
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 commentThe 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 commentThe 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. |
||
return; | ||
} | ||
|
||
((ICoreSessionInternal)session).AbortTransaction(options, cancellationToken); | ||
} | ||
|
||
public static Task AbortTransactionAsync(this ICoreSession session, AbortTransactionOptions options, CancellationToken cancellationToken = default) | ||
{ | ||
if (options == null || session.Options.DefaultTransactionOptions?.Timeout == options.Timeout) | ||
{ | ||
return session.AbortTransactionAsync(cancellationToken); | ||
} | ||
|
||
return ((ICoreSessionInternal)session).AbortTransactionAsync(options, cancellationToken); | ||
} | ||
|
||
public static void CommitTransaction(this ICoreSession session, CommitTransactionOptions options, CancellationToken cancellationToken = default) | ||
{ | ||
if (options == null || session.Options.DefaultTransactionOptions?.Timeout == options.Timeout) | ||
{ | ||
session.CommitTransaction(cancellationToken); | ||
return; | ||
} | ||
|
||
((ICoreSessionInternal)session).CommitTransaction(options, cancellationToken); | ||
} | ||
|
||
public static Task CommitTransactionAsync(this ICoreSession session, CommitTransactionOptions options, CancellationToken cancellationToken = default) | ||
{ | ||
if (options == null || session.Options.DefaultTransactionOptions?.Timeout == options.Timeout) | ||
{ | ||
return session.CommitTransactionAsync(cancellationToken); | ||
} | ||
|
||
return ((ICoreSessionInternal)session).CommitTransactionAsync(options, cancellationToken); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Copyright 2010-present MongoDB Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace MongoDB.Driver.Core.Bindings; | ||
|
||
// TODO: Merge this interface into ICoreSession on major release | ||
internal interface ICoreSessionInternal | ||
{ | ||
void AbortTransaction(AbortTransactionOptions options, CancellationToken cancellationToken = default); | ||
Task AbortTransactionAsync(AbortTransactionOptions options, CancellationToken cancellationToken = default); | ||
void CommitTransaction(CommitTransactionOptions options, CancellationToken cancellationToken = default); | ||
Task CommitTransactionAsync(CommitTransactionOptions options, CancellationToken cancellationToken = default); | ||
} |
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 toICoreSession
.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
toICoreSessionInternal
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 implementICoreSessionInternal
.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!