Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with conflicts caused by replication in BigCouch

The CouchDB Replication and Conflicts wiki page suggests using _bulk_docs with all_or_nothing=true to forcibly write new versions of documents even if that introduces conflicts on write, but then resolve shortly after on subsequent reads. I've implemented this and conceptually it seems to work OK.

But BigCouch doesn't support all_or_nothing semantics so writes to bulk docs can return 409 Conflict results. What is the best practice for implementing similar app-level conflict resolution for conflicts introduced by replication in BigCouch? Should I look at write-time conflict resolution instead?

like image 445
akent Avatar asked Jul 01 '12 03:07

akent


People also ask

How does CouchDB replication work?

When you ask CouchDB to replicate one database to another, it will go and compare the two databases to find out which documents on the source differ from the target and then submit a batch of the changed documents to the target until all changes are transferred.


1 Answers

Get the revision number of the document to be updated if there is a conflict during attachment and recursively call in-case of a conflict,

$url = "http://couchdb/DATABASE/DOCID/ATTACHMENTNAME?rev=$rev"; curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_PUT, true ); curl_setopt( $ch, CURLOPT_URL, $url ); curl_exec( $ch ); 
like image 183
user2254842 Avatar answered Nov 14 '22 00:11

user2254842