Couchbase C Client  2.5.6
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

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.
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;
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

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()