> On Aug 18, 2014, at 1:35 AM, Daniel McGreal <[email protected]> wrote:
> 
> Is it possible to use Couchbase Server's (Java SDK) Check and Set 
> functionality with Sync Gateway's bucket shadowing in order to have 
> optimistic concurrency on both sides of the application? Essentially this 
> boils down to whether SG will respect CAS values when it updates a document 
> in CB. I'm particularly interested in CB3 CAS support with Java SDK 2.0.

No — the gateway uses a simple Set call without CAS to update the app bucket.

What you're suggesting, I think, is for the gateway to record the CAS value 
whenever it saves a document to the app bucket, and then use a Set-with-CAS the 
next time it updates the document; that way if the CAS value has changed the 
Set will fail, and the gateway can read the current value from the app bucket.

It's been a while since I worked on this code, but IIRC there are two problems:

1. Couchbase Server's Set call doesn't return the new CAS value. So to get this 
value we'd have to issue an immediate Get after the Set, which could be bad for 
performance (and is subject to possible race conditions.)

2. It's unclear what to do if there is a conflict. CAS codes carry less 
information than the revision histories that the Gateway and Couchbase Lite 
use. The result would be a conflict, but I'm not sure if it would be possible 
to add the new version from the app bucket to the revision tree in a meaningful 
way. (Hm, it might be. This needs more thought…)

Do you have any more ideas about how you think this should work? (I will freely 
admit that I'm not an expert on CAS.)

—Jens

-- 
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/1A413910-8CAF-4655-B06A-3EDC71809C4A%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to