I am using Couchbase .NET SDK 1.3.
The task is to store a value, provided the data under its key has not been modified in the DB since the value was read, and be sure the new value is persisted/replicated to a certain number of nodes. For modification check, I'd like to utilize optimistic locking, i.e. Couchbase's CAS methods. I need to synchronously wait until persistence/replication of the value is successful.
Problem is that Couchbase SDK provides methods to specify either a CAS value or durability requirements:
ExecuteCas(mode, key, value, validfor, cas);
ExecuteStore(mode, key, value, persistTo, replicateTo);
I need to combine both. There is also Observe
method:
Observe(key, cas, persistTo, replicateTo);
Seems that it's what I need, but I couldn't find its documentation anywhere. So, particularly, I can't be sure if the method waits for the value to be persisted/replicated or just checks that at the moment of the call. Is it valid to use this method like so?
var storeResult = client.ExecuteCas(StoreMode.Set, key, value, TimeSpan.FromSeconds(60), cas);
// check storeResult.Success
var observeResult = client.Observe(key, cas, persistTo, replicateTo);
// check observeResult.Success
Got an answer on the official forums: https://forums.couchbase.com/t/2199
Indeed,
Observe
method can be used. It will block until the value is persisted/replicated.