Resolving replication conflicts for deleted documents in CouchDB

妖精的绣舞 提交于 2019-12-21 07:34:11

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/13043927/resolving-replication-conflicts-for-deleted-documents-in-couchdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!