getAndLock problem
Hi,
I've recently started using Couchbase 1.8.1 enterprise version (Java API 1.0) and found that while key is locked other systems/threads fail to read during that lock period. So there is no internal suspension on data retrieval. According to the documentation that is expected behavior.
It looks like if some other system is trying to access locked key it should explicitly suspend execution thread until data get unlocked:
something like
while (isLocked) TimeUnit.MILLISECONDS.sleep(5);
That is perfectly fine unless I am using EJBs where explicit thread management is prohibited.
What native couchbase library means could you suggest or maybe some best practices how to wait on getAndLock if record that being retrieved is already locked?
Thanks,
Alex
Have you looked at optimistic locking using cas? You could also look at
http://dustin.github.com/java-memcached-client/apidocs/net/spy/memcached...
Finally, if you do a
gets on the locked key, you should get a -1 based on which you can do the appropriate.