澄清复合操作的非原子性

Clarification of non-atomicity of compound operations

This guide page 强调复合操作是 "not atomic" 和 "not transactions",但此处给出的示例以及下面复制的示例似乎并未证明它们不是事务。如果 Bob 的编辑先到达,则显示的最终结果与顺序一致:

问题是 Bob 的前两个编辑 没有实际应用 ,因此,例如,如果我们撤消 Alice 的编辑,我们最终会得到这个吗? :

{
  'address' : 'Anytown, USA' // Bob's address!
}

我引用的指南部分如下。


Although edits made in a compound operation are delivered together, they are not atomic. It is possible that, because of conflict resolution, some edits in a compound operation are never delivered. Imagine a collaboration scenario where two editors modify the same collaborative map at the same time. Alice runs this code:

model.beginCompoundOperation();
myCollaborativeMap.set('name', 'Alice');
myCollaborativeMap.set('phone', '555-5309');
model.endCompoundOperation();`

And Bob runs this code:

model.beginCompoundOperation();
myCollaborativeMap.set('name', 'Bob');
myCollaborativeMap.set('phone', '555-0000');
myCollaborativeMap.set('address', 'Anytown, USA');
model.endCompoundOperation();

If Bob's edits arrive at the server first, the map contents will ultimately resolve to:

{
  'name' : 'Alice',          // Alice's name
  'phone' : '555-5309',      // Alice's number
  'address' : 'Anytown, USA' // Bob's address!
}

If Alice's edits arrive at the server first, the map contents will be:

{
  'name' : 'Bob',            // Bob's name
  'phone' : '555-0000',      // Bob's number
  'address' : 'Anytown, USA' // Bob's address
}

Bob 的编辑实际上已应用,因此如果您撤消 Alice 的更改,那么结果应该是 Bob 的更改。

但是,它仍然不是传统数据库 ACID 意义上的事务性。所做的唯一保证是复合操作中的更改将一起应用,而不会混合其他更改。

例如,在典型的 sql 数据库事务中,如果在应用更改时出现问题,所有更改都会回滚。

在复合操作中,其中的每个更改都被单独转换和应用。有可能由于文档中的冲突更改,其中一个更改最终被取消(例如,它试图更改的字符串的一部分已被删除。)在这种情况下,该部分更改似乎不会得到应用,但复合操作中的所有其他更改仍会发生。