How to set up a conflict solver "deletes always win"

Hello everybody,

I need to create a conflict solver type : “deletes always win”.

My use case is :

  • Server creates (couchbase/syncgateway) documents
  • Mobile app sync documents
  • Mobile switch offline
  • Server delete some documents
  • Mobile update some documents
  • Mobile switch online
  • Mobile sync with server

Deleted server documents are recreated by mobile side application.
This is expected because Tombstone doesn’t appear as conflict and as result the updated mobile revision win.

But I want a solution to preserve the deleted server revision, how can i do that ?

(using couchbase mobile 1.5)

Best regards,

You will be pleased to know that this is the default behavior in 2.0 now. Are you taking about 1.x though?

Oops you are. I didn’t see the edit. I’ll have to think on that one.

Yes I use CL 1.5 version.
Are you saying that CL 2.0 can solve my problem ?

Indeed the algorithm has been changed from deletes always lose in 1.x to deletes always win in 2.0.

Thanks !

I was lookink for that behavior in the documentation 2.0 but I found nothing.
Have you any link who explain that ?

Another thing, in that way, how conflict are resolved in 2.0 ?

Best regards

There is a blog post on conflict handling in CBM 2.0 that will be coming out very soon …hopefully next week. I will share the link to that here as soon as its available.

In the meantime, here is a preview of whats to come (in the blog) -
The conflict resolution process is handled by the writers at the time the document is saved, which in our case would be the the Couchbase Lite 2.0 mobile clients.
Every document in Couchbase Lite 2.0 is associated with a “conflict resolver” that is executed if a conflict occurs when an attempt is made to save a document. The conflict resolver function chooses a “winner” among the conflicting revisions and this winner is added as a child to the document revision tree.

The default conflict resolver policy is as follows

  • Deletes always win
    • This means that if you attempt to save an update to a document that is already deleted, then your update will be ignored. Similarly, if you attempt to delete a document, then your delete will always succeed.
  • Most recent change (highest generation ID) wins or the revision with max revID wins if the generations are the same.
1 Like

Thank you for fast answer !

For now, I will patch my client and migrate 2.0 very soon.
The new default conflict solver should solved my problemes.

I read that I could migrate my default database (SQLite), this is perfect.

Hmm…so you are using sqlite ? can you point to the resource that indicates this auto migration (just for my understanding of what you are attempting to do)

I read that here :

I currently use the SQLite storage engines.

Ah got it. You meant that you were using the sqlite storage engine type. I was wondering if you were looking to migrate from sqlite to CBLite!

That said, just in case you hadn’t accounted for it, please be forewarned that the API in 2.0 is vastly different from 1.x API. So while migrating your current DB is an important first step, you will also have to update your app to use the 2.0 APIs …

Yes I see that, I will rewrite my CBLite manager when I will migrate my application.