Couchbase C Client  2.10.6
Asynchronous C Client for Couchbase
Lock/Unlock

Detailed Description

Documents may be locked and unlocked on the server. While a document is locked, any attempt to modify it (or lock it again) will fail.

Note
Locks are not persistent across nodes (if a node fails over, the lock is not transferred to a replica).
The recommended way to manage access and concurrency control for documents in Couchbase is through the CAS (See lcb_CMDBASE::cas and lcb_RESPBASE::cas), which can also be considered a form of opportunistic locking.
Locking an item
There is no exclusive function to lock an item. Locking an item is done using lcb_get3(), by setting the lcb_CMDGET::lock option to true.

Functions

lcb_error_t lcb_unlock3 (lcb_t instance, const void *cookie, const lcb_CMDUNLOCK *cmd)
 Unlock a previously locked item using lcb_CMDGET::lock. More...
 

Typedefs

typedef lcb_CMDBASE lcb_CMDUNLOCK
 Command for lcb_unlock3() More...
 
typedef lcb_RESPBASE lcb_RESPUNLOCK
 Response structure for an unlock command. More...
 

Function Documentation

◆ lcb_unlock3()

lcb_error_t lcb_unlock3 ( lcb_t  instance,
const void *  cookie,
const lcb_CMDUNLOCK cmd 
)

Unlock a previously locked item using lcb_CMDGET::lock.

Stability
Committed:
Parameters
instancethe instance
cookiethe context pointer to associate with the command
cmdthe command containing the information about the locked key
Returns
LCB_SUCCESS if successful, an error code otherwise
See also
lcb_get3()
Request
void locked_callback(lcb_t, lcb_CALLBACKTYPE, const lcb_RESPBASE *resp) {
lcb_CMDUNLOCK cmd = { 0 };
LCB_CMD_SET_KEY(&cmd, resp->key, resp->nkey);
cmd.cas = resp->cas;
lcb_unlock3(instance, cookie, &cmd);
}

Typedef Documentation

◆ lcb_CMDUNLOCK

Command for lcb_unlock3()

Attention
lcb_CMDBASE::cas must be specified, or the operation will fail on the server

◆ lcb_RESPUNLOCK

Response structure for an unlock command.

Note
the lcb_RESPBASE::cas field does not contain the CAS of the item