Couchbase C Client  3.3.14
Asynchronous C Client for Couchbase
vbucket.h
Go to the documentation of this file.
1/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2014-2020 Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef LCB_VBUCKET_H
19#define LCB_VBUCKET_H
20#include <libcouchbase/visibility.h>
21#include <libcouchbase/sysdefs.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
47typedef enum {
57/* for backward compatiblity */
58#define LCBVB_SVCTYPE_CBAS LCBVB_SVCTYPE_ANALYTICS
59 LCBVB_SVCTYPE__MAX
61
64typedef enum {
67 LCBVB_SVCMODE__MAX
69
74typedef struct {
75 lcb_U16 data;
76 lcb_U16 mgmt;
77 lcb_U16 views;
78 lcb_U16 ixquery;
79 lcb_U16 ixadmin;
80 lcb_U16 n1ql;
81 lcb_U16 fts;
82 lcb_U16 cbas;
83 lcb_U16 eventing;
86 char *fts_base_;
87 char *cbas_base_;
88 char *eventing_base_;
89 char *hoststrs[LCBVB_SVCTYPE__MAX];
91
115
117typedef struct {
118 int servers[4];
120
122typedef struct {
123 lcb_U32 index;
124 lcb_U32 point;
126
134
135typedef enum {
136 LCBVB_CAP_XATTR = 1 << 0,
137 LCBVB_CAP_CBHELLO = 1 << 1,
138 LCBVB_CAP_CCCP = 1 << 2,
139 LCBVB_CAP_COUCHAPI = 1 << 3,
140 LCBVB_CAP_DCP = 1 << 4,
141 LCBVB_CAP_NODES_EXT = 1 << 5,
142 LCBVB_CAP_TOUCH = 1 << 6,
143 LCBVB_CAP_XDCR_CHECKPOINTING = 1 << 7,
144 LCBVB_CAP_COLLECTIONS = 1 << 8,
145 LCBVB_CAP_DURABLE_WRITE = 1 << 9,
146 LCBVB_CAP_TOMBSTONED_USER_XATTRS = 1 << 10
147} lcbvb_BUCKET_CAPABILITIES;
148
149typedef enum {
150 LCBVB_CCAP_N1QL_ENHANCED_PREPARED_STATEMENTS = 1 << 0,
151} lcbvb_CLUSTER_CAPABILITIES;
152
155typedef struct lcbvb_CONFIG_st {
157 unsigned nvb;
158 unsigned ndatasrv;
159 unsigned nsrv;
160 unsigned nrepl;
161 unsigned ncontinuum; /* number of continuum points */
162 unsigned is3x; /* whether server 3.0 config semantics are in place */
163 int64_t revepoch; /* revision Epoch from the config (-1 if not present) */
164 int64_t revid; /* revision ID from the config (-1 if not present) */
165 char *buuid; /* bucket UUID */
166 char *bname; /* bucket name */
167 size_t bname_len; /* bucket name */
168 const char *errstr; /* last error */
169 lcbvb_SERVER *servers; /* nodes */
170 lcbvb_VBUCKET *vbuckets; /* vbucket map */
171 lcbvb_VBUCKET *ffvbuckets; /* fast-forward map */
172 lcbvb_CONTINUUM *continuum; /* ketama continuums */
173 int *randbuf; /* Used for random server selection */
174 uint64_t caps;
175 uint64_t ccaps;
177
178#define LCBVB_BUCKET_NAME(cfg) (cfg)->bname
179#define LCBVB_NSERVERS(cfg) (cfg)->nsrv
180#define LCBVB_NDATASERVERS(cfg) (cfg)->ndatasrv
181#define LCBVB_NREPLICAS(cfg) (cfg)->nrepl
182#define LCBVB_DISTTYPE(cfg) (cfg)->dtype
183#define LCBVB_CAPS(cfg) (cfg)->caps
184#define LCBVB_CCAPS(cfg) (cfg)->ccaps
185#define LCBVB_GET_SERVER(conf, ix) ((conf)->servers + ix)
186
200LIBCOUCHBASE_API
202
209LIBCOUCHBASE_API
211
229LIBCOUCHBASE_API
230int lcbvb_load_json(lcbvb_CONFIG *vbc, const char *data);
231
235LIBCOUCHBASE_API
236int lcbvb_load_json_ex(lcbvb_CONFIG *vbc, const char *data, const char *source, char **network);
237
243LIBCOUCHBASE_API
245
251LIBCOUCHBASE_API
252const char *lcbvb_get_error(const lcbvb_CONFIG *vbc);
253
264LIBCOUCHBASE_API
265void lcbvb_replace_host(lcbvb_CONFIG *cfg, const char *hostname);
266
272LIBCOUCHBASE_API
274
285LIBCOUCHBASE_API
286int lcbvb_vbmaster(lcbvb_CONFIG *cfg, int vbid);
287
301LIBCOUCHBASE_API
302int lcbvb_vbreplica(lcbvb_CONFIG *cfg, int vbid, unsigned ix);
303
310#define lcbvb_vbserver(cfg, vbid, ix) ((ix == 0) ? lcbvb_vbmaster(cfg, vbid) : lcbvb_vbreplica(cfg, vbid, ix - 1))
311
319#define lcbvb_nmv_remap(cfg, vbid, bad) lcbvb_nmv_remap_ex(cfg, vbid, bad, 0)
320
336int lcbvb_nmv_remap_ex(lcbvb_CONFIG *cfg, int vbid, int bad, int use_heuristics);
337
349LIBCOUCHBASE_API
350int lcbvb_map_key(lcbvb_CONFIG *cfg, const void *key, lcb_SIZE n, int *vbid, int *srvix);
351
361LIBCOUCHBASE_API
362int lcbvb_k2vb(lcbvb_CONFIG *cfg, const void *key, lcb_SIZE n);
363
374LIBCOUCHBASE_API
375int lcbvb_has_vbucket(lcbvb_CONFIG *vbc, int vbid, int ix);
376
383LIBCOUCHBASE_API
384unsigned lcbvb_get_nservers(const lcbvb_CONFIG *cfg);
385
392LIBCOUCHBASE_API
394
399LIBCOUCHBASE_API
401
407LIBCOUCHBASE_API
409
423LIBCOUCHBASE_API
425
436LIBCOUCHBASE_API
437unsigned lcbvb_get_port(lcbvb_CONFIG *cfg, unsigned ix, lcbvb_SVCTYPE type, lcbvb_SVCMODE mode);
438
454LIBCOUCHBASE_API
455const char *lcbvb_get_hostport(lcbvb_CONFIG *cfg, unsigned ix, lcbvb_SVCTYPE type, lcbvb_SVCMODE mode);
456
469LIBCOUCHBASE_API
470const char *lcbvb_get_hostname(const lcbvb_CONFIG *cfg, unsigned ix);
471
483LIBCOUCHBASE_API
484const char *lcbvb_get_resturl(lcbvb_CONFIG *cfg, unsigned ix, lcbvb_SVCTYPE type, lcbvb_SVCMODE mode);
485
491LIBCOUCHBASE_API
493
507LIBCOUCHBASE_API
508int lcbvb_get_randhost_ex(const lcbvb_CONFIG *cfg, lcbvb_SVCTYPE type, lcbvb_SVCMODE mode, int *used);
509
523
531 VBUCKET_CHANGE_STATUS;
532
543LIBCOUCHBASE_API
545
547LIBCOUCHBASE_API
549
553LIBCOUCHBASE_API
555
570LIBCOUCHBASE_API
571int lcbvb_genconfig_ex(lcbvb_CONFIG *vb, const char *name, const char *uuid, const lcbvb_SERVER *servers,
572 unsigned nservers, unsigned nreplica, unsigned nvbuckets);
573
589LIBCOUCHBASE_API
590int lcbvb_genconfig(lcbvb_CONFIG *vb, unsigned nservers, unsigned nreplica, unsigned nvbuckets);
591
597LIBCOUCHBASE_API
599
605LIBCOUCHBASE_API
607
617LIBCOUCHBASE_API
618const char *lcbvb_get_capibase(lcbvb_CONFIG *cfg, unsigned ix, lcbvb_SVCMODE mode);
621/*the rest of these symbols are deprecated and should not be touched by
622 * doxygen */
623
624typedef enum { LIBVBUCKET_SOURCE_FILE, LIBVBUCKET_SOURCE_MEMORY } vbucket_source_t;
625
628#define VBUCKET_DISTRIBUTION_VBUCKET LCBVB_DIST_VBUCKET
629#define VBUCKET_DISTRIBUTION_KETAMA LCBVB_DIST_KETAMA
630#define VBUCKET_NO_CHANGES LCBVB_NO_CHANGES
631#define VBUCKET_SERVERS_MODIFIED LCBVB_SERVERS_MODIFIED
632#define VBUCKET_MAP_MODIFIED LCVBVB_MAP_MODIFIED
633
634LIBCOUCHBASE_API int vbucket_config_parse(lcbvb_CONFIG *, vbucket_source_t, const char *);
635LIBCOUCHBASE_API const char *vbucket_get_error_message(lcbvb_CONFIG *);
636LIBCOUCHBASE_API lcbvb_CONFIG *vbucket_config_create(void);
637LIBCOUCHBASE_API void vbucket_config_destroy(lcbvb_CONFIG *);
638LIBCOUCHBASE_API int vbucket_config_get_num_replicas(lcbvb_CONFIG *);
639LIBCOUCHBASE_API int vbucket_config_get_num_vbuckets(lcbvb_CONFIG *);
640LIBCOUCHBASE_API int vbucket_config_get_num_servers(lcbvb_CONFIG *);
641LIBCOUCHBASE_API const char *vbucket_config_get_server(lcbvb_CONFIG *, int);
642LIBCOUCHBASE_API const char *vbucket_config_get_couch_api_base(lcbvb_CONFIG *, int);
643LIBCOUCHBASE_API const char *vbucket_config_get_rest_api_server(lcbvb_CONFIG *, int);
644LIBCOUCHBASE_API lcbvb_DISTMODE vbucket_config_get_distribution_type(lcbvb_CONFIG *);
645LIBCOUCHBASE_API int vbucket_map(lcbvb_CONFIG *, const void *, lcb_SIZE, int *, int *);
646LIBCOUCHBASE_API int vbucket_get_vbucket_by_key(lcbvb_CONFIG *, const void *, lcb_SIZE);
647LIBCOUCHBASE_API int vbucket_get_master(lcbvb_CONFIG *, int);
648LIBCOUCHBASE_API int vbucket_get_replica(lcbvb_CONFIG *, int, int);
649LIBCOUCHBASE_API lcbvb_CONFIGDIFF *vbucket_compare(lcbvb_CONFIG *, lcbvb_CONFIG *);
650LIBCOUCHBASE_API void vbucket_free_diff(lcbvb_CONFIGDIFF *);
651LIBCOUCHBASE_API int vbucket_config_get_revision(lcbvb_CONFIG *);
652LIBCOUCHBASE_API lcbvb_CHANGETYPE vbucket_what_changed(lcbvb_CONFIGDIFF *diff);
653LIBCOUCHBASE_API int vbucket_config_generate(lcbvb_CONFIG *vb, unsigned, unsigned, unsigned);
654
655#ifdef __cplusplus
656}
657#endif
658#endif
char * ftspath
Path prefix for fulltext queries.
Definition vbucket.h:106
char * cbaspath
Path prefix for analytics queries.
Definition vbucket.h:107
char * alt_hostname
selected alternative hostname for the node
Definition vbucket.h:110
lcbvb_SERVICES alt_svc_ssl
selected alternative SSL Services
Definition vbucket.h:112
lcb_U16 views
Port for view queries (HTTP)
Definition vbucket.h:77
int sequence_changed
Whether the ordering of the nodes has changed as well.
Definition vbucket.h:519
unsigned ndatasrv
Number of data (memcached) servers.
Definition vbucket.h:158
lcb_U16 n1ql
Query port.
Definition vbucket.h:80
lcb_U16 mgmt
Port for adminsitrative operations (HTTP)
Definition vbucket.h:76
lcb_U16 ixquery
Indexing query port.
Definition vbucket.h:78
char * views_base_
Views base URL.
Definition vbucket.h:84
char * eventingpath
Path prefix for eventing service.
Definition vbucket.h:108
lcbvb_SERVICES alt_svc
selected alternative plain services
Definition vbucket.h:111
lcb_U16 fts
CBFT.
Definition vbucket.h:81
lcb_U16 eventing
Eventing Management.
Definition vbucket.h:83
lcb_U16 data
Data port for key-value operations (memcached protocol)
Definition vbucket.h:75
lcbvb_DISTMODE dtype
Type of bucket/distribution.
Definition vbucket.h:156
unsigned nvb
Number of vbuckets.
Definition vbucket.h:157
lcbvb_SERVICES svc_ssl
SSL Services.
Definition vbucket.h:101
char * querypath
Path prefix for n1ql queries.
Definition vbucket.h:105
char * query_base_
N1QL base URL.
Definition vbucket.h:85
unsigned nvbs
Total number of vbuckets the server has assigned.
Definition vbucket.h:109
unsigned nrepl
Number of servers.
Definition vbucket.h:160
int n_repl_changed
Whether the number of the replicas has changed.
Definition vbucket.h:521
uint64_t caps
Bucket capabilities.
Definition vbucket.h:174
char ** servers_removed
List of strings of servers removed (via host:data_port)
Definition vbucket.h:515
char * viewpath
Path prefix for view queries.
Definition vbucket.h:104
char * authority
host:dataport for comparison
Definition vbucket.h:102
char * server_group
the group name or NULL
Definition vbucket.h:113
uint64_t ccaps
Cluster capabilities.
Definition vbucket.h:175
lcb_U16 cbas
CBAS (Analytics)
Definition vbucket.h:82
int n_vb_changes
How many vBuckets have had an ownership change.
Definition vbucket.h:517
char ** servers_added
List of strings of servers added (via host:data_port)
Definition vbucket.h:513
lcb_U16 ixadmin
Indexing admin port (HTTP)
Definition vbucket.h:79
char * hostname
Hostname for the node.
Definition vbucket.h:103
lcbvb_SERVICES svc
Plain services.
Definition vbucket.h:100
void lcbvb_replace_host(lcbvb_CONFIG *cfg, const char *hostname)
Replace hostname placeholders with specific host string This function shall replace hostname placehol...
int lcbvb_has_vbucket(lcbvb_CONFIG *vbc, int vbid, int ix)
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...
lcbvb_DISTMODE
Type of algorithm used to distribute keys.
Definition vbucket.h:129
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.
int lcbvb_get_randhost_ex(const lcbvb_CONFIG *cfg, lcbvb_SVCTYPE type, lcbvb_SVCMODE mode, int *used)
Get random node, excluding nodes already tried.
int lcbvb_k2vb(lcbvb_CONFIG *cfg, const void *key, lcb_SIZE n)
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 b...
lcbvb_CONFIGDIFF * lcbvb_compare(lcbvb_CONFIG *from, lcbvb_CONFIG *to)
Compare two configurations and return information on the changes.
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.
int lcbvb_genconfig(lcbvb_CONFIG *vb, unsigned nservers, unsigned nreplica, unsigned nvbuckets)
Generate a sample configuration used for testing.
int lcbvb_load_json(lcbvb_CONFIG *vbc, const char *data)
const char * lcbvb_get_error(const lcbvb_CONFIG *vbc)
Return a string indicating why parsing the configuration failed.
lcbvb_SVCMODE
This enum functions to indicate the 'mode' of the service.
Definition vbucket.h:64
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,...
unsigned lcbvb_get_nvbuckets(const lcbvb_CONFIG *cfg)
Get the number of vbuckets the bucket is configured with.
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...
void lcbvb_free_diff(lcbvb_CONFIGDIFF *diff)
Free the structure returned by lcbvb_compare()
lcbvb_DISTMODE lcbvb_get_distmode(const lcbvb_CONFIG *cfg)
Get the distribution mode (AKA bucket type) of the bucket.
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.
void lcbvb_destroy(lcbvb_CONFIG *conf)
int lcbvb_nmv_remap_ex(lcbvb_CONFIG *cfg, int vbid, int bad, int use_heuristics)
int lcbvb_get_revision(const lcbvb_CONFIG *cfg)
Get the revision for this configuration.
void lcbvb_genffmap(lcbvb_CONFIG *vb)
char * lcbvb_save_json(lcbvb_CONFIG *vbc)
Serialize the current config as a JSON string.
int lcbvb_map_key(lcbvb_CONFIG *cfg, const void *key, lcb_SIZE n, int *vbid, int *srvix)
const char * lcbvb_get_capibase(lcbvb_CONFIG *cfg, unsigned ix, lcbvb_SVCMODE mode)
lcbvb_CONFIG * lcbvb_parse_json(const char *data)
void lcbvb_make_ketama(lcbvb_CONFIG *vb)
int lcbvb_get_randhost(const lcbvb_CONFIG *cfg, lcbvb_SVCTYPE type, lcbvb_SVCMODE mode)
Convenience function to select a random node for a service.
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.
lcbvb_CHANGETYPE
Convenience enum to determine the mode of change.
Definition vbucket.h:525
lcbvb_SVCTYPE
This enum functions as a 'key' to indicate a specific service offered by a node.
Definition vbucket.h:47
lcbvb_CHANGETYPE lcbvb_get_changetype(lcbvb_CONFIGDIFF *diff)
Get a quick summary of the changes in the passed object.
int lcbvb_load_json_ex(lcbvb_CONFIG *vbc, const char *data, const char *source, char **network)
int lcbvb_vbmaster(lcbvb_CONFIG *cfg, int vbid)
int lcbvb_vbreplica(lcbvb_CONFIG *cfg, int vbid, unsigned ix)
@ LCBVB_DIST_KETAMA
Ketama hashing ("memcached") bucket.
Definition vbucket.h:131
@ LCBVB_DIST_UNKNOWN
Unknown distribution (cluster config)
Definition vbucket.h:132
@ LCBVB_DIST_VBUCKET
vBucket hashing ("couchbase") bucket
Definition vbucket.h:130
@ LCBVB_SVCMODE_SSL
SSL Transport.
Definition vbucket.h:66
@ LCBVB_SVCMODE_PLAIN
Plain transport.
Definition vbucket.h:65
@ LCBVB_NO_CHANGES
No changes between configs.
Definition vbucket.h:526
@ LCBVB_SERVERS_MODIFIED
Servers have been added or removed.
Definition vbucket.h:527
@ LCBVB_REPLICAS_MODIFIED
number of replicas has been modified
Definition vbucket.h:529
@ LCBVB_MAP_MODIFIED
vBuckets have been transferred
Definition vbucket.h:528
@ LCBVB_SVCTYPE_QUERY
N1QL Query.
Definition vbucket.h:53
@ LCBVB_SVCTYPE_DATA
memcached/Data port
Definition vbucket.h:48
@ LCBVB_SVCTYPE_VIEWS
Views/CAPI port.
Definition vbucket.h:49
@ LCBVB_SVCTYPE_ANALYTICS
Analytics Query.
Definition vbucket.h:55
@ LCBVB_SVCTYPE_IXQUERY
Index query.
Definition vbucket.h:51
@ LCBVB_SVCTYPE_IXADMIN
Index administration.
Definition vbucket.h:52
@ LCBVB_SVCTYPE_SEARCH
Fulltext.
Definition vbucket.h:54
@ LCBVB_SVCTYPE_EVENTING
Eventing Management.
Definition vbucket.h:56
@ LCBVB_SVCTYPE_MGMT
Administrative/'REST' UI.
Definition vbucket.h:50
Structure containing the configuration.
Definition vbucket.h:155
Structure representing changes between two configurations.
Definition vbucket.h:511
Definition vbucket.h:122
Node in the cluster This structure represents a node in the cluster. The node has a hostname (hostnam...
Definition vbucket.h:99
Services which may be provided by a node.
Definition vbucket.h:74
Definition vbucket.h:117