两阶段提交协议的 ACID 是多少? [英] How ACID is the two-phase commit protocol?

查看:23
本文介绍了两阶段提交协议的 ACID 是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一种情况,我开始怀疑两阶段提交协议是否真的能保证 ACID 属性,尤其是其中的A"部分.

I came across a situation where I started doubting whether the two-phase commit protocol really guarantees the ACID properties, especially the 'A' part of it.

让我们看一个涉及 2 个资源的理论分布式事务.(关于我不得不处理的问题的更实际描述,您可以在 我的博客).该场景是分布式事务的正常执行(无故障或恢复).应用程序启动事务,更新资源并发出 commit() 调用.提交完成后,应用程序检查两个资源并查看已完成事务的所有更改.一切都很好,2PC 协议完成了它的工作,对吗?

Let's look at a theoretical distributed transaction involving 2 resources. (More practical description of the problem I had to deal with you can find in my blog). The scenario is a normal execution of a distributed transaction (no failures or recovery). An application starts a transaction, updates both resources and issues a commit() call. After commit is completed the application checks both resources and sees all the changes from the completed transaction. Everything is fine, the 2PC protocol did its job, right?

现在,场景略有变化.当分布式事务执行 commit() 时,另一个应用程序将访问相同的 2 个资源.它是否只能看到交易中的部分更改?假设对一个资源的更改已经可见,而对第二个资源的更改尚不可见?

Now, a small change to the scenario. While the distributed transaction is doing commit(), another application is going to the same 2 resources. Can it see only part of the changes from the transaction? Let's say, changes to one resource are already visible while the changes to the second resource are not yet visible?

在我阅读的关于 2PC 协议的所有信息中,我找不到任何关于各个资源相对于彼此的变化的可见性的保证.而且我找不到任何说明所有资源都在完全相同的时间完成各自提交的内容.

In all the information I have read on the 2PC protocol I could not find any guarantees about the visibility of the changes in the individual resources relative to each other. And I could not find anything that says that all the resources finish their individual commits at exactly the same time.

推荐答案

我认为你在混淆话题.2PC 确保事务以一定的可见性提交.IE.在您的事务中,您提交的数据将以特定方式排序,并且与该事务一起提交的数据将按顺序提交.

I think you are confusing topics. 2PC ensures that transactions commit with a certain visibility. I.e. in your transaction the data you commit will be ordered in a specific way and commits with that transactions will commit serially.

在您的事务之外,您看到的行为将取决于锁定在您的数据库中的工作方式.通常,您会期望只读查询会看到事务之前的状态或事务之后的状态(除非使用相同的锁定语义,否则不能保证其接收到的状态).写入语义通常会导致锁定事务中的所有项目,但这同样取决于您的数据库的配置方式.

Outside of your transaction the behaviour you see will depend on how locking works in your database. Typically you would expect that a read-only query would either see the before transaction state or the after transaction state (with no guarantee per-se as to which it receives unless it is using the same locking semantics). Write semantics would typically result in locking all items in the transaction, but again this really depends on how your database is configured.

2PC 实际上只承诺操作是原子的,即使如此,它也只是在该事务范围内必须是原子的,具体取决于您的数据库的配置方式.

2PC really only promises that an operation is Atomic, and even then it is only necessarily atomic within the scope of that transaction depending on how your database is configured.

这篇关于两阶段提交协议的 ACID 是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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