I have aquestion regarding locking in couchbase.
In our application we have a service which is continuously processing documents from couchbase based on a status field in the document which is also indexed using the views. we are currently fetching each document with a waiting status using getwithlock in the c# client and updating the status to processed and then processing the document. my question is, if we multithread our application to process the documents because all the threads will be querying the same index if one thread does a getwithlock will the other threads just pick the next document available or wait for the lock to be released and pick up the same document?
From the documentation: http://docs.couchbase.com/couchbase-devguide-2.2/#locking-items
“Get-and-lock methods enable you to retrieve a value for a given key and lock that key; it thereby provides a form of pessimistic concurrency control in Couchbase Server. While a key is locked, other clients are not able to update the key, nor are they able to retrieve it”
So, the other threads won’t actually wait until the lock as expired, but they will not be able to access the key - an error will be returned. However, you can only set a lock for a maximum of 30 seconds. After that time the key will become available.