解决CouchDB中已删除文档的复制冲突 [英] Resolving replication conflicts for deleted documents in CouchDB

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

问题描述

正式文档推荐的解决复制冲突的方法是:


  1. 使用document的 _conflicts
  2. 获取列出的所有修订版本的文档

  3. 执行应用程序特定的合并

  4. 删除不需要的修订版本

问题出现在我要合并文件。它们不会显示在 _conflicts 字段中,而是显示在 _deleted_conflicts 中。如果我仅使用 _conflicts 字段合并,并且文档在本地数据库中删除并在远程副本中编辑,则将在复制时在本地复原。我的应用程序模型假设删除总是在合并时优先:删除的文档保持删除,无论它与什么编辑冲突。



因此,乍一看,最简单的事要做的是检查 _deleted_conflicts 不为空,如果它不为空,删除文档,对不对?嗯...这个问题是,这也可能包含通过解决步骤#4中的编辑冲突引入的删除的修订,所以 _deleted_conflicts 的含义在这个



在CouchDB中处理删除冲突的规范方法(如果有的话),不涉及将标记文档标记为已删除并在应用程序层进行过滤?

解决方案

最好的解决方案是使用reserved属性 _deleted 删除文档而不是 HTTP DELETE 。然后您可以自由设置其他属性:

  doc._deleted = true; 
doc.deletedByUser = true;
doc.save();然后在合并过程中,检查 _deleted_conflicts 的_changes源文件(



< $ c>并删除文档,如果_deleted_conflicts中有 deletedByUser 标志设置为 true 的修订版本。 / p>

我希望这会有帮助!


The way of resolving replication conflicts recommended by official documentation is:

  1. Read conflicting revisions using document's _conflicts field (e.g. via a view)
  2. Fetch docs for all revisions listed
  3. Perform application-specific merging
  4. Remove unwanted revisions

The problem comes in when I want to merge deleted documents. They do not show up in _conflicts field, but in _deleted_conflicts. If I merge only using _conflicts field, and a document is deleted in the local database and edited in the remote replica, it will be resurrected locally on replication. My application model assumes that deletion always takes precedence when merging: a deleted documents stays deleted regardless of what edits it conflicts with.

So, at a first glance, the simplest thing to do is to check that _deleted_conflicts is not empty and if it is not empty, delete the document, right? Well... the problem with this is that this may also contain deleted revisions that were introduced by resolving edit conflicts in step #4, so the meaning of _deleted_conflicts is ambiguous in this case.

What's the canonical way of handling deletion conflicts in CouchDB (if any) that doesn't involve doing gross things like marking documents as deleted and filtering at the application layer?

解决方案

The best solution would be to use the reserved property _deleted to remove documents instead of HTTP DELETE. Then you are free to also set other properties:

doc._deleted = true;
doc.deletedByUser = true;
doc.save();

Then in the merge process check the _changes feed for _deleted_conflicts and delete the document if there is a revision within _deleted_conflicts that has the deletedByUser flag set to true.

I hope this helps!

这篇关于解决CouchDB中已删除文档的复制冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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