CAS Validation - Is it possible?

I’m in the process of updating our application from the 1.3 client to 2.0.

Leveraging information learned from the following post, with version 1.3, I was able to verify that a locally cached copy of the data retrieved from Couchbase is current by verifying that the CAS has not changed, without retrieving the often large blob of data (encoding / decoding optimization). Code that I had to do this is:

var result = CouchbaseClient.Observe(cacheKey, cachedCasValue, PersistTo.Zero, ReplicateTo.Zero);
if (result.Success && (result.Cas == cachedCasValue))
{
    // MATCH - use what's in cache
} else {
    // NO MATCH - cached data is out of date 
}

With the new 2.0 Client, Observe has fundamentally changed; it returns an ObserveResponse object, which only contains information about data storage. It does not respect checking / verifying the CAS value. I’ve tried this:

ObserveResponse casCheck = (CouchbaseBucket.Observe(cacheKey, cachedCasValue, false, ReplicateTo.Zero, PersistTo.Zero));

And regardless of the cachedCasValue, it returns only information about Durability (in my case DurabilitySatisfied regardless of CAS value validity). Since the latest CAS is not included in the response (like in 1.3), I cannot verify this in my own code.

Is there any way to achieve the desired results with the 2.0 client? I don’t see anything in IBucket that matches, other than this method.

Thanks!

Howard

Hi @unhuman -

In the 2.0 client, the Observe method will check to see if the CAS has changed and return a failure message if it has changed. Also, each of the operations contain overloads which use Observe: Upsert, Remove, Insert, etc.

And regardless of the cachedCasValue, it returns only information about
Durability (in my case DurabilitySatisfied regardless of CAS value
validity).

This is likely a bug, if you get DurabilitySatisfied when the CAS has changed; you should be receiving DurabilityNotSatisfied.

-Jeff

Thanks for the quick reply. I’ll see how important this is for us - maybe I’ll work up another patch.

Best,

Howie

@unhuman -

I made a ticket here: https://issues.couchbase.com/browse/NCBC-777

-Jeff

1 Like

@unhuman -

Patch is here: http://review.couchbase.org/#/c/44989/

-Jeff

I was fixing it simultaneously (although a little bit slower), but that’s exactly the fix I found as well.

Running the test cases locally, I’ve seen some peculiar behavior. Your tests, for me, fail (The operation has timed out (for each Remove, Insert, and Upsert) with the key variable set as: “When_CAS_Changed_Observe_Returns_DurabilityNotSatisfied” and “When_CAS_Changed_Observe_Returns_DurabilitySatisfied”.

If I change the keys to “Test_Observe_Upsert”, they work. I saw similar behavior when I was writing my own test cases. No idea why. Not letting this block the review.

Thanks!