Couchbase C Client  3.3.14
Asynchronous C Client for Couchbase
Read (Replica)

Detailed Description

Retrieve a document from a replica if it cannot be fetched from the primary

Function Documentation

◆ lcb_cmdgetreplica_on_behalf_of()

lcb_STATUS lcb_cmdgetreplica_on_behalf_of ( lcb_CMDGETREPLICA * cmd,
const char * data,
size_t data_len )
Stability
Internal
Internal: This should never be used and is not supported.

◆ lcb_cmdgetreplica_on_behalf_of_extra_privilege()

lcb_STATUS lcb_cmdgetreplica_on_behalf_of_extra_privilege ( lcb_CMDGETREPLICA * cmd,
const char * privilege,
size_t privilege_len )
Stability
Internal
Internal: This should never be used and is not supported.

Enumeration Type Documentation

◆ lcb_REPLICA_MODE

Spool a single get-with-replica request.

Stability
Committed
Parameters
instance
cookie
cmd
Returns
LCB_SUCCESS on success, error code otherwise.

When a response is received, the callback installed for LCB_CALLBACK_GETREPLICA will be invoked. The response will be an lcb_RESPGET pointer.

Request

lcb_CMDGETREPLICA* cmd;
lcb_cmdgetreplica_create(&cmd);
lcb_cmdgetreplica_key(cmd, "key", 3);
lcb_cmdgetreplica(instance, cookie, &cmd);

Response

static void rget_callback(lcb_INSTANCE *instance, int cbtype, const lcb_RESPBASE *rb)
{
const lcb_RESPGET *resp = (const lcb_RESPGET *)rb;
char* key;
char* value;
size_t key_len;
size_t value_len;
lcb_STATUS rc = lcb_respgetreplica_status(resp);
lcb_respgetreplica_key(resp, &key, &key_len);
printf("Got Get-From-Replica response for %.*s\n", key_len, key);
if (rc == LCB_SUCCESS) {
lcb_respgetreplica_value(resp, &value, &value_len);
printf("Got response: %.*s\n", value_len, value);
else {
printf("Couldn't retrieve: %s\n", lcb_strerror_short(rc));
}
}
LCB_INTERNAL_API const char * lcb_strerror_short(lcb_STATUS error)
Get a shorter textual description of an error message.
lcb_STATUS
Error codes returned by the library.
Definition error.h:213
struct lcb_RESPGET_ lcb_RESPGET
Command for retrieving a single item.
Definition couchbase.h:687
struct lcb_st lcb_INSTANCE
Library handle representing a connection to a cluster and its data buckets.
Definition couchbase.h:35
lcb_RESPCALLBACK lcb_install_callback(lcb_INSTANCE *instance, int cbtype, lcb_RESPCALLBACK cb)
@ LCB_CALLBACK_GETREPLICA
lcb_getreplica()
Definition couchbase.h:481
Warning
As this function queries a replica node for data it is possible that the returned document may not reflect the latest document in the server.
This function should only be used in cases where a normal lcb_get3() has failed, or where there is reason to believe it will fail. Because this function may query more than a single replica it may cause additional network and server-side CPU load. Use sparingly and only when necessary.
  • ::LCB_ERR_DOCUMENT_NOT_FOUND if the key is not found on the replica(s), ::LCB_ERR_NO_MATCHING_SERVER if there are no replicas (either configured or online), or if the given replica (if lcb_CMDGETREPLICA::strategy is ::LCB_REPLICA_SELECT) is not available or is offline.