分布式事务如何工作(例如MSDTC)? [英] How do distributed transactions work (eg. MSDTC)?

查看:123
本文介绍了分布式事务如何工作(例如MSDTC)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以一种模糊的方式理解了常规ACID交易的工作方式。您对数据库执行某些工作的方式是直到设置了某种提交标志才确认工作。提交部分基于一些基本假设(例如,单个磁盘块的写入是原子的)。万一发生灾难性错误,您只需在恢复阶段清除未提交的数据即可。

I understand, in a fuzzy sort of way, how regular ACID transactions work. You perform some work on a database in such a way that the work is not confirmed until some kind of commit flag is set. The commit part is based on some underlying assumption (like a single disk block write is atomic). In the event of a catastrophic error, you can just clear out the uncommitted data in the recovery phase.

分布式事务如何工作?在某些MS文档中,我读到您可以通过某种方式跨数据库和文件系统执行事务(除其他外)。

How do distributed transactions work? In some of the MS documentation I have read that you can somehow perform a transaction across databases and filesystems (among other things).

该技术可能是(也许是)用于安装程序,您要在该安装程序中完全安装或完全不安装该程序。您只需在安装程序启动时开始事务。接下来,您可以连接到注册表和文件系统,进行定义安装的更改。完成工作后,只需提交即可;如果由于某种原因安装失败,则回滚。这个神奇的分布式事务处理协调器会自动为您清理注册表和文件系统。

This technology could be (and probably is) used for installers, where you want the program to be fully installed or fully absent. You simply begin a transaction at the start of the installer. Next you could connect to the registry and filesystem, making the changes that define the installation. When the job is done, simply commit, or rollback if the installation fails for some reason. The registry and filesystem are automatically cleaned for you by this magical distributed transaction coordinator.

怎么可能以这种方式处理两个不同的系统?在我看来,总是有可能使系统处于不一致状态,在该状态下文件系统已提交其更改而注册表没有。我认为在MSDTC中甚至可以通过网络执行事务。

How is it possible that two disparate systems can be transacted upon in this fashion? It seems to me that it is always possible to leave the system in an inconsistent state, where the filesystem has committed its changes and the registry has not. I think in MSDTC it is even possible to perform a transaction across the network.

我已阅读 http://blogs.msdn.com/florinlazar/archive/2004/03/04/84199.aspx ,但感觉就像只是解释的开始一样,第4步应该大大扩展。

I have read http://blogs.msdn.com/florinlazar/archive/2004/03/04/84199.aspx, but it feels like only the beginning of the explanation, and that step 4 should be expanded considerably.

编辑:根据我在 http://en.wikipedia.org/wiki/Distributed_transaction ,它可以通过两阶段提交来实现( http://en.wikipedia.org/wiki/Two-phase_commit )。读完这篇文章后,我仍然对100%的方法不甚了解,步骤之间似乎有很多错误的余地。

From what I gather on http://en.wikipedia.org/wiki/Distributed_transaction, it can be accomplished by a two-phase commit (http://en.wikipedia.org/wiki/Two-phase_commit). After reading this, I'm still not understanding the method 100%, it seems like there is a lot of room for error between the steps.

推荐答案

关于步骤4:


事务管理器与资源管理器协调
以确保
所有人都成功完成了所要求的
工作,或者没有完成任何工作,因此
保持了ACID属性。

The transaction manager coordinates with the resource managers to ensure that all succeed to do the requested work or none of the work if done, thus maintaining the ACID properties.

这当然要求所有参与者提供适当的接口和(无错误的)实现。接口看起来像这样模糊:

This of course requires all participants to provide the proper interfaces and (error-free) implementations. The interface looks like vaguely this:

public interface ITransactionParticipant {
    bool WouldCommitWork();
    void Commit();
    void Rollback();
}

在提交时,事务管理器查询所有参与者是否愿意提交交易。如果参与者能够在所有允许的错误条件(验证,系统错误等)下提交此事务,则仅可以声明此声明。在所有参与者都声明了提交事务的能力之后,管理器将 Commit()消息发送给所有参与者。如果任何参与者提出错误或超时,则整个事务将中止,并且单个成员将回滚。

The Transaction manager at commit-time queries all participants whether they are willing to commit the transaction. The participants may only assert this if they are able to commit this transaction under all allowable error conditions (validation, system errors, etc). After all participants have asserted the ability to commit the transaction, the manager sends the Commit() message to all participants. If any participant instead raises an error or times out, the whole transaction aborts and individual members are rolled back.

此协议要求参与者在断言之前记录其全部交易内容他们的承诺能力。当然,这必须采用特殊的本地事务日志结构,以便能够从各种故障中恢复。

This protocol requires participants to have recorded their whole transaction content before asserting their ability to commit. Of course this has to be in a special local transaction log structure to be able to recover from various kinds of failures.

这篇关于分布式事务如何工作(例如MSDTC)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆