Understanding conflict handling

Hi,

I’m playing around a simple demo app to understand how conflicts are generated and handled in CBLite & SG. I’m working with CBLite EE 2.7.0 and SG 2.7.1, in SG’s config the databases.foo_db.allow_conflicts is not set so should default to true.

My app starts creating a new doc like this (logcat output):

Created doc 4f5ad939-c9ea-437e-bd82-9ce5d9684a0c
Doc to string: Document..{4f5ad939-c9ea-437e-bd82-9ce5d9684a0c@1-ed6907ebc6666108a3abd12da2cdf990c9886f27:a=>a,b=>b}
Doc to map to string: {a=a, b=b}
Doc info: 1-ed6907ebc6666108a3abd12da2cdf990c9886f27 - 892

Then I start a push sync and if I try to get the doc via SG api I find it as expected:

{
    "_id": "4f5ad939-c9ea-437e-bd82-9ce5d9684a0c",
    "_rev": "1-ed6907ebc6666108a3abd12da2cdf990c9886f27",
    "_revisions": {
        "ids": [
            "ed6907ebc6666108a3abd12da2cdf990c9886f27"
        ],
        "start": 1
    },
    "a": "a",
    "b": "b"
}

Then I make a PUT to SG to modify the doc server side, this is the new doc:

{
    "_id": "4f5ad939-c9ea-437e-bd82-9ce5d9684a0c",
    "_rev": "2-22ea3716b100df98b4de2fc024f5b5e8",
    "_revisions": {
        "ids": [
            "22ea3716b100df98b4de2fc024f5b5e8",
            "ed6907ebc6666108a3abd12da2cdf990c9886f27"
        ],
        "start": 2
    },
    "a": "a",
    "b": "server"
}

I also update the doc on the app:

Updated doc 4f5ad939-c9ea-437e-bd82-9ce5d9684a0c
Doc to string: Document..{4f5ad939-c9ea-437e-bd82-9ce5d9684a0c@2-df44bc0ee1c8cd88408c469bae21a8a3c659419e:a=>a,b=>client}
Doc to map to string: {a=a, b=client}
Doc info: 2-df44bc0ee1c8cd88408c469bae21a8a3c659419e - 893

and then start a push sync. Sync performs with no errors, but on the server I can’t find any conflicting revision on the doc, the SG GET payload is exactly the same as above. Even if I perform a pull sync on the app, nothing changes and replication conflict resolver is not fired.
I’d expect to find conflicting revisions in document’s tree server side (how can I inspect them?) and have conflict resolver fired when pull replica is started.

Am I missing something?

Thanks.
Paolo

Update: adding a DocumentReplicationListener on the replicator, during push replica I got an error for the doc:

 Error replicating document: 
    CouchbaseLiteException{CouchbaseLite,10409,'conflicts with newer server revision'}

Going deeper in docs and this blog post, this might be due to the fact that:

there will be no conflicting revisions added to the Sync Gateway when syncing with Couchbase Lite 2.0 clients

so the value of allow_conflicts config has no effect on CBLite 2.x: SG rejects conflicts from mobile clients. This can explain why I can’t see any doc change server side after push sync.

I sill have to understand why during pull sync my ConflictResolver is not fired…

Ok, found my mistake, the test doc was missing the property to be added to my user’s channel, so pull replica didn’t fetch the server side modifications. Now after conflict generation, the resolver is called during the first pull replica.

Hope this help someone else digging in…

P

1 Like

thanks for sharing your experience. :smile: