0

参考这篇关于使用 MongoDB 执行两阶段提交的文章:

交易“初始”状态的目的是什么?为什么不直接插入具有“待处理”状态的事务文档并保存到数据库的往返行程?

4

2 回答 2

0

There is actually a good reason for the initial state: The 2PC protocol defines a state machine with an 'initial' state, which transitions to 'pending'. The transaction should only be in 'pending' state once all participants are in pending state. In addition the transition to 'commit' should only be started when the transaction is in 'pending' state. Finally the transaction should only be marked as 'committed' once all participants have successfully committed.

If you started the transition to commit without fully reaching the pending state, you risk breaking the atomicity and isolation guarantees.

In the article referenced the transaction state is changed to pending before setting the participants to pending (inserting the records). The transaction state is set to committed before committing the participants. And there is an extra state called 'done', this might lead to bugs in the coordinator implementation. I suggest you take the article with a grain of salt.

于 2013-09-19T05:30:48.867 回答
0

如果有多个应用程序在运行同一个事务,如本文后面所述,“初始”状态基本上意味着逻辑锁是空闲的,因此 findAndModify() 可以更新文档以获取该锁。因此,只允许一个应用程序运行该事务。

于 2013-09-18T19:12:43.190 回答