处理CouchDB中的冲突 [英] Handling conflicts in CouchDB

查看:62
本文介绍了处理CouchDB中的冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个带有两个属性的文档,开始"和结束".一个修订版可能有一个开始"时间,结束"为空,反之亦然.我希望最终文档中不要包含从修订版本开始的时间,而不是选择一个修订版本作为开始时间,在该日期中,该时间不为null,对于End则相同.

Say I have a doc with two properties, "Start" and "End." One revision may have a time for Start and null for End, and vice versa. Rather than choosing a single revision as the winner, I want the final doc to contain the Start time from the revision where it is not null, and same for End.

是否存在用于在同步期间处理此类冲突解决方案的最佳实践?我发现的文档包含有关选择单个修订版作为获胜者的说明,但是我想从多个修订版中选择值.

Are there any best practices for handling this type of conflict resolution during a sync? Documentation I have found contains instructions for choosing a single revision as the winner, but I'd like to select values from multiple revs.

特定于C#/MyCouch库的示例会很棒,但是也欢迎任何常规或其他语言建议.

Examples specific to C#/MyCouch library would be great, but any general or other language advice is also much appreciated.

推荐答案

您不能在复制过程中(<同步>)指定自定义冲突解决方法.CouchDB自动选择获胜的版本,您不能影响它:

You cannot specify a custom way of conflict resolution during replication (a.k.a. sync). CouchDB automatically chooses the winning revision, and you cannot influence that:

默认情况下,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.

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

You can wait for the replication to finish and handle conflicts afterwards, by performing application-specific merging of document revisions.

查看处理冲突文档的文档,我发现了以下伪代码示例:

Looking into the documentation for Working with conflicting documents, I found the following pseudocode example:

  1. 获取docid?conflicts = true
  2. 对于_conflicts数组中的每个成员:GET docid?rev = xxx如果在此阶段发生任何错误,请从步骤1重新开始.(可能有一场比赛,其他人已经解决了冲突并删除了该版本)
  3. 执行特定于应用程序的合并
  4. 用_bulk_docs编写第一个版本的更新,并删除其他转速.

这篇关于处理CouchDB中的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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