在 CouchDB 中处理冲突

Handling conflicts in CouchDB

假设我有一个具有两个属性的文档,"Start" 和 "End." 一个修订版可能有一个开始时间和结束时间,反之亦然。我不想选择单个修订版作为获胜者,而是希望最终文档包含修订版的开始时间,它不为空,结束时间也相同。

在同步期间是否有处理此类冲突解决方案的最佳做法?我找到的文档包含有关选择单个修订作为获胜者的说明,但我想 select 来自多个修订的值。

特定于 C#/MyCouch 库的示例会很棒,但也非常感谢任何通用或其他语言建议。

在 复制(a.k.a.sync)期间,不能指定自定义的冲突解决方式。 CouchDB 会自动选择获胜的修订版本,您无法影响它:

By default, CouchDB picks one arbitrary revision as the "winner", using a deterministic algorithm so that the same choice will be made on all peers.

您可以等待复制完成,然后通过执行特定于应用程序的文档修订合并来处理冲突。

查看 Working with conflicting documents 的文档,我发现了以下伪代码示例:

  1. GET docid?conflicts=true
  2. For each member in the _conflicts array: GET docid?rev=xxx If any errors occur at this stage, restart from step 1. (There could be a race where someone else has already resolved this conflict and deleted that rev)
  3. Perform application-specific merging
  4. Write _bulk_docs with an update to the first rev and deletes of the other revs.