强制 MSDTC 孤立 SQLServer 分布式事务

发布于 2024-09-30 12:59:21 字数 439 浏览 6 评论 0原文

当关闭我的项目的基于WebSphere 的JavaEE 应用程序时,分布式事务有时会在SQLServer 2005 数据库中保持活动状态。它们会永远保留它们的锁,并且必须手动杀死。它们在 this very好文章

本文讨论了事务协调器如何无法协调分布式事务参与者,因此将事务标记为进程 ID -2。

鉴于我们很少遇到此问题,但它总是在我们关闭应用程序时发生,因此我不相信这是 MSDTC 的故障。它更可能与 WebSphere 及其终止应用程序的方式有关。

我想测试一下。但我无法可靠地实现它。

有没有办法强制 MSDTC 孤立 SQLServer 分布式事务?

When shutting down my project's WebSphere-based JavaEE application, distributed transactions are sometimes left alive in the SQLServer 2005 database. These retain their locks forever and must be killed manually. They are described generally in this very good article.

The article talks about how the transaction coordinator is unable to co-ordinate the distributed transaction participants and so flags the transaction with a process ID of -2.

Given that we get this issue infrequently, but that it always happens when we shut down the application, I am not convinced it is a failure of the MSDTC. It is more likely to have something to do with WebSphere and how it terminates applications.

I would like to test it. But I cannot reliably make it happen.

Is there any way to force the MSDTC to orphan a SQLServer distributed transaction?

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

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

发布评论

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

评论(2

差↓一点笑了 2024-10-07 12:59:21

我的问题具有误导性,因为我不太确定问题到底是什么。我怀疑 MSDTC 正在协助 WebSphere 与 MQ 和 SQLServer 进行事务处理。当我们对 WAS 服务器执行非正常关闭并且供应商提供的应用程序部分尝试进行某种清理并失败时,就会出现此问题。

我怀疑这个问题对其他人没有帮助(除非他们在 Windows 上的 WebSphere 中使用 Misys 消息管理器),所以很抱歉,亲爱的读者,浪费了您的时间。

My question was misleading, because I wasn't quite sure what the problem actually was. I suspect MSDTC is assisting WebSphere in transacting with MQ and SQLServer. The problem occurs when we perform an unclean shutdown of the WAS server and the vendor-provided part of our application tries to do some sort of cleanup and fails.

I suspect this question is not helpful to anyone else (unless they are using the Misys Message Manager in WebSphere on Windows) so apologies, dear reader, for wasting your time.

七度光 2024-10-07 12:59:21

如果具有打开但尚未准备好的 DTC 或 XA 事务的 SQLServer 会话关闭,则可能会出现孤立的 DTC 事务。这可能是由于网络中断或应用程序意外中止而发生的。
在这种情况下,SQLServer 保留带有 DTC 的事务,并且 SPID 为 -2。
关于 SQLServerCentral 的帖子提到以下查询可用于识别孤立事务:

Select req_transactionUOW
 from master..syslockinfo
 where req_spid = -2

使用给定的 UOW 作为参数执行“kill”,将删除活动交易。

SQLSever 的这种行为非常罕见。通常,会话丢失将中止任何 XA 事务。

好消息是 SQLServer 提供了一个选项来更改此行为。
可以设置跟踪标志3924以实现此目的。只需使用“sa”权限执行 DBCC TRACEON(3924,-1),SQLServer 就会自动删除事务,以防会话丢失。

SQLServer 重新启动时跟踪标志将丢失。为了在 SQLServer 启动期间自动将其设置到 SQLServer 配置管理器中:

SQLServer 配置管理器 sceenshot

Orphaned DTC transactions can occur in case SQLServer sessions with open but not yet prepared DTC or XA transactions are closed. This may happen because of network interruption or due to unexpected application abort.
In this case SQLServer keeps the transaction with DTC and the SPID is -2.
The post on SQLServerCentral mentions that following query can be used to identify the orphaned transactions:

Select req_transactionUOW
 from master..syslockinfo
 where req_spid = -2

Exeuting "kill" with the UOW given as argument, will remove the active ransaction.

This behavior of SQLSever is very uncommon. Usually a session loss will abort any XA transaction.

The good news is that SQLServer provides an option that changes this behavior.
The trace flag 3924 can be set in order to achieve this. Just exec DBCC TRACEON(3924,-1) with "sa" privileges and SQLServer automatically removes transactions in case sessions get lost.

The trace flag will be lost on SQLServer restart. In order to get it set during SQLServer startup automatically add it in SQLServer configuration manager:

SQLServer Configuration Manager sceenshot

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