Couchbase C Client  2.10.7
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
lcb_RESPBASE::nkey
lcb_SIZE nkey
Size of key.
Definition: couchbase.h:626
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.
lcb_CMDBASE::cas
lcb_U64 cas
The known CAS of the item.
Definition: couchbase.h:523
lcb_CALLBACKTYPE
lcb_CALLBACKTYPE
The type of response passed to the callback.
Definition: couchbase.h:695
lcb_RESPBASE::cas
lcb_CAS cas
CAS for response (if applicable)
Definition: couchbase.h:626
LCB_CMD_SET_KEY
#define LCB_CMD_SET_KEY(cmd, keybuf, keylen)
Set the key for the command.
Definition: couchbase.h:556
lcb_t
struct lcb_st * lcb_t
Definition: couchbase.h:41
lcb_RESPBASE
Base response structure for callbacks.
Definition: couchbase.h:625
lcb_CMDBASE
Common ABI header for all commands.
Definition: couchbase.h:522
lcb_RESPBASE::key
const void * key
Key for request.
Definition: couchbase.h:626