Couchbase C Client
3.3.14
Asynchronous C Client for Couchbase
|
These routines contain functionality for parsing a cluster topology configuration and mapping keys to cluster nodes appropriately.
lcbvb_CONFIG * lcbvb_create | ( | void | ) |
Allocate a new config This can be used to create new config object and load it with a JSON config, optionally retrieving the error code.
lcbvb_CONFIG * lcbvb_parse_json | ( | const char * | data | ) |
data
and return a new config object data |
int lcbvb_load_json | ( | lcbvb_CONFIG * | vbc, |
const char * | data ) |
vbc | Object to populate |
data | NUL-terminated string to parse |
source | hostname of the node, which emitted configuration. Pointer to NULL will disable heuristic when network argument is pointer to NULL string. |
network | pointer to string, which specified key in alternative addresses dict. Use pointer NULL string to trigger heuristic, in this case, the function will try to match configuration source address to the list of addresses to determine best network. |
int lcbvb_load_json_ex | ( | lcbvb_CONFIG * | vbc, |
const char * | data, | ||
const char * | source, | ||
char ** | network ) |
char * lcbvb_save_json | ( | lcbvb_CONFIG * | vbc | ) |
Serialize the current config as a JSON string.
const char * lcbvb_get_error | ( | const lcbvb_CONFIG * | vbc | ) |
Return a string indicating why parsing the configuration failed.
void lcbvb_replace_host | ( | lcbvb_CONFIG * | cfg, |
const char * | hostname ) |
Replace hostname placeholders with specific host string This function shall replace hostname placeholists with the actual host string specified in hoststr
.
cfg | the configuration |
hostname | the actual hostname to use. |
Use this immediately after a successful parsing of the configuration file.
void lcbvb_destroy | ( | lcbvb_CONFIG * | conf | ) |
int lcbvb_vbmaster | ( | lcbvb_CONFIG * | cfg, |
int | vbid ) |
Gets the master node index for the given vbucket
cfg | The configuration |
vbid | The vbucket to query |
vbid
. Ensure it is within range of 0 < vbid < cfg->nvbs
int lcbvb_vbreplica | ( | lcbvb_CONFIG * | cfg, |
int | vbid, | ||
unsigned | ix ) |
Return the 0-based replica index for the given vbucket.
cfg | The configuration object |
vbid | The vbucket to query |
ix | the replica index to retrieve. This is a number ranging from 0 to vbc->nrepl exclusive. |
vbix
or ix
. Ensure that 0 < vbid < cfg->nvbs
and -1 < ix < cfg->nrepl
int lcbvb_nmv_remap_ex | ( | lcbvb_CONFIG * | cfg, |
int | vbid, | ||
int | bad, | ||
int | use_heuristics ) |
Using various guesswork and heuristics, attempt to locate an alternate node for the master of a given vbucket. This should be used if the master index is -1 or if the master index is deemed incorrect by some other means.
cfg | the configuration object |
vbid | the vbucket index to loop up |
bad | the index known to be bad. Passing this parameter allows the handler to safely call this function and be sure that a previous call's applied heuristics will not affect the modified map. |
use_heuristics | whether additional heuristics should be used. If heuristics is off, only the fast-forward map is employed. |
int lcbvb_map_key | ( | lcbvb_CONFIG * | cfg, |
const void * | key, | ||
lcb_SIZE | n, | ||
int * | vbid, | ||
int * | srvix ) |
Map a given string to a vbucket and server
cfg | The configuration object | |
key | Key to map | |
n | Length of key | |
[out] | vbid | Will contain the vBucket |
[out] | srvix | Will contain the server index |
int lcbvb_k2vb | ( | lcbvb_CONFIG * | cfg, |
const void * | key, | ||
lcb_SIZE | n ) |
Maps a key to a vBucket ID
cfg | The configuration |
key | The key to retrieve |
n | The size of the key |
int lcbvb_has_vbucket | ( | lcbvb_CONFIG * | vbc, |
int | vbid, | ||
int | ix ) |
vbc | the configuration |
vbid | the vbucket number |
ix | the server index to check against |
ix
is either a master or a replica for the vbucket vbid
. Returns 0 otherwise. unsigned lcbvb_get_nservers | ( | const lcbvb_CONFIG * | cfg | ) |
Get the number of servers in the bucket. Note that not all servers may actually be available.
cfg | The configuration |
unsigned lcbvb_get_nreplicas | ( | const lcbvb_CONFIG * | cfg | ) |
Get the number of replicas the bucket is configured with Note that not all replicas may necessarily be online or available.
cfg | the configuration |
unsigned lcbvb_get_nvbuckets | ( | const lcbvb_CONFIG * | cfg | ) |
Get the number of vbuckets the bucket is configured with.
lcbvb_DISTMODE lcbvb_get_distmode | ( | const lcbvb_CONFIG * | cfg | ) |
Get the distribution mode (AKA bucket type) of the bucket.
cfg | the configuration |
int lcbvb_get_revision | ( | const lcbvb_CONFIG * | cfg | ) |
Get the revision for this configuration.
The revision is an integer which is increased each time the cluster generates a new configuration. This feature is available only on configurations generated by nodes of Couchbase Server v2.5 or later.
cfg | the configuration |
-1
if the config does not have a revision unsigned lcbvb_get_port | ( | lcbvb_CONFIG * | cfg, |
unsigned | ix, | ||
lcbvb_SVCTYPE | type, | ||
lcbvb_SVCMODE | mode ) |
Gets the port associated with a given service of a given mode on a given server.
cfg | the config object |
ix | the index of the server to query |
type | the type of service being provided |
mode | the mode of transport being used (e.g. plain, ssl) |
const char * lcbvb_get_hostport | ( | lcbvb_CONFIG * | cfg, |
unsigned | ix, | ||
lcbvb_SVCTYPE | type, | ||
lcbvb_SVCMODE | mode ) |
Return a string for the given service This is like lcbvb_get_port but returns a string in the form of host:port
rather than the numeric port.
cfg | |
ix | |
type | |
mode |
const char * lcbvb_get_hostname | ( | const lcbvb_CONFIG * | cfg, |
unsigned | ix ) |
Get the hostname of a given server index. This may be used if all nodes reside on different hostnames, and can be used to answer the question of "which node does this index belong to" without having to perform additional string processing on the port of the string.
cfg | the configuration |
ix | the index of the server to look up |
const char * lcbvb_get_resturl | ( | lcbvb_CONFIG * | cfg, |
unsigned | ix, | ||
lcbvb_SVCTYPE | type, | ||
lcbvb_SVCMODE | mode ) |
Function to return the URL prefix for a REST service.
Returns a string suitable for being passed as a URL. This is only valid for LCBVB_SVCTYPE_VIEWS and LCBVB_SVCTYPE_QUERY.
This function is different from lcbvb_get_hostport() – it is mainly a convenience, but does cache the string. Also, theoretically the cluster is free to choose a different URL prefix for a given service. Using this function will guarantee the URL prefix is correct.
int lcbvb_get_randhost | ( | const lcbvb_CONFIG * | cfg, |
lcbvb_SVCTYPE | type, | ||
lcbvb_SVCMODE | mode ) |
Convenience function to select a random node for a service.
int lcbvb_get_randhost_ex | ( | const lcbvb_CONFIG * | cfg, |
lcbvb_SVCTYPE | type, | ||
lcbvb_SVCMODE | mode, | ||
int * | used ) |
Get random node, excluding nodes already tried.
cfg | the config |
type | type of service |
mode | transport mode |
used | an array of integers representing server indexes (should be of size LCBVB_NSERVERS). Servers whose indexes in the used array are nonzero will be skipped. |
lcbvb_CONFIGDIFF * lcbvb_compare | ( | lcbvb_CONFIG * | from, |
lcbvb_CONFIG * | to ) |
Compare two configurations and return information on the changes.
from | the original configuration to use as the base |
to | the new configuration |
lcbvb_CHANGETYPE lcbvb_get_changetype | ( | lcbvb_CONFIGDIFF * | diff | ) |
Get a quick summary of the changes in the passed object.
diff | the diff returned from lcbvb_compare() |
int lcbvb_genconfig_ex | ( | lcbvb_CONFIG * | vb, |
const char * | name, | ||
const char * | uuid, | ||
const lcbvb_SERVER * | servers, | ||
unsigned | nservers, | ||
unsigned | nreplica, | ||
unsigned | nvbuckets ) |
Generate a sample configuration.
vb | a new configuration object returned via lcbvb_create() |
name | the name of the bucket |
uuid | UUID for the bucket |
servers | an array of server objects which will serve as the basis for the server list within the configuration. The memory pointed to by servers may be released after this function has completed |
nservers | number of servers in the array |
nreplica | how many replicas for the bucket |
nvbuckets | how many vbuckets for the bucket |
int lcbvb_genconfig | ( | lcbvb_CONFIG * | vb, |
unsigned | nservers, | ||
unsigned | nreplica, | ||
unsigned | nvbuckets ) |
Generate a sample configuration used for testing.
vb | a new configuration object returned via lcbvb_create() |
nservers | how many nodes to place into the configuration |
nreplica | how many replicas should be assigned to the bucket |
nvbuckets | how many vbuckets to create |
void lcbvb_genffmap | ( | lcbvb_CONFIG * | vb | ) |
void lcbvb_make_ketama | ( | lcbvb_CONFIG * | vb | ) |
const char * lcbvb_get_capibase | ( | lcbvb_CONFIG * | cfg, |
unsigned | ix, | ||
lcbvb_SVCMODE | mode ) |
Get the views URL base.
cfg | The configuration |
ix | The index of the server to fetch |
mode | The mode, either plain or ssl |
struct lcbvb_SERVICES |
Services which may be provided by a node.
struct lcbvb_SERVER |
Node in the cluster This structure represents a node in the cluster. The node has a hostname (hostname), and various services.
Data Fields | ||
---|---|---|
lcbvb_SERVICES | svc | Plain services. |
lcbvb_SERVICES | svc_ssl | SSL Services. |
char * | authority | host:dataport for comparison |
char * | hostname | Hostname for the node. |
char * | viewpath | Path prefix for view queries. |
char * | querypath | Path prefix for n1ql queries. |
char * | ftspath | Path prefix for fulltext queries. |
char * | cbaspath | Path prefix for analytics queries. |
char * | eventingpath | Path prefix for eventing service. |
unsigned | nvbs | Total number of vbuckets the server has assigned. |
char * | alt_hostname | selected alternative hostname for the node |
lcbvb_SERVICES | alt_svc | selected alternative plain services |
lcbvb_SERVICES | alt_svc_ssl | selected alternative SSL Services |
char * | server_group | the group name or NULL |
struct lcbvb_VBUCKET |
Data Fields | ||
---|---|---|
int | servers[4] |
struct lcbvb_CONFIG |
Structure containing the configuration.
Data Fields | ||
---|---|---|
lcbvb_DISTMODE | dtype | Type of bucket/distribution. |
unsigned | nvb | Number of vbuckets. |
unsigned | ndatasrv | Number of data (memcached) servers. |
unsigned | nsrv | |
unsigned | nrepl |
Number of servers. Number of replicas |
unsigned | ncontinuum | |
unsigned | is3x | |
int64_t | revepoch | |
int64_t | revid | |
char * | buuid | |
char * | bname | |
size_t | bname_len | |
const char * | errstr | |
lcbvb_SERVER * | servers | |
lcbvb_VBUCKET * | vbuckets | |
lcbvb_VBUCKET * | ffvbuckets | |
lcbvb_CONTINUUM * | continuum | |
int * | randbuf | |
uint64_t | caps | Bucket capabilities. |
uint64_t | ccaps | Cluster capabilities. |
struct lcbvb_CONFIGDIFF |
Structure representing changes between two configurations.
#define lcbvb_vbserver | ( | cfg, | |
vbid, | |||
ix ) |
#define lcbvb_nmv_remap | ( | cfg, | |
vbid, | |||
bad ) |
uncommitted Equivalent to
enum lcbvb_SVCTYPE |
This enum functions as a 'key' to indicate a specific service offered by a node.
enum lcbvb_SVCMODE |
enum lcbvb_DISTMODE |
enum lcbvb_CHANGETYPE |