Couchbase Lite 3.x replication conflict resolver order during Sync Gateway migration
0 reputation · 14 Feb 2020, 02:39 UTC
0 reputation · 14 Feb 2020, 02:39 UTC
Couchbase Lite 3.x uses a replication protocol that Sync Gateway 2.x does not understand, so an existing Couchbase Lite 2.x and Sync Gateway 2.x deployment must move to Couchbase Lite 3.x and Sync Gateway 3.x together. Mixed-version topologies cannot replicate.
The goal is to determine which conflict resolver runs first when the same document is updated concurrently on a mobile client and Sync Gateway during the upgrade. Custom resolvers registered on iOS, Android, and .NET may not apply in a consistent order, and the documentation does not state a default resolution order for mixed SDK versions.
It is unclear whether the server-side Sync Gateway resolver, the client-side Couchbase Lite resolver, or the last-write-wins fallback takes precedence when both sides define conflicting logic.
37275 reputation · 14 Feb 2020, 09:43 UTC
Sync Gateway 3.x applies server-side conflict resolution to conflicting revisions it receives before distributing a winning revision to clients. If Sync Gateway resolves the conflict first, the Couchbase Lite client resolver typically does not run on that already-resolved revision during pull. When client and server custom resolvers return different bodies, there is no guaranteed cross-SDK winner; the side that resolves first persists its body, and the other side converges on the next replication. Last-write-wins is the fallback only when no resolver decides. No documented default order guarantees consistent precedence across iOS, Android, and .NET during a coordinated 3.x migration.
Confirmed: Couchbase Lite 3.x and Sync Gateway 3.x must be upgraded together. Mixed CBL 2.x/Sync Gateway 3.x or CBL 3.x/Sync Gateway 2.x topologies cannot replicate under the 3.x protocol. Sync Gateway performs server-side conflict resolution when it detects conflicting revisions; Couchbase Lite applies client-side resolution during local replication for unresolved conflicts.
Likely explanation, not guaranteed: Sync Gateway 3.x resolves conflicts it observes before forwarding the winning revision to clients, so a client resolver may never execute on server-resolved conflicts. This behavior is not documented as a strict default for every forwarded revision, and push conflicts may interleave differently than pull conflicts.
Inspect conflicting revisions read-only:
curl -X GET 'http://localhost:4985/{database}/_docs/{document-id}?open_revs=all'
Check Sync Gateway configuration for an active conflict handler, and review Sync Gateway logs for conflict resolution entries after a test conflict. Review the Couchbase Lite 3.x and Sync Gateway 3.x release notes for the replication compatibility matrix and any documented conflict-resolution changes.
Are conflicting updates pushed from Couchbase Lite to Sync Gateway, pulled from Sync Gateway to Couchbase Lite, or both? The recommended resolver precedence changes by replication direction.
Use comments to ask for clarification. Post a solution as an answer.
37,275 reputation · 14 Feb 2020, 06:59 UTC
Do not assume one resolver cascade applies to both push and pull. On a pull, Sync Gateway 3.x typically sends a single winning revision after server-side resolution, so Couchbase Lite 3.x may have no conflict to resolve locally. On a push, the client can send conflicting revisions to Sync Gateway, and the server-side handler decides what gets stored. Because the default winner is revision-history based rather than wall-clock, timestamps are not a reliable tiebreaker. Verify with Sync Gateway debug logging and a logging custom resolver on each client SDK, then compare the persisted local revision against the revision Sync Gateway serves after concurrent client and server updates.