Sub-Document Mutate operations not working properly with XDCR

106 views Asked by At

We have setup 2 couchbase clusters with XDCR between them. We are using sub-doc mutate to update document with new fields (there is no removal of any field, also no field is being overridden/updated). We found out that if we are updating same document concurrently via cluster 1 and cluster 2, some updates are getting lost.

for eg: if we add field-1 in document-1 via cluster-1 and concurrently field-2 is being added to document-1 from cluster-2, then only one update will be effective and either field-1 or field-2 would be missing from the resulting document.

Is there any way we can solve this issue so that there is no data loss? Our original thought was that because this was a “sub-doc” operation, XDCR would take this into consideration and merge both document versions by updating final document accordingly based on individual paths provided during sub-doc mutate operations.

1

There are 1 answers

0
Matthew Groves On

As far as I know, XDCR does not currently treat subdocument mutations any differently than document mutations.

The only conflict resolution available (currently) is sequence number or timestamp. This explains why one of your subdocument mutations is "winning" over the other.

I don't know of any way around this, other than avoiding it (i.e restricting certain writes in active-active situation to one cluster or another). For instance, a shopping cart for an east US user is written in the east, copied to the west for reading, and vice versa.

XDCR Custom Conflict Resolution support is something that is coming in a future version. You can see some of the progress on issues.couchbase.com like MB-39731, MB-41107, MB-41106, etc. but I don't know the exact date for that release, and it may (or may not) be a developer preview feature initially.

The only other thing that might be worth looking into is Couchbase Sync Gateway/Lite, which has both automatic and custom conflict resolution. This doesn't sound like it will fit your use case, but you might want to look into it just in case.