Couchbase C Client  2.4.0_beta
Get items from replica

Detailed Description

Get items from replica.

This is like lcb_get() but is useful when an item from the master cannot be retrieved.

From command version 1, it is possible to select strategy of how to select the replica node. Currently three strategies are available:

  1. LCB_REPLICA_FIRST: Previously accessible and default as of 2.0.8, the caller will get a reply from the first replica to successfully reply within the timeout for the operation or will receive an error.
  1. LCB_REPLICA_ALL: Ask all replicas to send documents/item back.
  1. LCB_REPLICA_SELECT: Select one replica by the index in the configuration starting from zero. This approach can more quickly receive all possible replies for a given topology, but it can also generate false negatives.
Note
applications should not assume the order of the replicas indicates more recent data is at a lower index number. It is up to the application to determine which version of a document/item it may wish to use in the case of retrieving data from a replica.

Examples

Get document from the second replica

lcb_get_replica_cmd_t *get = calloc(1, sizeof(*get));
get->version = 1;
get->v.v1.key = "my-key";
get->v.v1.nkey = strlen(get->v.v1.key);
get->v.v1.strategy = LCB_REPLICA_SELECT;
get->v.v1.index = 2;
lcb_get_replica_cmd_st* commands[] = { get };
lcb_get_replica(instance, NULL, 1, commands);

#### Get document from the first available replica

get->v.v1.strategy = LCB_REPLICA_FIRST;
lcb_get_replica_cmd_st* commands[] = { get };
lcb_get_replica(instance, NULL, 1, commands);

Get document from all replicas

This will will generate lcb_get_num_replicas() responses

get->v.v1.strategy = LCB_REPLICA_ALL;
lcb_get_replica_cmd_st* commands[] = { get };
lcb_get_replica(instance, NULL, 1, commands);

Functions

lcb_error_t lcb_get_replica (lcb_t instance, const void *command_cookie, lcb_SIZE num, const lcb_get_replica_cmd_t *const *commands)
 Get a number of replca values from the cache.

Enumerations

enum  lcb_replica_t
 Select get-replica mode. More...

Function Documentation

lcb_error_t lcb_get_replica ( lcb_t  instance,
const void *  command_cookie,
lcb_SIZE  num,
const lcb_get_replica_cmd_t *const *  commands 
)

Get a number of replca values from the cache.

Example:

lcb_get_replica_cmd_t *get = calloc(1, sizeof(*get));
get->version = 0;
get->v.v0.key = "my-key";
get->v.v0.nkey = strlen(get->v.v0.key);
lcb_get_replica-cmd_t* commands[] = { get };
lcb_get_replica(instance, NULL, 1, commands);
Parameters
instancethe instance used to batch the requests from
command_cookieA cookie passed to all of the notifications from this command
numthe total number of elements in the commands array
commandsthe array containing the items to get
Returns
The status of the operation
Stability
Committed:

Data Structure Documentation

struct lcb_GETREPLICACMDv1

Command for lcb_get_replica()

Data Fields
const void * key
lcb_SIZE nkey
const void * hashkey
lcb_SIZE nhashkey
lcb_replica_t strategy Strategy to use.
int index If strategy is LCB_REPLICA_SELECT, specific the replica index to use.
struct lcb_get_replica_cmd_t

wrapper structure for lcb_get_replica()

See Also
lcb_GETREPLICACMDv1
Data Fields
int version
union lcb_get_replica_cmd_t v

Enumeration Type Documentation

Select get-replica mode.

See Also
lcb_rget3_cmd_t
Enumerator:
LCB_REPLICA_FIRST 

Query all the replicas sequentially, retrieving the first successful response.

LCB_REPLICA_ALL 

Query all the replicas concurrently, retrieving all the responses.

LCB_REPLICA_SELECT 

Query the specific replica specified by the lcb_rget3_cmd_t::index field.