Couchbase C Client  2.4.4
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 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
24 extern "C" {
25 #endif
26 
47 typedef enum {
51  LCBVB_SVCTYPE__MAX
53 
56 typedef enum {
59  LCBVB_SVCMODE__MAX
61 
66 typedef struct {
67  lcb_U16 data;
68  lcb_U16 mgmt;
69  lcb_U16 views;
70  char *views_base_;
71  char *hoststrs[LCBVB_SVCTYPE__MAX];
73 
81 typedef struct {
84  char *authority;
85  char *hostname;
86  char *viewpath;
87  unsigned nvbs;
88 } lcbvb_SERVER;
89 
91 typedef struct {
92  int servers[4];
94 
96 typedef struct {
97  lcb_U32 index;
98  lcb_U32 point;
100 
103 typedef enum {
107 
110 typedef struct {
112  unsigned nvb;
113  unsigned nsrv;
114  unsigned nrepl;
115  unsigned ncontinuum; /* number of continuum points */
116  unsigned is3x; /* whether server 3.0 config semantics are in place */
117  int revid; /* revision ID from the config (-1 if not present) */
118  char *buuid; /* bucket UUID */
119  char *bname; /* bucket name */
120  const char *errstr; /* last error */
121  lcbvb_SERVER *servers; /* nodes */
122  lcbvb_VBUCKET *vbuckets; /* vbucket map */
123  lcbvb_VBUCKET *ffvbuckets; /* fast-forward map */
124  lcbvb_CONTINUUM *continuum; /* ketama continuums */
125 } lcbvb_CONFIG;
126 
127 
128 #define LCBVB_NSERVERS(cfg) (cfg)->nsrv
129 #define LCBVB_NREPLICAS(cfg) (cfg)->nrepl
130 #define LCBVB_DISTTYPE(cfg) (cfg)->dtype
131 #define LCBVB_GET_SERVER(conf, ix) ((conf)->servers + ix)
132 
146 LIBCOUCHBASE_API
147 lcbvb_CONFIG *
148 lcbvb_create(void);
149 
156 LIBCOUCHBASE_API
157 lcbvb_CONFIG *
158 lcbvb_parse_json(const char *data);
159 
170 LIBCOUCHBASE_API
171 int
172 lcbvb_load_json(lcbvb_CONFIG *vbc, const char *data);
173 
179 LIBCOUCHBASE_API
180 char *
182 
188 LIBCOUCHBASE_API
189 const char *
190 lcbvb_get_error(const lcbvb_CONFIG *vbc);
191 
202 LIBCOUCHBASE_API
203 void
204 lcbvb_replace_host(lcbvb_CONFIG *cfg, const char *hostname);
205 
211 LIBCOUCHBASE_API
212 void
214 
225 LIBCOUCHBASE_API
226 int
227 lcbvb_vbmaster(lcbvb_CONFIG *cfg, int vbid);
228 
242 LIBCOUCHBASE_API
243 int
244 lcbvb_vbreplica(lcbvb_CONFIG *cfg, int vbid, unsigned ix);
245 
246 
260 int
261 lcbvb_nmv_remap(lcbvb_CONFIG *cfg, int vbid, int bad);
262 
274 LIBCOUCHBASE_API
275 int
276 lcbvb_map_key(lcbvb_CONFIG *cfg, const void *key, lcb_SIZE n,
277  int *vbid, int *srvix);
278 
288 LIBCOUCHBASE_API
289 int
290 lcbvb_k2vb(lcbvb_CONFIG *cfg, const void *key, lcb_SIZE n);
291 
302 LIBCOUCHBASE_API
303 int
304 lcbvb_has_vbucket(lcbvb_CONFIG *vbc, int vbid, int ix);
305 
312 LIBCOUCHBASE_API
313 unsigned
314 lcbvb_get_nservers(const lcbvb_CONFIG *cfg);
315 
322 LIBCOUCHBASE_API
323 unsigned
325 
331 LIBCOUCHBASE_API
333 lcbvb_get_distmode(const lcbvb_CONFIG *cfg);
334 
348 LIBCOUCHBASE_API
349 int
350 lcbvb_get_revision(const lcbvb_CONFIG *cfg);
351 
362 LIBCOUCHBASE_API
363 unsigned
364 lcbvb_get_port(lcbvb_CONFIG *cfg, unsigned ix,
365  lcbvb_SVCTYPE type, lcbvb_SVCMODE mode);
366 
367 
383 LIBCOUCHBASE_API
384 const char *
385 lcbvb_get_hostport(lcbvb_CONFIG *cfg, unsigned ix,
386  lcbvb_SVCTYPE type, lcbvb_SVCMODE mode);
387 
389 typedef struct {
399 
401 typedef enum {
405 } lcbvb_CHANGETYPE, VBUCKET_CHANGE_STATUS;
406 
417 LIBCOUCHBASE_API
420 
422 LIBCOUCHBASE_API
423 void
425 
429 LIBCOUCHBASE_API
432 
447 LIBCOUCHBASE_API
448 int
450  const char *name, const char *uuid,
451  const lcbvb_SERVER *servers,
452  unsigned nservers, unsigned nreplica, unsigned nvbuckets);
453 
469 LIBCOUCHBASE_API
470 int
472  unsigned nservers, unsigned nreplica, unsigned nvbuckets);
473 
474 
480 LIBCOUCHBASE_API
481 void
483 
493 LIBCOUCHBASE_API
494 const char *
495 lcbvb_get_capibase(lcbvb_CONFIG *cfg, unsigned ix, lcbvb_SVCMODE mode);
498 /*the rest of these symbols are deprecated and should not be touched by
499  * doxygen */
500 
501 typedef enum {
502  LIBVBUCKET_SOURCE_FILE,
503  LIBVBUCKET_SOURCE_MEMORY
504 } vbucket_source_t;
505 
508 #define VBUCKET_DISTRIBUTION_VBUCKET LCBVB_DIST_VBUCKET
509 #define VBUCKET_DISTRIBUTION_KETAMA LCBVB_DIST_KETAMA
510 #define VBUCKET_NO_CHANGES LCBVB_NO_CHANGES
511 #define VBUCKET_SERVERS_MODIFIED LCBVB_SERVERS_MODIFIED
512 #define VBUCKET_MAP_MODIFIED LCVBVB_MAP_MODIFIED
513 
514 LIBCOUCHBASE_API int vbucket_config_parse(lcbvb_CONFIG*,vbucket_source_t,const char*);
515 LIBCOUCHBASE_API const char *vbucket_get_error_message(lcbvb_CONFIG*);
516 LIBCOUCHBASE_API lcbvb_CONFIG* vbucket_config_create(void);
517 LIBCOUCHBASE_API void vbucket_config_destroy(lcbvb_CONFIG*);
518 LIBCOUCHBASE_API int vbucket_config_get_num_replicas(lcbvb_CONFIG*);
519 LIBCOUCHBASE_API int vbucket_config_get_num_vbuckets(lcbvb_CONFIG*);
520 LIBCOUCHBASE_API int vbucket_config_get_num_servers(lcbvb_CONFIG*);
521 LIBCOUCHBASE_API const char *vbucket_config_get_server(lcbvb_CONFIG*,int);
522 LIBCOUCHBASE_API const char *vbucket_config_get_couch_api_base(lcbvb_CONFIG*,int);
523 LIBCOUCHBASE_API const char *vbucket_config_get_rest_api_server(lcbvb_CONFIG*,int);
524 LIBCOUCHBASE_API lcbvb_DISTMODE vbucket_config_get_distribution_type(lcbvb_CONFIG*);
525 LIBCOUCHBASE_API int vbucket_map(lcbvb_CONFIG*,const void*,lcb_SIZE,int*,int*);
526 LIBCOUCHBASE_API int vbucket_get_vbucket_by_key(lcbvb_CONFIG*,const void*,lcb_SIZE);
527 LIBCOUCHBASE_API int vbucket_get_master(lcbvb_CONFIG*,int);
528 LIBCOUCHBASE_API int vbucket_get_replica(lcbvb_CONFIG*,int,int);
529 LIBCOUCHBASE_API lcbvb_CONFIGDIFF* vbucket_compare(lcbvb_CONFIG*,lcbvb_CONFIG*);
530 LIBCOUCHBASE_API void vbucket_free_diff(lcbvb_CONFIGDIFF*);
531 LIBCOUCHBASE_API int vbucket_config_get_revision(lcbvb_CONFIG*);
532 LIBCOUCHBASE_API lcbvb_CHANGETYPE vbucket_what_changed(lcbvb_CONFIGDIFF *diff);
533 LIBCOUCHBASE_API int vbucket_config_generate(lcbvb_CONFIG *vb, unsigned, unsigned, unsigned);
534 
535 
536 #ifdef __cplusplus
537 }
538 #endif
539 #endif
int n_vb_changes
How many vBuckets have had an ownership change.
Definition: vbucket.h:395
int lcbvb_get_revision(const lcbvb_CONFIG *cfg)
Get the revision for this configuration.
lcb_U16 mgmt
Port for adminsitrative operations (HTTP)
Definition: vbucket.h:68
char * hostname
Hostname for the node.
Definition: vbucket.h:85
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...
Servers have been added or removed.
Definition: vbucket.h:403
char * lcbvb_save_json(lcbvb_CONFIG *vbc)
Serialize the current config as a JSON string.
int lcbvb_nmv_remap(lcbvb_CONFIG *cfg, int vbid, int bad)
Services which may be provided by a node.
Definition: vbucket.h:66
unsigned nrepl
Number of servers.
Definition: vbucket.h:114
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_SVCTYPE
This enum functions as a 'key' to indicate a specific service offered by a node.
Definition: vbucket.h:47
lcbvb_DISTMODE
Type of algorithm used to distribute keys.
Definition: vbucket.h:103
int lcbvb_vbreplica(lcbvb_CONFIG *cfg, int vbid, unsigned ix)
unsigned nvb
Number of vbuckets.
Definition: vbucket.h:112
lcbvb_SERVICES svc_ssl
SSL Services.
Definition: vbucket.h:83
unsigned nvbs
Total number of vbuckets the server has assigned.
Definition: vbucket.h:87
Structure representing changes between two configurations.
Definition: vbucket.h:389
Definition: vbucket.h:91
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...
char ** servers_added
List of strings of servers added (via host:data_port)
Definition: vbucket.h:391
lcbvb_CHANGETYPE lcbvb_get_changetype(lcbvb_CONFIGDIFF *diff)
Get a quick summary of the changes in the passed object.
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 ...
const char * lcbvb_get_capibase(lcbvb_CONFIG *cfg, unsigned ix, lcbvb_SVCMODE mode)
lcbvb_SERVICES svc
Plain services.
Definition: vbucket.h:82
vBuckets have been transferred
Definition: vbucket.h:404
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_vbmaster(lcbvb_CONFIG *cfg, int vbid)
char * viewpath
Path prefix for view queries.
Definition: vbucket.h:86
memcached/Data port
Definition: vbucket.h:48
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...
Plain transport.
Definition: vbucket.h:57
Administrative/'REST' UI.
Definition: vbucket.h:50
lcbvb_DISTMODE lcbvb_get_distmode(const lcbvb_CONFIG *cfg)
Get the distribution mode (AKA bucket type) of the bucket.
int lcbvb_load_json(lcbvb_CONFIG *vbc, const char *data)
int lcbvb_map_key(lcbvb_CONFIG *cfg, const void *key, lcb_SIZE n, int *vbid, int *srvix)
lcbvb_DISTMODE dtype
Type of bucket/distribution.
Definition: vbucket.h:111
int sequence_changed
Whether the ordering of the nodes has changed as well.
Definition: vbucket.h:397
lcbvb_CONFIG * lcbvb_parse_json(const char *data)
void lcbvb_make_ketama(lcbvb_CONFIG *vb)
char ** servers_removed
List of strings of servers removed (via host:data_port)
Definition: vbucket.h:393
lcb_U16 data
Data port for key-value operations (memcached protocol)
Definition: vbucket.h:67
lcbvb_CONFIGDIFF * lcbvb_compare(lcbvb_CONFIG *from, lcbvb_CONFIG *to)
Compare two configurations and return information on the changes.
No changes between configs.
Definition: vbucket.h:402
int lcbvb_genconfig(lcbvb_CONFIG *vb, unsigned nservers, unsigned nreplica, unsigned nvbuckets)
Generate a sample configuration used for testing.
vBucket hashing ("couchbase") bucket
Definition: vbucket.h:104
Definition: vbucket.h:96
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.
char * views_base_
Views base URL.
Definition: vbucket.h:70
void lcbvb_replace_host(lcbvb_CONFIG *cfg, const char *hostname)
Replace hostname placeholders with specific host string This function shall replace hostname placehol...
lcb_U16 views
Port for view queries (HTTP)
Definition: vbucket.h:69
Node in the cluster This structure represents a node in the cluster. The node has a hostname (hostnam...
Definition: vbucket.h:81
SSL Transport.
Definition: vbucket.h:58
void lcbvb_destroy(lcbvb_CONFIG *conf)
void lcbvb_free_diff(lcbvb_CONFIGDIFF *diff)
Free the structure returned by lcbvb_compare()
lcbvb_SVCMODE
This enum functions to indicate the 'mode' of the service.
Definition: vbucket.h:56
Ketama hashing ("memcached") bucket.
Definition: vbucket.h:105
Views/CAPI port.
Definition: vbucket.h:49
char * authority
host:dataport for comparison
Definition: vbucket.h:84
int lcbvb_k2vb(lcbvb_CONFIG *cfg, const void *key, lcb_SIZE n)
lcbvb_CHANGETYPE
Convenience enum to determine the mode of change.
Definition: vbucket.h:401
Structure containing the configuration.
Definition: vbucket.h:110
const char * lcbvb_get_error(const lcbvb_CONFIG *vbc)
Return a string indicating why parsing the configuration failed.