处理跨数据库服务器的事务
我有一个场景,其中工作单元定义为:
Update table T1 in database server S1
Update table T2 in database server S2
并且我希望上述工作单元完全发生或根本不发生(与任何数据库事务的情况一样)。我该怎么做?我广泛搜索并发现了这个 帖子接近我的预期,但这似乎是针对 Hibernate 的。
我使用 Spring、iBatis 和 Tomcat (6.x) 作为容器。
I have a scenario where the unit of work is defined as:
Update table T1 in database server S1
Update table T2 in database server S2
And I want the above unit of work to happen either completely or none at all (as the case with any database transaction). How can I do this? I searched extensively and found this post close to what I am expecting but this seems to be very specific to Hibernate.
I am using Spring, iBatis and Tomcat (6.x) as the container.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这实际上取决于您需要的解决方案有多强大。这种事情的最低可靠性级别是 XA 事务。要使用它,您需要一个数据库和支持它的 JDBC 驱动程序,然后您可以配置 Spring 使用它(这里是一个大纲)。
如果 XA 对您来说不够健壮(XA 有故障场景,例如在提交的第二阶段出现问题,例如硬件故障),那么您真正需要做的是将所有数据放入一个数据库中,然后然后有一个单独的过程来传播它。所以数据可能不一致,但是是可以恢复的。
编辑:我的意思是将所有数据放入一个数据库中。要么是第一个数据库,要么是用于此目的的不同数据库。该数据库本质上将成为一个队列,从中提供最终数据视图。对该数据库的写入(假设是一个不错的数据库产品)将完成,或者完全失败。然后,一个单独的线程将轮询该数据库并将任何丢失的数据分发到其他数据库。因此,如果该过程失败,当该线程再次启动时,它将继续分发过程。数据可能不会立即存在于您想要的每个位置,但不会丢失任何内容。
It really depends on how robust a solution you need. The minimal level of reliability on such a thing is XA transactions. To use that, you need a database and JDBC driver that supports it for starters, then you could configure Spring to use it (here is an outline).
If XA isn't robust enough for you (XA has failure scenarios, such as if something goes wrong in the second phase of commits, such as a hardware failure) then what you really need to do is put all the data in one database and then have a separate process propagate it. So the data may be inconsistent, but it is recoverable.
Edit: What I mean is that put the whole of the data into one database. Either the first database, or a different database for this purpose. This database would essentially become a queue from which the final data view is fed. The write to that database (assuming a decent database product) will be complete, or fail completely. Then, a separate thread would poll that database and distribute any missing data to the other databases. So if the process should fail, when that thread starts up again it will continue the distribution process. The data may not exist in every place you want it to right away, but nothing would get lost.
您需要一个分布式事务管理器。我喜欢使用可以在 JVM 中运行的 Atomikos 。
You want a distributed transaction manager. I like using Atomikos which can be run within a JVM.