Couchbase C Client
2.4.4
|
These routines contain functionality for parsing a cluster topology configuration and mapping keys to cluster nodes appropriately.
Functions | |
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. More... | |
lcbvb_CONFIG * | lcbvb_parse_json (const char *data) |
int | lcbvb_load_json (lcbvb_CONFIG *vbc, const char *data) |
char * | lcbvb_save_json (lcbvb_CONFIG *vbc) |
Serialize the current config as a JSON string. More... | |
const char * | lcbvb_get_error (const lcbvb_CONFIG *vbc) |
Return a string indicating why parsing the configuration failed. More... | |
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 . More... | |
void | lcbvb_destroy (lcbvb_CONFIG *conf) |
int | lcbvb_vbmaster (lcbvb_CONFIG *cfg, int vbid) |
int | lcbvb_vbreplica (lcbvb_CONFIG *cfg, int vbid, unsigned ix) |
int | lcbvb_nmv_remap (lcbvb_CONFIG *cfg, int vbid, int bad) |
int | lcbvb_map_key (lcbvb_CONFIG *cfg, const void *key, lcb_SIZE n, int *vbid, int *srvix) |
int | lcbvb_k2vb (lcbvb_CONFIG *cfg, const void *key, lcb_SIZE n) |
int | lcbvb_has_vbucket (lcbvb_CONFIG *vbc, int vbid, int ix) |
uncommitted Determines if a given server index is either a master or a replica for a vbucket More... | |
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. More... | |
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. More... | |
lcbvb_DISTMODE | lcbvb_get_distmode (const lcbvb_CONFIG *cfg) |
Get the distribution mode (AKA bucket type) of the bucket. More... | |
int | lcbvb_get_revision (const lcbvb_CONFIG *cfg) |
Get the revision for this configuration. More... | |
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. More... | |
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. More... | |
lcbvb_CONFIGDIFF * | lcbvb_compare (lcbvb_CONFIG *from, lcbvb_CONFIG *to) |
Compare two configurations and return information on the changes. More... | |
void | lcbvb_free_diff (lcbvb_CONFIGDIFF *diff) |
Free the structure returned by lcbvb_compare() | |
lcbvb_CHANGETYPE | lcbvb_get_changetype (lcbvb_CONFIGDIFF *diff) |
Get a quick summary of the changes in the passed object. More... | |
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. More... | |
int | lcbvb_genconfig (lcbvb_CONFIG *vb, unsigned nservers, unsigned nreplica, unsigned nvbuckets) |
Generate a sample configuration used for testing. More... | |
void | lcbvb_make_ketama (lcbvb_CONFIG *vb) |
const char * | lcbvb_get_capibase (lcbvb_CONFIG *cfg, unsigned ix, lcbvb_SVCMODE mode) |
Macros | |
#define | LCBVB_NSERVERS(cfg) |
#define | LCBVB_NREPLICAS(cfg) |
#define | LCBVB_DISTTYPE(cfg) |
#define | LCBVB_GET_SERVER(conf, ix) |
Typedefs | |
typedef struct lcbvb_CONFIGDIFF | VBUCKET_CONFIG_DIFF |
typedef enum lcbvb_CHANGETYPE | VBUCKET_CHANGE_STATUS |
Enumerations | |
enum | lcbvb_SVCTYPE |
This enum functions as a 'key' to indicate a specific service offered by a node. More... | |
enum | lcbvb_SVCMODE |
This enum functions to indicate the 'mode' of the service. More... | |
enum | lcbvb_DISTMODE |
Type of algorithm used to distribute keys. More... | |
enum | lcbvb_CHANGETYPE |
Convenience enum to determine the mode of change. More... | |
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 |
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 | ) |
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 | ( | lcbvb_CONFIG * | cfg, |
int | vbid, | ||
int | bad | ||
) |
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 |
vbix | 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. |
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 | ||
) |
uncommitted Determines if a given server index is either a master or a replica for a vbucket
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 |
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 |
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_make_ketama | ( | lcbvb_CONFIG * | vb | ) |
vb | The configuration object. |
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. |
unsigned | nvbs | Total number of vbuckets the server has assigned. |
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 | nsrv | |
unsigned | nrepl |
Number of servers. Number of replicas |
unsigned | ncontinuum | |
unsigned | is3x | |
int | revid | |
char * | buuid | |
char * | bname | |
const char * | errstr | |
lcbvb_SERVER * | servers | |
lcbvb_VBUCKET * | vbuckets | |
lcbvb_VBUCKET * | ffvbuckets | |
lcbvb_CONTINUUM * | continuum |
struct lcbvb_CONFIGDIFF |
Structure representing changes between two configurations.
enum lcbvb_SVCTYPE |
enum lcbvb_SVCMODE |
enum lcbvb_DISTMODE |
enum lcbvb_CHANGETYPE |