Couchbase C Client
2.4.4
|
The lcb_durability_poll() is used to wait asynchronously until the item have been persisted and/or replicated to at least the number of nodes specified in the durability options.
The command is implemented by sending a series of OBSERVE
broadcasts (see lcb_observe()) to all the nodes in the cluster which are either master or replica for a specific key. It polls repeatedly until either the timeout interval has elapsed or all the items have been persisted and/or replicated to the number of nodes specified in the criteria.
Unlike most other API calls which accept only a per-key structure, the lcb_durability_opts_st (lcb_DURABILITYOPTSv0) structure affects the way the command will poll for all keys as a whole:
The lcb_DURABILITYOPTSv0::timeout field indicates the upper limit (in microseconds) of time the command will wait until all the keys' durability requirements are satisfied. If the durability requirements ae not satisfied when the timeout is reached, the outstanding keys will be set to an error status in the callback (see lcb_DURABILITYRESPv0::err). If set to 0, it will default to the value of the LCB_CNTL_DURABILITY_TIMEOUT setting.
The lcb_DURABILITYOPTSv0::interval field specifies how long to wait between each attempt at verifying the completion of the durability requirements. If not specified, this will be LCB_CNTL_DURABILITY_INTERVAL
The lcb_DURABILITYOPTSv0::persist_to field specifies how many nodes must contain the item on their disk in order for the command to succeed. The maximum value should be the number of nodes in the cluster.
The lcb_DURABILITYOPTSv0::replicate_to field specifies how many replicas must contain the item in their memory for this command to succeed. The maximum value should be the the number of replicas in the cluster.
The lcb_DURABILITYOPTSv0::check_delete flag indicates that this operation should check for the non-presence of an item. This is used to ensure a successful removal of an item via lcb_remove(). In this case, the semantics of 'persist_to' and 'replicate_to' are inverted, where 'persist_to' means the number of nodes where the item is deleted from the disk, and 'replicate_to' means the number of nodes where the item not present in the cache.
In all cases, the value of 'replicate_to' will implicitly always be at least the value of 'persist_to'-1.
The lcb_DURABILITYOPTSv0::cap_max field indicates that the library should set persist_to and replicate_to to their maximum available number if those fields are set beyond current limits. This will be set based on the number of nodes active in the cluster and the number of replicas the cluster is configured with.
Functions | |
lcb_error_t | lcb_durability_poll (lcb_t instance, const void *cookie, const lcb_durability_opts_t *options, lcb_SIZE ncmds, const lcb_durability_cmd_t *const *cmds) |
Schedule a durability check on a set of keys. More... | |
lcb_durability_callback | lcb_set_durability_callback (lcb_t, lcb_durability_callback) |
Typedefs | |
typedef void(* | lcb_durability_callback )(lcb_t instance, const void *cookie, lcb_error_t err, const lcb_durability_resp_t *res) |
Callback for durability status. More... | |
lcb_error_t lcb_durability_poll | ( | lcb_t | instance, |
const void * | cookie, | ||
const lcb_durability_opts_t * | options, | ||
lcb_SIZE | ncmds, | ||
const lcb_durability_cmd_t *const * | cmds | ||
) |
Schedule a durability check on a set of keys.
This callback wraps (somewhat) the lower-level OBSERVE (lcb_observe) operations so that users may check if a key is endured, e.g. if a key is persisted accross "at least" n number of servers
When each key has its criteria satisfied, the durability callback (see above) is invoked for it.
The callback may also be invoked when a condition is encountered that will prevent the key from ever satisfying the criteria.
instance | the lcb handle |
cookie | a pointer to be received with each callback |
options | a set of options and criteria for this durability check |
cmds | a list of key specifications to check for |
ncmds | how many key specifications reside in the list |
LCB_DURABILITY_ETOOMANY
which indicates that the number of servers specified by the user exceeds the possible number of servers that the key may be replicated and/or persisted to:Example (after receiving a store callback)
struct lcb_DURABILITYCMDv0 |
Single-key command structure for lcb_durability_poll()
Data Fields | |
const void * | key |
size_t | nkey |
struct lcb_durability_cmd_t |
lcb_durability_poll() Command wrapper
Data Fields | ||
---|---|---|
int | version | |
union lcb_durability_cmd_t | v |
struct lcb_DURABILITYOPTSv0 |
Options for lcb_durability_poll()
Data Fields | ||
---|---|---|
lcb_U32 | timeout |
Upper limit in microseconds from the scheduling of the command. When this timeout occurs, all remaining non-verified keys will have their callbacks invoked with |
lcb_U32 | interval |
The durability check may involve more than a single call to observe - or more than a single packet sent to a server to check the key status. This value determines the time to wait (in microseconds) between multiple probes for the same server. If left at 0, the LCB_CNTL_DURABILITY_INTERVAL will be used instead. |
lcb_U16 | persist_to | how many nodes the key should be persisted to (including master) |
lcb_U16 | replicate_to | how many nodes the key should be replicated to (excluding master) |
lcb_U8 | check_delete | this flag inverts the sense of the durability check and ensures that the key does not exist |
lcb_U8 | cap_max | If replication/persistence requirements are excessive, cap to the maximum available. |
struct lcb_durability_opts_t |
Options for lcb_durability_poll() (wrapper)
Data Fields | ||
---|---|---|
int | version | |
union lcb_durability_opts_t | v |
struct lcb_DURABILITYRESPv0 |
Response structure for lcb_durability_poll()
Data Fields | ||
---|---|---|
const void * | key | |
lcb_SIZE | nkey | |
lcb_error_t | err |
if this entry failed, this contains the reason, e.g.
|
lcb_cas_t | cas | if found with a different CAS, this is the CAS |
unsigned char | persisted_master |
Whether the key was persisted to the master. For deletes, this means the key was removed from disk |
unsigned char | exists_master |
Whether the key exists on the master. For deletes, this means the key does not exist in cache |
unsigned char | npersisted | how many nodes (including master) this item was persisted to |
unsigned char | nreplicated | how many nodes (excluding master) this item was replicated to |
unsigned short | nresponses |
Total number of observe responses received for the node. This can be used as a performance metric to determine how many total OBSERVE probes were sent until this key was 'done' |
typedef void(* lcb_durability_callback)(lcb_t instance, const void *cookie, lcb_error_t err, const lcb_durability_resp_t *res) |
Callback for durability status.
The callback is invoked on completion of each key (i.e. only one callback is invoked per-key).
lcb_t | the instance |
cookie | the user cookie |
err | an error |
res | a response containing information about the key. |