Asynchronous set


#1

Hi,
I use multiple apache machines and two nodes of couchbase.
I see that I upsert a key in one apache machine but fail to get it from a different apache machine two seconds later. I assume that the php sdk will direct me to the right node and the right vbucket. So I guess that the upsert method is asynchronous.
How can I promise strong consistency using php sdk?

Thanks,
Tan-Tan


#2

If you are using normal KV methods (upsert(), get()) etc, then any change made by an upsert should be immediately visible via a get in another machine.

While Couchbase does have consistency options, the options are only intended for:

  1. Fault tolerance (i.e. replication and persistence, so if the active node for an item goes away, the replica is certain to contain the exact same data)
  2. For communication across different Couchbase systems (for example, between KV and query index)

The fault tolerance scenario in your case does not apply, since it appears that a node has not failed. The cross-subsystem scenario does not apply either since you are using the same subsystem (KV or Memcached) for both.

Whatever is happening in your case is a result of application error, meaning that somehow you are causing the key to be removed before the second get is performed. Do check that:

  • All machines are connected to the same bucket and cluster
  • If using expiration, ensure the item hasn’t yet expired
  • The key is not explicitly being removed from the cluster

#3

Thank you, I’ll keeping digging my code.


#4

After deeper digging, I can say with increasing confidence that the problem is not in my code.
In my code there is no place that deletes keys.
Also, while I run my test that reproduces the issue (every time) I run another script that fetches the content every 100 millis and prints it correctly, so I believe that the problem occurs only when I access the SDK from apache process.
Also, I noticed that it’s not happening on both of my buckets, only on the one that replicated using XDCR with my other data-center, maybe it’s related.
BTW, the time that takes for the issue to raise is different every execution, sometimes on the second try and sometimes on the 40th one, and of course all the range between them.
Any new directions?


#5

Few more tests:
The same key that didn’t return a value, returns actually an empty value, no exception is thrown.
It happens also using CLI with php script.
The same key that failed in the php script will always fail in this execution even if I redefine the connection and the bucket instances, and if that key returned the right value, it will keep doing so also with new connection instance.
It didn’t reproduce with python even once, so I believe it’s the PHP sdk that causes it.


#6

Also, I noticed that the cbc version that fails with php is 2.5.2 and the version that succeed with the python is 2.5.1.


#7

Tested some more:
It didn’t happen when I used JSON object, it happened only with int values, and only with large numbers, e.g. php time().
Building the latest code from the git hub also didn’t solve it.
I bypassed the problem by working only with JSON objects.