On Thu, Oct 23, 2014 at 2:12 PM, Christoph Berlin <[email protected]>
wrote:

>
> If I understand you correctly both documents get created but the version
> with the higher revision wins, correct?
>
>
Yes, as Jens mentioned it's a special case of a conflict where there is no
common parent.  Two branches, each having it's own root.

The rule for determining the winning conflict, in the case that there are
no branches with delete revisions and the branches are of the same length,
is a lexicographic comparison between the digest parts, and the lower one
wins.

Eg if your conflicting revs were:

1-a342
1-z343

Since "a342" has lower sort order than "z343", then 1-a342 would be the
chosen winning revision.

There are some more complicated rules if you have deletion revisions on any
of the branches, or the branches are of different length.



> However lets assume a slightly different scenario:
> 1) iPad creates user_profile document offline at login and then syncs to
> database
> 2) iPhone is online and synced. When I try to create a NEW document with
> the ID (same step as creating a user profile offline) I get an error that
> the document ID already exists, correct?
>

Yup, it will reject it with a 409 error.


>
> My question would be whether it is save to assume that I could technically
> create two documents with the same ID on two different offline devices and
> Sync Gateway will try to clean up the mess?
>

Yeah as Jens mentioned, it's not really Sync Gateway cleaning up any mess,
it's more that the distributed algorithm takes this scenario into account,
and deals with it gracefully on all parts of the system (each Couchbase
Lite node and the Sync Gateway node).

So if you create two docs with the same ID on two different offline
devices, once they go online and reconcile, one of those docs will be
considered the winning revision and the other will be considered the losing
revision, and all future edits will happen on the winning revision.  The
behavior will be consistent across all nodes in the system.  (eg, each node
will pick the same winning revision)



> If so how do I protect my data logic from running into that problem?
> Meaning there is a reason that I usually cannot create the same document ID
> twice but in this scenario it bypasses that check.
>

I would argue that for some business requirements, its not actually a
problem.  In TodoLite, you can create two profiles with the same email on
two different devices while they are offline, and it doesn't create any
problems.  Sure, there might be conflicting revisions within that profile
doc once the devices sync, but in and of itself doesn't create a
"problem".  I mean, it doesn't break anything.  As I said before, if you
don't clean up the conflict, it will just use a bit more storage than it
otherwise would.

But, if your business requirements consider it a problem, then you could do
what Jens mentioned and first issue a GET to the Sync Gateway and see if
that doc already exists.  Of course, that puts the network back into the
critical path for your app for that operation, so you might get some extra
user attrition for impatient users on slow networks.  So there's a tradeoff.

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/CACSSHCGFRaEpc8REN5DVqYJ_xso%3DPxioToCrW0%2BHH7nF8OxnHA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to