couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <>
Subject Re: Resolving replication conflicts for deleted documents in CouchDB
Date Thu, 25 Oct 2012 12:17:16 GMT
A deletion is just an update. The algorithm that CouchDB uses to
choose one leaf out of many deliberately chooses _deleted:false over

Here's a test run I just performed on couchdb/master;

# setup instance #1
curl localhost:5984/alex -XPUT

curl localhost:5984/alex/foo -XPUT -d{}

# setup identical instance #2
curl localhost:5984/alex2 -XPUT

curl localhost:5984/alex2/foo -XPUT -d{}

# update doc in instance #1
curl localhost:5984/alex2/foo -XPUT -d

# delete doc in instance #2
curl localhost:5984/alex2/foo?rev=1-967a00dff5e02add41819138abb3284d  -XDELETE

curl localhost:5984/_replicate -Hcontent-type:application/json -d
25 Oct 2012 12:10:54 GMT","end_time":"Thu, 25 Oct 2012 12:10:54

curl localhost:5984/alex/foo

curl 'localhost:5984/alex/foo?open_revs=all'
Content-Type: application/json

Content-Type: application/json


As you can see, the first database, alex, will show the non-deleted
doc as per our algorithm, but the doc has two leaf revisions now. To
resolve in the direction you want, delete the
2-7051cbe5c8faecd085a3fa619e6e6337 revision;

curl localhost:5984/alex/foo?rev=2-7051cbe5c8faecd085a3fa619e6e6337 -XDELETE

curl 'localhost:5984/alex/foo'


On 25 October 2012 01:29, Alexander Bolodurin
<> wrote:
> Hi,
> (I have asked this at StackOverflow, but, unsurprisingly, the question didn't get much
> I'm designing replication conflict handling for a system, and one of its assumptions
is that deletion always takes precedence when resolving conflicts: a deleted documents stays
deleted regardless of what edits it conflicts with, IDs are not reused.
> The "official" way of resolving replication conflicts (read conflicting revisions, merge
in the application code, delete unwanted revisions) is not applicable to deleted documents.
If a document is edited on instance 1, and deleted on instance 2, after replication both instances
get the revision from 1. Because only one leaf revision is alive, the document ends up "undeleted",
and without conflicts. The other revision ends up in _deleted_conflicts field, instead of
_conflicts, but I can't use _deleted_conflicts as a cue that a document was deleted, because
it includes deleted revisions from resolving edit conflicts and documents that were deleted
and then re-added, so it's too general and conflates several cases.
> How can I get around this at the CouchDB level? Moving it up the application layer gets
really hairy really quickly as now I have to have my custom "deleted" flag, rewrite my views,
test more code and have extra batch jobs to clean up records marked for delete.
> Regards,
> Alex.

View raw message