Couchbase C Client  2.10.7
Asynchronous C Client for Couchbase
Mutation Tokens

Detailed Description

Mutation Tokens are returned with mutations if LCB_CNTL_FETCH_MUTATION_TOKENS is enabled (off by default). Mutation tokens are largely of internal use, but can be used by N1QL queries and durability requirement polling

Functions

const lcb_MUTATION_TOKENlcb_resp_get_mutation_token (int cbtype, const lcb_RESPBASE *rb)
 Retrieves the mutation token from the response structure. More...
 
const lcb_MUTATION_TOKENlcb_get_mutation_token (lcb_t instance, const lcb_KEYBUF *kb, lcb_error_t *errp)
 

Macros

#define LCB_MUTATION_TOKEN_ID(p)
 Get the vBucket UUID.
 
#define LCB_MUTATION_TOKEN_SEQ(p)
 Get the sequence number.
 
#define LCB_MUTATION_TOKEN_VB(p)
 Get the vBucket number itself.
 
#define LCB_MUTATION_TOKEN_ISVALID(p)
 Whether this mutation token has valid contents.
 

Function Documentation

◆ lcb_resp_get_mutation_token()

const lcb_MUTATION_TOKEN* lcb_resp_get_mutation_token ( int  cbtype,
const lcb_RESPBASE rb 
)

Retrieves the mutation token from the response structure.

Parameters
cbtypethe type of callback invoked
rbthe pointer to the response
Returns
The embedded mutation token, or NULL if the response does not have a mutation token. This may be either because the command does not support mutation tokens, or because they have been disabled at the connection level.

◆ lcb_get_mutation_token()

const lcb_MUTATION_TOKEN* lcb_get_mutation_token ( lcb_t  instance,
const lcb_KEYBUF kb,
lcb_error_t errp 
)
Stability
Volatile:

Retrieves the last mutation token for a given key. This relies on the LCB_CNTL_DURABILITY_MUTATION_TOKENS option, and will check the instance-level log to determine the latest MUTATION_TOKEN for the given vBucket ID which the key maps to.

Parameters
instancethe instance
kbThe buffer representing the key. The type of the buffer (see lcb_KEYBUF::type) may either be LCB_KV_COPY or LCB_KV_VBID
[out]errpSet to an error if this function returns NULL
Returns
The mutation token if successful, otherwise NULL.

Getting the latest mutation token for a key:

kb.contig.bytes = "Hello";
kv.config.nbytes = 5;
mt = lcb_get_mutation_token(instance, &kb, &rc);

Getting the latest mutation token for a vbucket:

kv.contig.nbytes = 543;
kv.config.bytes = NULL;
mt = lcb_get_mutation_token(instance, &kb, &rc);

Getting the mutation token for each vbucket

size_t ii, nvb;
lcbvb_CONFIG *vbc;
nvb = vbucket_get_num_vbuckets(vbc);
for (ii = 0; ii < nvb; ii++) {
const lcb_MUTATION_TOKEN *mt;
kb.contig.nbytes = ii;
kb.config.bytes = NULL;
mt = lcb_get_mutation_token(instance, &kb, &rc);
}

Data Structure Documentation

◆ lcb_MUTATION_TOKEN

struct lcb_MUTATION_TOKEN

Structure representing a synchronization token.

This token may be used for durability operations and N1QL queries. The contents of this structure should be considered opaque, and accessed via the various macros

Data Fields
lcb_U64 uuid_ Use LCB_MUTATION_TOKEN_ID()
lcb_U64 seqno_ Use LCB_MUTATION_TOKEN_SEQ()
lcb_U16 vbid_ Use LCB_MUTATION_TOKEN_VB()
LCB_CNTL_VBCONFIG
#define LCB_CNTL_VBCONFIG
Get the vBucket handle.
Definition: cntl.h:208
lcb_KEYBUF
Common request header for all keys.
Definition: kvbuf.h:66
lcb_MUTATION_TOKEN
Structure representing a synchronization token.
Definition: couchbase.h:645
LCB_CNTL_GET
#define LCB_CNTL_GET
Retrieve a setting.
Definition: cntl.h:125
LCB_KV_COPY
@ LCB_KV_COPY
The buffer should be copied.
Definition: kvbuf.h:34
LCB_KV_VBID
@ LCB_KV_VBID
For use within the hashkey field, indicates that the length of the hashkey is the vBucket ID,...
Definition: kvbuf.h:40
lcb_CONTIGBUF::nbytes
lcb_size_t nbytes
Number of total bytes.
Definition: kvbuf.h:62
lcb_KEYBUF::type
lcb_KVBUFTYPE type
The type of key to provide.
Definition: kvbuf.h:76
lcb_get_mutation_token
const lcb_MUTATION_TOKEN * lcb_get_mutation_token(lcb_t instance, const lcb_KEYBUF *kb, lcb_error_t *errp)
lcb_cntl
lcb_error_t lcb_cntl(lcb_t instance, int mode, int cmd, void *arg)
This function exposes an ioctl/fcntl-like interface to read and write various configuration propertie...