-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add TransactionManager.ImplicitDistributedTransactions
#76469
Comments
Tagging subscribers to this area: @roji, @ajcvickers Issue DetailsBackground and motivationTaken from #76376: This adds a static, global The reasoning here, as advocated by @ajcvickers, is that back in .NET Framework many users were unintentionally causing escalation to a distributed transaction through improper use of Re the flag itself, /cc @roji @ajcvickers API Proposalnamespace System.Transactions;
public partial class TransactionManager
{
public static bool ImplicitDistributedTransactions { get; set; }
} API Usagestatic void Main(string[] args)
{
//...
// Early on, the app is configured to enlist transactions into DTC:
TransactionManager.ImplicitDistributedTransactions = true;
//...
} Alternative DesignsNo response RisksNo response
|
TransactionManager.ImplicitDistributedTransactions
My understanding is that DTC is Windows-only tech. Should the property be marked as Assuming the flag is not initialized I assume the default is false. Is there a way to say for a specific transaction that it should be enlisted into the DTC without setting this global flag? |
Tagging subscribers to this area: @roji Issue DetailsBackground and motivationTaken from #76376: This adds a static, global The reasoning here, as advocated by @ajcvickers, is that back in .NET Framework many users were unintentionally causing escalation to a distributed transaction through improper use of Re the flag itself, /cc @roji @ajcvickers API Proposalnamespace System.Transactions;
public partial class TransactionManager
{
public static bool ImplicitDistributedTransactions { get; set; }
} API Usagestatic void Main(string[] args)
{
//...
// Early on, the app is configured to enlist transactions into DTC:
TransactionManager.ImplicitDistributedTransactions = true;
//...
}
|
@terrajobst thanks for creating the issue. Yeah, the flag is a no op on non-Windows platforms (see here), and yeah, its default is false (uninitialized). Re using the flag on non-Windows platforms, that may be important as cross-platform applications may always set the flag to true (to enable distributed transactions on Windows), but then refrain from actually using them when running on non-Windows (not allowing the flag to be set on non-Windows would create a bit of friction there). I'm not sure what
Unfortunately not... System.Transactions was designed very intentionally to not have an explicit gesture/API for starting a distributed transaction; that's the reason many people unintentionally found themselves starting one, and why we're introducing the flag now. It's theoretically possible to add a flag to TransactionScope/CommittableTransaction, but it's quite a larger effort to flow that down etc. The main goal here is to avoid the accidental usage of distributed transactions in applications which never use them, rather than to fix the System.Transactions design issue (with a per-transaction opt-in), so a simple global flag seems sufficient... Note that in any future, cross-platform distributed transaction API (#71769), the plan would be to make the API very explicit/opt-in to avoid this design issue. So the flag being discussed now wouldn't affect that scenario (and that's why it has "Implicit" in the name). |
Sort of. Since .NET 5, we have an analyzer that warns when you use a platform-specific API outside of a platform-specific context. That context can either be an if check or marking the calling code with the same attribute (hence forwarding the platform constraint to the caller). The intention of this analyzer is to raise awareness of APIs that might not work at runtime, by, for example, throwing // Early on, the app is configured to enlist transactions into DTC:
if (OperatingSystem.IsWindows())
{
TransactionManager.ImplicitDistributedTransactions = true;
} The analyzer won't warn in this case and the caller doesn't need to use
I see. That is unfortunate in that we only have a "big hammer": either everything is enlisted into the DTC or nothing is. Given that the design of |
Re
Just a correction on this - turning on ImplicitDistributedTransactions doesn't mean that everything is always enlisted in to the DTC. It just means that this will happen if needed, e.g. if the user attempts to enlist two database connections into the same TransactionScope. If only a single (promotable) connection is used with TransactionScope, a distributed transaction doesn't get created regardless of the flag (that's already the case today before my changes in 7.0). So the flag is basically about enabling the creation of distributed transactions for the cases where they're required. |
So should we apply |
Sure, makes sense to me. |
Updated |
@terrajobst small note: we can put the (I pushed this into the PR in #76376) |
If this is for 7.0.0, should it be marked as blocking? |
namespace System.Transactions;
public partial class TransactionManager
{
public static bool ImplicitDistributedTransactions { get; [SupportedOSPlatform("windows")] set; }
} |
Closes dotnet#76469 (cherry picked from commit 2070def)
Background and motivation
Taken from #76376:
This adds a static, global
TransactionManager.ImplicitDistributedTransactions
flag, which must be explicitly turned on in order for distributed transactions to be supported.The reasoning here, as advocated by @ajcvickers, is that back in .NET Framework many users were unintentionally causing escalation to a distributed transaction through improper use of
TransactionScope
, etc. This flag protects users interested in usingTransactionScope
but who do not want distributed transactions; this is important as distributed transactions shouldn't be used lightly and without careful consideration (dependency on MSDTC - an external component, considerable perf impact, portability to non-Windows platforms...).Re the flag itself,
TransactionManager
already has global settings managing transactions. Re the nameImplicitDistributedTransactions
, there's a possibility we'd introduce cross-platform distributed transactions intoSystem.Transactions
(#71769); if that happens, users will very explicitly create distributed transactions, and would not need to set this flag (hence "Implicit")./cc @roji @ajcvickers
API Proposal
API Usage
The text was updated successfully, but these errors were encountered: