分布式事务如何工作(例如 MSDTC)?
我以一种模糊的方式理解常规 ACID 事务是如何工作的。 您在数据库上执行某些工作时,直到设置某种提交标志后才会确认该工作。 提交部分基于一些基本假设(例如单个磁盘块写入是原子的)。 如果发生灾难性错误,您可以在恢复阶段清除未提交的数据。
分布式事务如何运作? 在一些 MS 文档中,我读到您可以以某种方式跨数据库和文件系统(除其他外)执行事务。
该技术可以(并且可能是)用于安装程序,您希望程序完全安装或完全不存在。 您只需在安装程序启动时开始一个事务即可。 接下来,您可以连接到注册表和文件系统,进行定义安装的更改。 作业完成后,只需提交即可,如果安装因某种原因失败则回滚。 这个神奇的分布式事务协调器会自动为您清理注册表和文件系统。
两个不同的系统怎么可能以这种方式进行交易? 在我看来,总是有可能使系统处于不一致的状态,即文件系统已提交更改而注册表尚未提交。 我认为在 MSDTC 中甚至可以通过网络执行交易。
我已阅读 http://blogs.msdn.com/florinlazar/ archive/2004/03/04/84199.aspx,但感觉这只是解释的开始,第4步应该大大扩展。
编辑:根据我在http://en.wikipedia.org/wiki上收集的信息/Distributed_transaction,它可以通过两阶段提交来完成(http://en .wikipedia.org/wiki/Two-phase_commit)。 读完本文后,我仍然没有 100% 理解该方法,似乎步骤之间存在很大的错误空间。
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.
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.
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.
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.
Edit: 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于“第4步”:
这当然要求所有参与者提供正确的接口和(无错误)实现。 界面看起来大概是这样的:
事务管理器在提交时询问所有参与者是否愿意提交事务。 仅当参与者能够在所有允许的错误条件(验证、系统错误等)下提交此事务时,参与者才可以断言这一点。 当所有参与者都断言能够提交事务后,管理器将
Commit()
消息发送给所有参与者。 如果任何参与者提出错误或超时,则整个事务将中止并且单个成员将回滚。该协议要求参与者在断言其提交能力之前记录其整个交易内容。 当然,这必须位于特殊的本地事务日志结构中,以便能够从各种故障中恢复。
About "step 4":
This of course requires all participants to provide the proper interfaces and (error-free) implementations. The interface looks like vaguely this:
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.