How does CouchDB handles conflicts while doing bi-directional replication?
For example: Lets say there are two address book databases (in server A and B). There is a document for Jack which contains contact details of Jack.
How does couchDB handles it? If we initiate replication in a Java program, is there a way to know whether there were any conflicts from the java program?
The CouchDB documentation offers an explanation.
In a nutshell: CouchDB does not try to merge the conflicting versions. Both versions get copied into both replicas. A deterministic (but from an application-standpoint probably arbitrary) algorithm chooses one of them to be the "official" version. It will choose the same version on both replicas. Only this version will be visible by default and in views. Your application can query for the other versions, and merge them according to its needs (possibly involving the user by showing all versions on screen). If your application does not look for conflicts, one of the two updates will be effectively lost.
If you are not using the replication or bulk loading API (but the per-document REST API), the conflicting update will not make it into the database, but will be rejected with a 409 error. You have to merge before trying to update again (just like in Subversion).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With