You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fully fix ambient and distributed transactions #122
Hi @roji,
Do you have some kind of design doc about the redesign of this ?
I'll be in need of the distributed transaction support in this version of the driver very soon.
If you need some help this would be a pleasure.
@omatrot, there's no design doc or anything. It's one of the major goals of 3.2, but unfortunately I'm not going to be able to work on this in the near future - there's work on EF Core, other Npgsql features and real life as well.
Note that current versions of Npgsql do support distributed transactions, it's just that there are some issues with it. It's definitely worth trying to work with the latest 3.1, this way you can also report issues you come across for 3.2.
@omatrot thanks! There's still a few more things on my plate but I expect to start working on this in the next few weeks. Thanks for being so patient...
@roji No problem. There are some corner cases that can't be resolved in the actual implementation. I think that, ideally, the Resource Manager should be hosted in an external process (A Windows Service on windows at a minimum) to become truly durable. This will also allow it to monitor prepared transaction at the database level for instance. Despite all my efforts so far, when a process crash occurs, because of an external library for instance, in the tiny time frame between PREPARE and COMMIT PREPARED or ROLLBACK PREPARED, you end up with an orphaned prepared transaction that should be rolled back ASAP.
So far I've written a little utility to do this garbage collector "dirty" work. It is launched by a Windows scheduled task every 2 minutes. This is acceptable in my context, and is still helping a lot.
That's why I've been asking about a design doc ;-)
I'll dive into everything soon. There's no design doc, but we're here to decide where to take npgsql with regards to distributed transactions. I think there was a consensus at some point that to implement the resource manager in a separate app domain doesn't really make much sense, but I still have to fully understand what durable vs. non-durable means here.
@amirtuval always rolling back the prepared transaction is ok in some of my contexts because Npgsql is the only resource manager involved in the transaction.
@omatrot Sure, so in your use case it is fine, but I think it cannot be a general strategy for Npgsql, because in other use cases it is simply not acceptable.
I think the ideal situation here is a pluggable mechanism, allowing users would be able to implement their own behavior (such as @amirtuval's in-process recovery), or opt-out entirely of any recovery within Npgsql (e.g. by having a cron job that automatically rolls back PostgreSQL prepared transactions periodically). In the latter case the enlistment would be volatile. It would also be ideal if PostgreSQL could come built-in with a "proper", out-of-process recovery agent similar to ODP.NET.
Everyone, I've pushed my code as PR #1380. It implements most of what's been raised, except for recovery which is currently out of scope. It's a full rewrite, so I expect there will be some problems (although the test suite is more extensive than before). I'd really appreciate reviews if you can spare the time.
Since designing and implementing a full-fledged, durable, out-of-process solution isn't a trivial task, I don't really want to hold up 3.2 because of it. We can always add this later, and this will be an opt-in feature that doesn't impact anyone who doesn't use distributed transactions we can probably even do it before the next big release.
On the other hand, I'd like to provide people with an API to register their own recovery mechanism, e.g. to support cases like @amirtuval's without forcing them to fork. I've taken a quick look, and unfortunately right now things interact too tightly with Npgsql internals. For example, it has to deal with the case of the user closing a connection before its TransactionScope has completed; this requires interaction with the connector and the pool, which are internal elements. So I see this happening in the future, but again, I don't want to hold up 3.2 on this. Of course, everyone is free to fork and do what they want.
So I propose we release Npgsql 3.2 with a built-in volatile resource manager. That would be similar to what previous versions of Npgsql - there wasn't any recovery so there's no regression - but with much simpler code and hopefully with many of the bugs gone.
Let me know what you think of this plan. For those of you expecting more from 3.2, I'm sorry... We at least now have a much better base to build upon.
@domagojmedo distributed transaction support is currently missing in .NET (CorE) itself - I am currently working on bringing that support over from .NET Framework, for Windows only - see dotnet/runtime#715. Once that's done, it should be possible to use distributed transactions with Npgsql and PostgreSQL, on Windows (future cross-platform support is tracked by dotnet/runtime#71769).
I've opened #4581 to track testing this for .NET 7.0.
Activity
omatrot commentedon Jul 13, 2016
Hi @roji,
Do you have some kind of design doc about the redesign of this ?
I'll be in need of the distributed transaction support in this version of the driver very soon.
If you need some help this would be a pleasure.
roji commentedon Jul 13, 2016
@omatrot, there's no design doc or anything. It's one of the major goals of 3.2, but unfortunately I'm not going to be able to work on this in the near future - there's work on EF Core, other Npgsql features and real life as well.
Note that current versions of Npgsql do support distributed transactions, it's just that there are some issues with it. It's definitely worth trying to work with the latest 3.1, this way you can also report issues you come across for 3.2.
omatrot commentedon Aug 4, 2016
@roji
Here we go, I've made a pull request that is following the previous one. It targets the latest 3.1.
roji commentedon Aug 4, 2016
@omatrot thanks! There's still a few more things on my plate but I expect to start working on this in the next few weeks. Thanks for being so patient...
omatrot commentedon Aug 5, 2016
@roji No problem. There are some corner cases that can't be resolved in the actual implementation. I think that, ideally, the Resource Manager should be hosted in an external process (A Windows Service on windows at a minimum) to become truly durable. This will also allow it to monitor prepared transaction at the database level for instance. Despite all my efforts so far, when a process crash occurs, because of an external library for instance, in the tiny time frame between PREPARE and COMMIT PREPARED or ROLLBACK PREPARED, you end up with an orphaned prepared transaction that should be rolled back ASAP.
So far I've written a little utility to do this garbage collector "dirty" work. It is launched by a Windows scheduled task every 2 minutes. This is acceptable in my context, and is still helping a lot.
That's why I've been asking about a design doc ;-)
roji commentedon Aug 5, 2016
I'll dive into everything soon. There's no design doc, but we're here to decide where to take npgsql with regards to distributed transactions. I think there was a consensus at some point that to implement the resource manager in a separate app domain doesn't really make much sense, but I still have to fully understand what durable vs. non-durable means here.
29 remaining items
omatrot commentedon Dec 11, 2016
@amirtuval always rolling back the prepared transaction is ok in some of my contexts because Npgsql is the only resource manager involved in the transaction.
amirtuval commentedon Dec 11, 2016
@omatrot Sure, so in your use case it is fine, but I think it cannot be a general strategy for Npgsql, because in other use cases it is simply not acceptable.
omatrot commentedon Dec 11, 2016
@amirtuval I may not have been very clear about this and I'm sorry. I was not suggesting to implement this at the driver level.
roji commentedon Dec 11, 2016
I think the ideal situation here is a pluggable mechanism, allowing users would be able to implement their own behavior (such as @amirtuval's in-process recovery), or opt-out entirely of any recovery within Npgsql (e.g. by having a cron job that automatically rolls back PostgreSQL prepared transactions periodically). In the latter case the enlistment would be volatile. It would also be ideal if PostgreSQL could come built-in with a "proper", out-of-process recovery agent similar to ODP.NET.
Rewrite of Systems.Transactions support
roji commentedon Dec 11, 2016
Everyone, I've pushed my code as PR #1380. It implements most of what's been raised, except for recovery which is currently out of scope. It's a full rewrite, so I expect there will be some problems (although the test suite is more extensive than before). I'd really appreciate reviews if you can spare the time.
roji commentedon Dec 12, 2016
Everyone, just a few notes on how I see things...
Since designing and implementing a full-fledged, durable, out-of-process solution isn't a trivial task, I don't really want to hold up 3.2 because of it. We can always add this later, and this will be an opt-in feature that doesn't impact anyone who doesn't use distributed transactions we can probably even do it before the next big release.
On the other hand, I'd like to provide people with an API to register their own recovery mechanism, e.g. to support cases like @amirtuval's without forcing them to fork. I've taken a quick look, and unfortunately right now things interact too tightly with Npgsql internals. For example, it has to deal with the case of the user closing a connection before its TransactionScope has completed; this requires interaction with the connector and the pool, which are internal elements. So I see this happening in the future, but again, I don't want to hold up 3.2 on this. Of course, everyone is free to fork and do what they want.
So I propose we release Npgsql 3.2 with a built-in volatile resource manager. That would be similar to what previous versions of Npgsql - there wasn't any recovery so there's no regression - but with much simpler code and hopefully with many of the bugs gone.
Let me know what you think of this plan. For those of you expecting more from 3.2, I'm sorry... We at least now have a much better base to build upon.
omatrot commentedon Dec 12, 2016
@roji I'm fine with this roadmap.
pgrm commentedon Dec 13, 2016
closed after 3 years 🎆 🍾 👍
domagojmedo commentedon Aug 2, 2022
@roji I see that distributed transactions aren't supported in .NET 5 and newer (https://www.npgsql.org/doc/basic-usage.html#systemtransactions-and-distributed-transactions)
Is there a plan to enable them?
roji commentedon Aug 2, 2022
@domagojmedo distributed transaction support is currently missing in .NET (CorE) itself - I am currently working on bringing that support over from .NET Framework, for Windows only - see dotnet/runtime#715. Once that's done, it should be possible to use distributed transactions with Npgsql and PostgreSQL, on Windows (future cross-platform support is tracked by dotnet/runtime#71769).
I've opened #4581 to track testing this for .NET 7.0.