.NET:由于事务超时而异步回滚

发布于 2024-07-12 01:45:38 字数 376 浏览 7 评论 0原文

在 C# 项目中,我在 System.Transactions.Transaction 中登记了一个(易失性)事务资源。
当事务超时时,回滚是在工作线程中执行的:显然,事务使用计时器,并在计时器到时调用计时器回调(Microsoft关于这个问题的文档很少) 。 因此,我的事务资源中的 IEnlistmentNotification.Rollback(...) 的实现是异步调用的。

我的问题是:我该如何处理这个问题? 当然,回滚代码会更改我的资源的内部状态,例如通过丢弃更改。 看来我必须同步对该资源的所有访问。 然而,该资源并不是被设计为线程保存的。 有没有人有解决这个问题的经验,或者是否有某种“最佳实践”?

In a C# project, I have a (volatile) transactional resource enlisted in a System.Transactions.Transaction.
When a transaction timeout occurs, the rollback is executed in a worker thread: Obviously, the transaction uses a timer and calls a timer callback when the timer elapses (there is very little documentation from Microsoft on this issue). Thus, the implementation of IEnlistmentNotification.Rollback(...) in my transactional resource is called asynchronously.

My question is: How do I handle this? Of course, the rollback code changes the internal state of my resource, e.g. by discarding changes. It seems that I must synchronize all access to this resource. However, the resource is not designed to be thread save. Does anyone have experience with this problem, or is there some kind of "best practice" for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-07-19 01:45:38

我想你可以锁定资源的回滚方法以使它们同步,因为回滚将是奇怪的情况并且序列化访问不会导致太多性能问题...

使用 IoC,例如 Windsor,实现 IInterceptor并使用拦截器锁定所有 IResource.Rollback() 方法。 这是一个正交问题,因此应该作为一个整体来实现。

I guess you could lock the resources' rollback methods to make them synchronized, as the rollback would be the odd-case-out and serializing access wouldn't cause too much problem perf-wise...

With IoC, e.g. Windsor, implement IInterceptor and lock around all IResource.Rollback() methods with the interceptor. It's an orthogonal concern, so it should be implemented as one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文