libcouchbase 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +1 -1
  4. data/ext/libcouchbase/CMakeLists.txt +8 -6
  5. data/ext/libcouchbase/README.markdown +2 -2
  6. data/ext/libcouchbase/RELEASE_NOTES.markdown +0 -86
  7. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +0 -11
  8. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +0 -2
  9. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +1 -2
  10. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  11. data/ext/libcouchbase/cmake/config-cmake.h.in +0 -2
  12. data/ext/libcouchbase/cmake/defs.mk.in +2 -0
  13. data/ext/libcouchbase/cmake/source_files.cmake +5 -21
  14. data/ext/libcouchbase/include/libcouchbase/auth.h +0 -10
  15. data/ext/libcouchbase/include/libcouchbase/cntl.h +1 -27
  16. data/ext/libcouchbase/include/libcouchbase/error.h +1 -15
  17. data/ext/libcouchbase/include/libcouchbase/n1ql.h +1 -13
  18. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
  19. data/ext/libcouchbase/include/libcouchbase/subdoc.h +0 -9
  20. data/ext/libcouchbase/include/libcouchbase/views.h +1 -7
  21. data/ext/libcouchbase/include/libcouchbase/visibility.h +0 -1
  22. data/ext/libcouchbase/include/memcached/protocol_binary.h +1131 -29
  23. data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
  24. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  25. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +2 -3
  26. data/ext/libcouchbase/src/README.md +2 -0
  27. data/ext/libcouchbase/src/auth-priv.h +0 -1
  28. data/ext/libcouchbase/src/auth.cc +4 -10
  29. data/ext/libcouchbase/src/bootstrap.c +269 -0
  30. data/ext/libcouchbase/src/bootstrap.h +39 -50
  31. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +117 -84
  32. data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
  33. data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
  34. data/ext/libcouchbase/src/bucketconfig/bc_http.h +25 -50
  35. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
  36. data/ext/libcouchbase/src/bucketconfig/clconfig.h +386 -407
  37. data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
  38. data/ext/libcouchbase/src/cbft.cc +27 -22
  39. data/ext/libcouchbase/src/cntl.cc +19 -30
  40. data/ext/libcouchbase/src/connspec.cc +1 -48
  41. data/ext/libcouchbase/src/connspec.h +0 -27
  42. data/ext/libcouchbase/src/dump.cc +2 -2
  43. data/ext/libcouchbase/src/getconfig.cc +33 -7
  44. data/ext/libcouchbase/src/handler.cc +2 -0
  45. data/ext/libcouchbase/src/hostlist.cc +36 -0
  46. data/ext/libcouchbase/src/hostlist.h +62 -41
  47. data/ext/libcouchbase/src/http/http-priv.h +112 -125
  48. data/ext/libcouchbase/src/http/http.cc +30 -15
  49. data/ext/libcouchbase/src/http/http.h +34 -1
  50. data/ext/libcouchbase/src/http/http_io.cc +26 -22
  51. data/ext/libcouchbase/src/instance.cc +23 -94
  52. data/ext/libcouchbase/src/internal.h +26 -52
  53. data/ext/libcouchbase/src/jsparse/parser.cc +202 -146
  54. data/ext/libcouchbase/src/jsparse/parser.h +98 -91
  55. data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
  56. data/ext/libcouchbase/src/lcbht/lcbht.h +163 -174
  57. data/ext/libcouchbase/src/lcbio/connect.c +557 -0
  58. data/ext/libcouchbase/src/lcbio/connect.h +2 -9
  59. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  60. data/ext/libcouchbase/src/lcbio/iotable.h +16 -61
  61. data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
  62. data/ext/libcouchbase/src/lcbio/manager.c +2 -2
  63. data/ext/libcouchbase/src/mc/mcreq.h +2 -9
  64. data/ext/libcouchbase/src/mcserver/mcserver.cc +34 -143
  65. data/ext/libcouchbase/src/mcserver/mcserver.h +12 -7
  66. data/ext/libcouchbase/src/mcserver/negotiate.cc +38 -132
  67. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
  68. data/ext/libcouchbase/src/n1ql/n1ql.cc +32 -56
  69. data/ext/libcouchbase/src/newconfig.cc +6 -6
  70. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  71. data/ext/libcouchbase/src/operations/{cbflush.cc → cbflush.c} +15 -7
  72. data/ext/libcouchbase/src/operations/{counter.cc → counter.c} +0 -0
  73. data/ext/libcouchbase/src/operations/durability.cc +26 -6
  74. data/ext/libcouchbase/src/operations/durability_internal.h +3 -6
  75. data/ext/libcouchbase/src/operations/{get.cc → get.c} +26 -24
  76. data/ext/libcouchbase/src/operations/{observe.cc → observe.c} +93 -68
  77. data/ext/libcouchbase/src/operations/{pktfwd.cc → pktfwd.c} +0 -0
  78. data/ext/libcouchbase/src/operations/{remove.cc → remove.c} +0 -0
  79. data/ext/libcouchbase/src/operations/stats.cc +8 -3
  80. data/ext/libcouchbase/src/operations/{store.cc → store.c} +32 -27
  81. data/ext/libcouchbase/src/operations/subdoc.cc +18 -38
  82. data/ext/libcouchbase/src/operations/{touch.cc → touch.c} +0 -0
  83. data/ext/libcouchbase/src/packetutils.c +37 -0
  84. data/ext/libcouchbase/src/packetutils.h +2 -2
  85. data/ext/libcouchbase/src/probes.d +1 -1
  86. data/ext/libcouchbase/src/{retrychk.cc → retrychk.c} +3 -2
  87. data/ext/libcouchbase/src/retryq.cc +4 -4
  88. data/ext/libcouchbase/src/settings.c +0 -3
  89. data/ext/libcouchbase/src/settings.h +0 -5
  90. data/ext/libcouchbase/src/simplestring.c +211 -0
  91. data/ext/libcouchbase/src/simplestring.h +228 -0
  92. data/ext/libcouchbase/src/ssl/ssl_c.c +0 -1
  93. data/ext/libcouchbase/src/ssl/ssl_common.c +0 -2
  94. data/ext/libcouchbase/src/ssl/ssl_e.c +1 -0
  95. data/ext/libcouchbase/src/ssobuf.h +82 -0
  96. data/ext/libcouchbase/src/trace.h +4 -4
  97. data/ext/libcouchbase/src/vbucket/vbucket.c +1 -0
  98. data/ext/libcouchbase/src/views/{docreq.cc → docreq.c} +54 -48
  99. data/ext/libcouchbase/src/views/docreq.h +30 -24
  100. data/ext/libcouchbase/src/views/viewreq.c +358 -0
  101. data/ext/libcouchbase/src/views/viewreq.h +13 -43
  102. data/ext/libcouchbase/tests/basic/t_connstr.cc +50 -89
  103. data/ext/libcouchbase/tests/basic/t_host.cc +75 -67
  104. data/ext/libcouchbase/tests/basic/t_jsparse.cc +78 -27
  105. data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
  106. data/ext/libcouchbase/tests/htparse/t_basic.cc +78 -58
  107. data/ext/libcouchbase/tests/iotests/mock-environment.h +1 -2
  108. data/ext/libcouchbase/tests/iotests/t_confmon.cc +114 -96
  109. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  110. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
  111. data/lib/libcouchbase/ext/tasks.rb +6 -2
  112. data/lib/libcouchbase/query_view.rb +1 -1
  113. data/lib/libcouchbase/results_fiber.rb +6 -6
  114. data/lib/libcouchbase/version.rb +1 -1
  115. metadata +26 -26
  116. data/ext/libcouchbase/src/bootstrap.cc +0 -216
  117. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +0 -281
  118. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +0 -528
  119. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +0 -115
  120. data/ext/libcouchbase/src/bucketconfig/confmon.cc +0 -378
  121. data/ext/libcouchbase/src/dns-srv.cc +0 -142
  122. data/ext/libcouchbase/src/errmap.cc +0 -107
  123. data/ext/libcouchbase/src/errmap.h +0 -113
  124. data/ext/libcouchbase/src/lcbht/lcbht.cc +0 -177
  125. data/ext/libcouchbase/src/lcbio/connect.cc +0 -562
  126. data/ext/libcouchbase/src/lcbio/timer-cxx.h +0 -87
  127. data/ext/libcouchbase/src/mctx-helper.h +0 -51
  128. data/ext/libcouchbase/src/views/viewreq.cc +0 -318
  129. data/ext/libcouchbase/tests/iotests/t_errmap.cc +0 -97
@@ -26,82 +26,57 @@
26
26
 
27
27
  #include "config.h"
28
28
  #include "hostlist.h"
29
+ #include "simplestring.h"
29
30
  #include "clconfig.h"
30
31
  #include <lcbht/lcbht.h>
31
32
 
32
- #define REQBUCKET_COMPAT_PREFIX "/pools/default/bucketsStreaming/"
33
- #define REQBUCKET_TERSE_PREFIX "/pools/default/bs/"
34
-
35
- #define REQPOOLS_URI "/pools/"
33
+ #define REQBUCKET_COMPAT_FMT "GET /pools/default/bucketsStreaming/%s HTTP/1.1\r\n"
34
+ #define REQBUCKET_TERSE_FMT "GET /pools/default/bs/%s HTTP/1.1\r\n"
35
+ #define REQPOOLS_FMT "GET /pools/ HTTP/1.1\r\n"
36
36
  #define HOSTHDR_FMT "Host: %s:%s\r\n"
37
+ #define AUTHDR_FMT "Authorization: Basic %s\r\n"
37
38
  #define LAST_HTTP_HEADER "X-Libcouchbase: " LCB_VERSION_STRING "\r\n"
38
39
  #define CONFIG_DELIMITER "\n\n\n\n"
39
40
 
40
- namespace lcb {
41
- namespace clconfig {
42
- struct HttpProvider : Provider {
43
- HttpProvider(Confmon*);
44
- ~HttpProvider();
45
-
46
- void reset_stream_state();
47
-
48
- void delayed_disconn();
49
- void delayed_reconnect();
50
- void on_timeout();
51
- lcb_error_t on_io_error(lcb_error_t origerr);
52
-
53
- /**
54
- * Closes the current connection and removes the disconn timer along with it
55
- */
56
- void close_current();
57
-
58
- bool is_v220_compat() const;
59
-
60
- lcb_error_t connect_next();
61
-
62
- /* Overrides */
63
- bool pause();
64
- lcb_error_t refresh();
65
- ConfigInfo* get_cached();
66
- void config_updated(lcbvb_CONFIG*);
67
- void configure_nodes(const lcb::Hostlist&);
68
- const lcb::Hostlist* get_nodes() const;
69
- void dump(FILE*) const;
70
- lcb_error_t setup_request_header(const lcb_host_t& host);
71
- /* END Overrides */
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
72
44
 
45
+ typedef struct clprovider_http_st {
73
46
  /** Base configuration structure */
47
+ clconfig_provider base;
74
48
  lcbio_pCONNSTART creq;
75
49
  lcbio_CTX *ioctx;
76
- lcb::htparse::Parser* htp;
50
+ lcbht_pPARSER htp;
77
51
 
78
52
  /**
79
53
  * Buffer to use for writing our request header. Recreated for each
80
54
  * connection because of the Host: header
81
55
  */
82
- std::string request_buf;
56
+ char request_buf[1024];
83
57
 
84
58
  /**
85
59
  * We only recreate the connection if our current stream 'times out'. This
86
60
  * timer waits until the current stream times out and then proceeds to the
87
61
  * next connection.
88
62
  */
89
- lcb::io::Timer<HttpProvider, &HttpProvider::delayed_disconn> disconn_timer;
90
- lcb::io::Timer<HttpProvider, &HttpProvider::on_timeout> io_timer;
91
- lcb::io::Timer<HttpProvider, &HttpProvider::delayed_reconnect> as_reconnect;
63
+ lcbio_pTIMER disconn_timer;
64
+ lcbio_pTIMER io_timer;
65
+ lcbio_pTIMER as_reconnect;
92
66
 
93
67
  /** List of hosts to try */
94
- lcb::Hostlist *nodes;
68
+ hostlist_t nodes;
95
69
 
96
70
  /** The cached configuration. */
97
- ConfigInfo *current_config;
98
- ConfigInfo *last_parsed;
99
-
71
+ clconfig_info *current_config;
72
+ clconfig_info *last_parsed;
100
73
  int generation;
101
- bool try_nexturi;
102
- int uritype;
103
- };
74
+ int try_nexturi;
75
+ lcb_HTCONFIG_URLTYPE uritype;
76
+ } http_provider;
77
+
78
+ #ifdef __cplusplus
79
+ }
80
+ #endif
104
81
 
105
- } // namespace
106
- } // namespace
107
82
  #endif /* LCB_CLPROVIDER_HTTP_H */
@@ -0,0 +1,150 @@
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
+ #include <lcbio/lcbio.h>
19
+ #include <lcbio/timer-ng.h>
20
+ #include <libcouchbase/vbucket.h>
21
+ #include "clconfig.h"
22
+
23
+ #define LOGARGS(mcr, lvlbase) mcr->base.parent->settings, "mcraw", LCB_LOG_##lvlbase, __FILE__, __LINE__
24
+ #define LOGFMT "(MCRAW=%p)> "
25
+ #define LOGID(mcr) (void *)mcr
26
+
27
+ /* Raw memcached provider */
28
+
29
+ typedef struct {
30
+ /* Base provider */
31
+ clconfig_provider base;
32
+ /* Current (user defined) configuration */
33
+ clconfig_info *config;
34
+ lcbio_pTIMER async;
35
+ } bc_MCRAW;
36
+
37
+
38
+ static void
39
+ async_update(void *arg)
40
+ {
41
+ bc_MCRAW *mcr = arg;
42
+ if (!mcr->config) {
43
+ lcb_log(LOGARGS(mcr, WARN), "No current config set. Not setting configuration");
44
+ return;
45
+ }
46
+ lcb_confmon_provider_success(&mcr->base, mcr->config);
47
+ }
48
+
49
+ static clconfig_info* get_cached(clconfig_provider *pb) {
50
+ return ((bc_MCRAW *)pb)->config;
51
+ }
52
+ static lcb_error_t get_refresh(clconfig_provider *pb) {
53
+ lcbio_async_signal( ((bc_MCRAW*)pb)->async );
54
+ return LCB_SUCCESS;
55
+ }
56
+ static lcb_error_t pause_mcr(clconfig_provider *pb) {
57
+ (void)pb;
58
+ return LCB_SUCCESS;
59
+ }
60
+
61
+ static void configure_nodes(clconfig_provider *pb, const hostlist_t hl)
62
+ {
63
+ bc_MCRAW *mcr = (bc_MCRAW *)pb;
64
+ lcbvb_SERVER *servers;
65
+ lcbvb_CONFIG *newconfig;
66
+ unsigned ii, nsrv;
67
+
68
+ nsrv = hostlist_size(hl);
69
+
70
+ if (!nsrv) {
71
+ lcb_log(LOGARGS(mcr, FATAL), "No nodes provided");
72
+ return;
73
+ }
74
+
75
+ servers = calloc(nsrv, sizeof(*servers));
76
+ for (ii = 0; ii < nsrv; ii++) {
77
+ int itmp;
78
+ const lcb_host_t *curhost = hostlist_get(hl, ii);
79
+ lcbvb_SERVER *srv = servers + ii;
80
+
81
+ /* just set the memcached port and hostname */
82
+ srv->hostname = (char *)curhost->host;
83
+ sscanf(curhost->port, "%d", &itmp);
84
+ srv->svc.data = itmp;
85
+ if (pb->parent->settings->sslopts) {
86
+ srv->svc_ssl.data = itmp;
87
+ }
88
+ }
89
+
90
+ newconfig = lcbvb_create();
91
+ lcbvb_genconfig_ex(newconfig, "NOBUCKET", "deadbeef", servers, nsrv, 0, 2);
92
+ lcbvb_make_ketama(newconfig);
93
+ newconfig->revid = -1;
94
+
95
+ if (mcr->config) {
96
+ lcb_clconfig_decref(mcr->config);
97
+ mcr->config = NULL;
98
+ }
99
+ mcr->config = lcb_clconfig_create(newconfig, LCB_CLCONFIG_MCRAW);
100
+ mcr->config->cmpclock = gethrtime();
101
+ }
102
+
103
+ lcb_error_t
104
+ lcb_clconfig_mcraw_update(clconfig_provider *pb, const char *nodes)
105
+ {
106
+ lcb_error_t err;
107
+ bc_MCRAW *mcr = (bc_MCRAW *)pb;
108
+ hostlist_t hl = hostlist_create();
109
+ err = hostlist_add_stringz(hl, nodes, LCB_CONFIG_MCCOMPAT_PORT);
110
+ if (err != LCB_SUCCESS) {
111
+ hostlist_destroy(hl);
112
+ return err;
113
+ }
114
+
115
+ configure_nodes(pb, hl);
116
+ hostlist_destroy(hl);
117
+ lcbio_async_signal(mcr->async);
118
+ return LCB_SUCCESS;
119
+ }
120
+
121
+ static void
122
+ mcraw_shutdown(clconfig_provider *pb)
123
+ {
124
+ bc_MCRAW *mcr = (bc_MCRAW *)pb;
125
+ if (mcr->config) {
126
+ lcb_clconfig_decref(mcr->config);
127
+ }
128
+ if (mcr->async) {
129
+ lcbio_timer_destroy(mcr->async);
130
+ }
131
+ free(mcr);
132
+ }
133
+
134
+ clconfig_provider *
135
+ lcb_clconfig_create_mcraw(lcb_confmon *parent)
136
+ {
137
+ bc_MCRAW *mcr = calloc(1, sizeof(*mcr));
138
+ if (!mcr) {
139
+ return NULL;
140
+ }
141
+ mcr->async = lcbio_timer_new(parent->iot, mcr, async_update);
142
+ mcr->base.parent = parent;
143
+ mcr->base.type = LCB_CLCONFIG_MCRAW;
144
+ mcr->base.get_cached = get_cached;
145
+ mcr->base.refresh = get_refresh;
146
+ mcr->base.pause = pause_mcr;
147
+ mcr->base.configure_nodes = configure_nodes;
148
+ mcr->base.shutdown = mcraw_shutdown;
149
+ return &mcr->base;
150
+ }
@@ -19,9 +19,12 @@
19
19
  #define LCB_CLCONFIG_H
20
20
 
21
21
  #include "hostlist.h"
22
- #include <list>
22
+ #include "list.h"
23
+ #include "simplestring.h"
23
24
  #include <lcbio/timer-ng.h>
24
- #include <lcbio/timer-cxx.h>
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
25
28
 
26
29
  /** @file */
27
30
 
@@ -42,22 +45,22 @@
42
45
  * <ol>
43
46
  *
44
47
  * <li>
45
- * There is a _Configuration Monitor_ object (Confmon) which acts
48
+ * There is a _Configuration Monitor_ object (lcb_confmon) which acts
46
49
  * as the configuration supervisor. It is responsible for returning
47
50
  * configuration objects to those entities which request it.
48
51
  * </li>
49
52
  *
50
53
  * <li>
51
- * There are multiple _Configuration Provider_ (Provider) objects.
54
+ * There are multiple _Configuration Provider_ (clconfig_provider) objects.
52
55
  * These providers aggregate configurations from multiple sources and
53
56
  * implement a common interface to:
54
57
  *
55
58
  * <ol>
56
59
  * <li>Return a _quick_ configuration without fetching from network or disk
57
- * (see Provider::get_cached())</i>
60
+ * (see clconfig_provider::get_cached())</i>
58
61
 
59
62
  * <li>Schedule a refresh to retrieve the latest configuration from the
60
- * network (see Provider::refresh())</li>
63
+ * network (see clconfig_provider::refresh())</li>
61
64
  *
62
65
  * <li>Notify the monitor that it has received a new configuration. The
63
66
  * monitor itself will determine whether or not to accept the new
@@ -69,7 +72,7 @@
69
72
  * _Configuration Info_ objects. These objects are refcounted wrappers
70
73
  * around vbucket configuration handles. They have a refcount and also an
71
74
  * integer which can be used to compare with other objects for 'freshness'.
72
- * See ConfigInfo
75
+ * See clconfig_info
73
76
  * </li>
74
77
  *
75
78
  * <li>
@@ -77,7 +80,7 @@
77
80
  * and are invoked whenever a new valid configuration is detected. This is
78
81
  * really only ever used during bootstrap or testing where we are explicitly
79
82
  * waiting for a configuration without having any actual commands to schedule.
80
- * See Listener
83
+ * See clconfig_listener
81
84
  * </li>
82
85
  * </ol>
83
86
  */
@@ -87,295 +90,55 @@
87
90
  *@{
88
91
  */
89
92
 
90
- namespace lcb {
91
- namespace clconfig {
92
-
93
93
  /**
94
94
  * @brief Enumeration of the various config providers available.
95
95
  * The type of methods available. These are enumerated in order of preference
96
96
  */
97
- enum Method {
97
+ typedef enum {
98
+ /** Currently unused. The intent here is to allow a user to provide means
99
+ * by which the application may give a configuration file to the library */
100
+ LCB_CLCONFIG_USER,
98
101
  /** File-based "configcache" provider. Implemented in bc_file.c */
99
- CLCONFIG_FILE,
102
+ LCB_CLCONFIG_FILE,
100
103
  /** New-style config-over-memcached provider. Implemented in bc_cccp.c */
101
- CLCONFIG_CCCP,
104
+ LCB_CLCONFIG_CCCP,
102
105
  /** Old-style streaming HTTP provider. Implemented in bc_http.c */
103
- CLCONFIG_HTTP,
106
+ LCB_CLCONFIG_HTTP,
104
107
  /** Raw memcached provided */
105
- CLCONFIG_MCRAW,
108
+ LCB_CLCONFIG_MCRAW,
106
109
 
107
- CLCONFIG_MAX,
110
+ LCB_CLCONFIG_MAX,
108
111
 
109
112
  /** Ephemeral source, used for tests */
110
- CLCONFIG_PHONY
111
- };
112
-
113
-
114
- /** Event types propagated to listeners */
115
- enum EventType {
116
- /** Called when a new configuration is being set in confmon */
117
- CLCONFIG_EVENT_GOT_NEW_CONFIG,
118
-
119
- /** Called when _any_ configuration is received via set_enxt */
120
- CLCONFIG_EVENT_GOT_ANY_CONFIG,
113
+ LCB_CLCONFIG_PHONY
114
+ } clconfig_method_t;
121
115
 
122
- /** Called when all providers have been tried */
123
- CLCONFIG_EVENT_PROVIDERS_CYCLED,
124
-
125
- /** The monitor has stopped */
126
- CLCONFIG_EVENT_MONITOR_STOPPED
127
- };
128
116
 
129
-
130
- /** @brief Possible confmon states */
131
- enum State {
132
- /** The monitor is idle and not requesting a new configuration */
133
- CONFMON_S_INACTIVE = 0,
134
-
135
- /** The monitor is actively requesting a configuration */
136
- CONFMON_S_ACTIVE = 1 << 0,
137
-
138
- /** The monitor is fetching a configuration, but is in a throttle state */
139
- CONFMON_S_ITERGRACE = 1 << 1
140
- };
141
-
142
-
143
- struct Provider;
144
- struct Listener;
145
- class ConfigInfo;
117
+ struct clconfig_info_st;
118
+ struct clconfig_provider_st;
119
+ struct clconfig_listener_st;
120
+ struct lcb_confmon_st;
146
121
 
147
122
  /**
148
123
  * This object contains the information needed for libcouchbase to deal with
149
124
  * when retrieving new configs.
150
125
  */
151
- struct Confmon {
152
- /**
153
- * @brief Create a new configuration monitor.
154
- * This function creates a new `confmon` object which can be used to manage
155
- * configurations and their providers.
156
- *
157
- * @param settings
158
- * @param iot
159
- *
160
- * Once the confmon object has been created you may enable or disable various
161
- * providers (see lcb_confmon_set_provider_active()). Once no more providers
162
- * remain to be activated you should call lcb_confmon_prepare() once. Then
163
- * call the rest of the functions.
164
- */
165
- Confmon(lcb_settings*, lcbio_pTABLE iot);
166
- void destroy() { delete this; }
167
- ~Confmon();
168
-
169
- /**
170
- * Get the provider following the current provider, or NULL if this is
171
- * the last provider in the list.
172
- * @param cur The current provider.
173
- * @return The next provider, or NULL if no more providers remain.
174
- */
175
- Provider *next_active(Provider *cur);
176
-
177
- /**
178
- * Gets the first active provider.
179
- * @return the first provider, or NULL if no providers exist.
180
- */
181
- Provider *first_active();
182
-
183
- /**
184
- * Prepares the configuration monitor object for operations. This will insert
185
- * all the enabled providers into a list. Call this function each time a
186
- * provider has been enabled.
187
- * @param mon
188
- */
189
- void prepare();
190
-
191
- /**
192
- * Set a given provider as being 'active'. This will activate the
193
- * provider as well as call #prepare() to update the list.
194
- * @param type The ID of the provider to activate
195
- * @param enabled true for activate, false for deactivate
196
- */
197
- void set_active(Method type, bool enabled);
198
-
199
- /**
200
- * @brief Request a configuration refresh
201
- *
202
- * Start traversing the list of current providers, requesting a new
203
- * configuration for each. This function will asynchronously loop through all
204
- * providers until one provides a new configuration.
205
- *
206
- * You may call #stop() to asynchronously break out of the loop.
207
- * If the confmon is already in a refreshing state
208
- * (i.e. #is_refreshing()) returns true then this function does
209
- * nothing.
210
- *
211
- * This function is reentrant safe and may be called at any time.
212
- *
213
- * @param mon
214
- * @see lcb_confmon_add_listener()
215
- * @see #stop()
216
- * @see #is_refreshing()
217
- */
218
- void start();
219
-
220
- /**
221
- * @brief Cancel a pending configuration refresh.
222
- *
223
- * Stops the monitor. This will call Provider::pause() for each active
224
- * provider. Typically called before destruction or when a new configuration
225
- * has been found.
226
- *
227
- * This function is safe to call anywhere. If the monitor is already stopped
228
- * then this function does nothing.
229
- *
230
- * @param mon
231
- * @see #start()
232
- * @see #is_refreshing()
233
- */
234
- void stop();
235
-
236
- /**
237
- * @brief Check if the monitor is waiting for a new config from a provider
238
- * @param mon
239
- * @return true if refreshing, false if idle
240
- */
241
- bool is_refreshing() const {
242
- return (state & CONFMON_S_ACTIVE) != 0;
243
- }
244
-
245
- /**
246
- * Get the current configuration
247
- * @return The configuration
248
- */
249
- ConfigInfo* get_config() const {
250
- return config;
251
- }
252
-
253
- /**
254
- * Get the last error which occurred on this object
255
- * @return The last error
256
- */
257
- lcb_error_t get_last_error() const {
258
- return last_error;
259
- }
260
-
261
- /**
262
- * @brief Get the current monitor state
263
- * @param mon the monitor
264
- * @return a set of flags consisting of @ref State values.
265
- */
266
- int get_state() const {
267
- return state;
268
- }
269
-
270
- void stop_real();
271
- void do_next_provider();
272
- int do_set_next(ConfigInfo*, bool notify_miss);
273
- void invoke_listeners(EventType, ConfigInfo*);
274
-
275
- /**
276
- * @brief Indicate that a provider has failed and advance the monitor
277
- *
278
- * Indicate that the current provider has failed to obtain a new configuration.
279
- * This is always called by a provider and should be invoked when the provider
280
- * has encountered an internal error which caused it to be unable to fetch
281
- * the configuration.
282
- *
283
- * Note that this function is safe to call from any provider at any time. If
284
- * the provider is not the current provider then it is treated as an async
285
- * push notification failure and ignored. This function is _not_ safe to call
286
- * from consumers of providers
287
- *
288
- * Once this is called, the confmon instance will either roll over to the next
289
- * provider or enter the inactive state depending on the configuration and
290
- * whether the current provider is the last provider in the list.
291
- *
292
- * @param provider
293
- * @param err
294
- */
295
- void provider_failed(Provider *which, lcb_error_t why);
296
-
297
- /**
298
- * @brief Indicate that a provider has successfuly retrieved a configuration.
299
- *
300
- * Indicates that the provider has fetched a new configuration from the network
301
- * and that confmon should attempt to propagate it. It has similar semantics
302
- * to lcb_confmon_provider_failed() except that the second argument is a config
303
- * object rather than an error code. The second argument must not be `NULL`
304
- *
305
- * The monitor will compare the new config against the current config.
306
- * If the new config does not feature any changes from the current config then
307
- * it is ignored and the confmon instance will proceed to the next provider.
308
- * This is done through a direct call to provider_failed(provider, LCB_SUCCESS).
309
- *
310
- * This function should _not_ be called outside of an asynchronous provider's
311
- * handler.
312
- *
313
- * @param provider the provider which yielded the new configuration
314
- * @param info the new configuration
315
- */
316
- void provider_got_config(Provider *which, ConfigInfo* config);
317
-
318
- /** Dump information about the monitor
319
- * @param mon the monitor object
320
- * @param fp the file to which information should be written
321
- */
322
- void dump(FILE *fp);
323
-
324
- Provider* get_provider(Method m) const {
325
- return all_providers[m];
326
- }
327
-
328
- /**
329
- * @brief Register a listener to be invoked on state changes and events
330
- *
331
- * Adds a 'listener' object to be called at each configuration update. The
332
- * listener may co-exist with other listeners (though it should never be added
333
- * twice). When a new configuration is received and accept, the listener's
334
- * Listener::callback field will be invoked with it.
335
- *
336
- * The callback will continue to be invoked for each new configuration received
337
- * until remove_listener is called. Note that the listener is not allocated
338
- * by the confmon and its responsibility is the user's
339
- *
340
- * @param mon the monitor
341
- * @param listener the listener. The listener's contents are not copied into
342
- * confmon and should thus remain valid until it is removed
343
- */
344
- void add_listener(Listener* lsn);
345
-
346
- /**
347
- * @brief Unregister (and remove) a listener added via lcb_confmon_add_listener()
348
- * @param mon the monitor
349
- * @param listener the listener
350
- */
351
- void remove_listener(Listener *lsn);
126
+ typedef struct lcb_confmon_st {
127
+ /** Linked list of active/enabled providers */
128
+ lcb_clist_t active_providers;
352
129
 
353
130
  /**Current provider. This provider may either fail or succeed.
354
131
  * In either case unless the provider can provide us with a specific
355
132
  * config which is newer than the one we have, it will roll over to the
356
133
  * next provider. */
357
- Provider *cur_provider;
134
+ struct clconfig_provider_st *cur_provider;
358
135
 
359
136
  /** All providers we know about. Currently this means the 'builtin' providers */
360
- Provider* all_providers[CLCONFIG_MAX];
137
+ struct clconfig_provider_st * all_providers[LCB_CLCONFIG_MAX];
361
138
 
362
139
  /** The current configuration pointer. This contains the most recent accepted
363
140
  * configuration */
364
- ConfigInfo * config;
365
-
366
- typedef std::list<Listener*> ListenerList;
367
- /** List of listeners for events */
368
- ListenerList listeners;
369
-
370
- lcb_settings *settings;
371
- lcb_error_t last_error;
372
- lcbio_pTABLE iot;
373
-
374
- /** This is the async handle for a reentrant start */
375
- lcb::io::Timer<Confmon, &Confmon::do_next_provider> as_start;
376
-
377
- /** Async handle for a reentrant stop */
378
- lcb::io::Timer<Confmon, &Confmon::stop_real> as_stop;
141
+ struct clconfig_info_st * config;
379
142
 
380
143
  /* CONFMON_S_* values. Used internally */
381
144
  int state;
@@ -383,27 +146,44 @@ struct Confmon {
383
146
  /** Last time the provider was stopped. As a microsecond timestamp */
384
147
  lcb_uint32_t last_stop_us;
385
148
 
386
- typedef std::list<Provider*> ProviderList;
387
- ProviderList active_providers;
388
- };
149
+ /** This is the async handle for a reentrant start */
150
+ lcbio_pTIMER as_start;
151
+
152
+ /** Async handle for a reentrant stop */
153
+ lcbio_pTIMER as_stop;
154
+
155
+ /** List of listeners for events */
156
+ lcb_list_t listeners;
157
+ lcb_settings *settings;
158
+ lcb_error_t last_error;
159
+ lcbio_pTABLE iot;
160
+ } lcb_confmon;
389
161
 
390
162
  /**
391
163
  * The base structure of a provider. This structure is intended to be
392
164
  * 'subclassed' by implementors.
393
165
  */
394
- struct Provider {
395
- Provider(Confmon*, Method type_);
166
+ typedef struct clconfig_provider_st {
167
+ lcb_list_t ll; /**< Node in linked list of active providers (if active) */
396
168
 
397
- /** Destroy the resources created by this provider. */
398
- virtual ~Provider();
169
+ /** The type of provider */
170
+ clconfig_method_t type;
171
+
172
+ /** Whether this provider has been disabled/enabled explicitly by a user */
173
+ int enabled;
174
+
175
+ /** The parent manager object */
176
+ struct lcb_confmon_st *parent;
399
177
 
400
178
  /**
401
179
  * Get the current map known to this provider. This should not perform
402
180
  * any blocking operations. Providers which use a push model may use
403
181
  * this method as an asynchronous return value for a previously-received
404
182
  * configuration.
183
+ *
184
+ * @param pb
405
185
  */
406
- virtual ConfigInfo* get_cached() = 0;
186
+ struct clconfig_info_st* (*get_cached)(struct clconfig_provider_st *pb);
407
187
 
408
188
 
409
189
  /**
@@ -422,7 +202,7 @@ struct Provider {
422
202
  *
423
203
  * @param pb
424
204
  */
425
- virtual lcb_error_t refresh() = 0;
205
+ lcb_error_t (*refresh)(struct clconfig_provider_st *pb);
426
206
 
427
207
  /**
428
208
  * Callback invoked to the provider to indicate that it should cease
@@ -433,11 +213,8 @@ struct Provider {
433
213
  * between 0 seconds and several minutes depending on how a user has
434
214
  * configured the client.
435
215
  * @param pb
436
- * @return true if actually paused
437
216
  */
438
- virtual bool pause() {
439
- return false;
440
- }
217
+ lcb_error_t (*pause)(struct clconfig_provider_st *pb);
441
218
 
442
219
  /**
443
220
  * Called when a new configuration has been received.
@@ -447,132 +224,64 @@ struct Provider {
447
224
  * Note that this should only update the server list and do nothing
448
225
  * else.
449
226
  */
450
- virtual void config_updated(lcbvb_CONFIG*) {
451
- }
227
+ void (*config_updated)(struct clconfig_provider_st *provider,
228
+ lcbvb_CONFIG* config);
452
229
 
453
230
  /**
454
231
  * Retrieve the list of nodes from this provider, if applicable
455
232
  * @param p the provider
456
233
  * @return A list of nodes, or NULL if the provider does not have a list
457
234
  */
458
- virtual const lcb::Hostlist* get_nodes() const {
459
- return NULL;
460
- }
235
+ hostlist_t (*get_nodes)(const struct clconfig_provider_st *p);
461
236
 
462
237
  /**
463
238
  * Call to change the configured nodes of this provider.
464
239
  * @param p The provider
465
240
  * @param l The list of nodes to apply
466
241
  */
467
- virtual void configure_nodes(const lcb::Hostlist&) {
468
- }
242
+ void (*configure_nodes)(struct clconfig_provider_st *p, const hostlist_t l);
243
+
244
+ /** Destroy the resources created by this provider. */
245
+ void (*shutdown)(struct clconfig_provider_st *);
469
246
 
470
247
  /**
471
248
  * Dump state information. This callback is optional
472
249
  * @param p the provider
473
250
  * @param f the file to write to
474
251
  */
475
- virtual void dump(FILE *) const {
476
- }
477
-
478
- void enable() {
479
- enabled = 1;
480
- }
481
-
482
- virtual void enable(void *) {
483
- assert("Must be implemented in subclass if used" && 0);
484
- }
485
-
486
- /** The type of provider */
487
- const Method type;
488
-
489
- /** Whether this provider has been disabled/enabled explicitly by a user */
490
- bool enabled;
491
-
492
- /** The parent manager object */
493
- Confmon *parent;
494
-
495
- lcb_settings& settings() const {
496
- return *parent->settings;
497
- }
498
- };
499
-
500
- Provider *new_cccp_provider(Confmon*);
501
- Provider *new_file_provider(Confmon*);
502
- Provider *new_http_provider(Confmon*);
503
- Provider *new_mcraw_provider(Confmon*);
252
+ void (*dump)(struct clconfig_provider_st *p, FILE *f);
253
+ } clconfig_provider;
504
254
 
505
255
 
506
256
  /** @brief refcounted object encapsulating a vbucket config */
507
- class ConfigInfo {
508
- public:
509
- /**
510
- * Creates a new configuration wrapper object containing the vbucket config
511
- * pointed to by 'config'. Its initial refcount will be set to 1.
512
- *
513
- * @param config a newly parsed configuration
514
- * @param origin the type of provider from which the config originated.
515
- * @return a new ConfigInfo object. This should be incref()'d/decref()'d
516
- * as needed.
517
- */
518
- static ConfigInfo* create(lcbvb_CONFIG *vbc, Method origin) {
519
- return new ConfigInfo(vbc, origin);
520
- }
521
- /**
522
- * @brief Compares two info structures and determine which one is newer
523
- *
524
- * This function returns an integer less than
525
- * zero, zero or greater than zero if the first argument is considered older
526
- * than, equal to, or later than the second argument.
527
- * @param a
528
- * @param b
529
- * @see lcbvb_get_revision
530
- * @see ConfigInfo::cmpclock
531
- */
532
- int compare(const ConfigInfo&);
533
-
534
- /**
535
- * @brief Increment the refcount on a config object
536
- */
537
- void incref() { refcount++; }
538
-
539
- /**
540
- * @brief Decrement the refcount on a config object.
541
- * Decrement the refcount. If the internal refcount reaches 0 then the internal
542
- * members (including the vbucket config handle itself) will be freed.
543
- * @param info the configuration
544
- */
545
- void decref() {
546
- if (!--refcount) {
547
- delete this;
548
- }
549
- }
550
-
551
- operator lcbvb_CONFIG*() const {
552
- return vbc;
553
- }
554
-
555
- Method get_origin() const {
556
- return origin;
557
- }
558
-
257
+ typedef struct clconfig_info_st {
559
258
  /** Actual configuration */
560
259
  lcbvb_CONFIG* vbc;
561
260
 
562
- private:
563
- ConfigInfo(lcbvb_CONFIG *vbc, Method origin);
564
-
565
- ~ConfigInfo();
566
-
567
261
  /** Comparative clock with which to compare */
568
- uint64_t cmpclock;
262
+ lcb_uint64_t cmpclock;
569
263
 
570
264
  /** Reference counter */
571
265
  unsigned int refcount;
572
266
 
573
267
  /** Origin provider type which produced this config */
574
- Method origin;
575
- };
268
+ clconfig_method_t origin;
269
+ } clconfig_info;
270
+
271
+ /** Event types propagated to listeners */
272
+ typedef enum {
273
+ /** Called when a new configuration is being set in confmon */
274
+ CLCONFIG_EVENT_GOT_NEW_CONFIG,
275
+
276
+ /** Called when _any_ configuration is received via set_enxt */
277
+ CLCONFIG_EVENT_GOT_ANY_CONFIG,
278
+
279
+ /** Called when all providers have been tried */
280
+ CLCONFIG_EVENT_PROVIDERS_CYCLED,
281
+
282
+ /** The monitor has stopped */
283
+ CLCONFIG_EVENT_MONITOR_STOPPED
284
+ } clconfig_event_t;
576
285
 
577
286
  /**
578
287
  * @brief Listener for events
@@ -580,25 +289,289 @@ private:
580
289
  * a callback invoked on significant vbucket events. See clconfig_event_t
581
290
  * for a variety of events the listener can know.
582
291
  */
583
- struct Listener {
584
- virtual ~Listener() {
585
- }
586
-
292
+ typedef struct clconfig_listener_st {
587
293
  /** Linked list node */
588
294
  lcb_list_t ll;
589
295
 
296
+ /** Monitor object */
297
+ lcb_confmon *parent;
298
+
590
299
  /**
591
300
  * Callback invoked for significant events
592
301
  *
302
+ * @param lsn the listener structure itself
593
303
  * @param event the event which took place
594
304
  * @param config the configuration associated with the event. Note that
595
305
  * `config` may also be NULL
596
306
  */
597
- virtual void clconfig_lsn(EventType event, ConfigInfo *config) = 0;
598
- };
307
+ void (*callback)(struct clconfig_listener_st *lsn, clconfig_event_t event,
308
+ struct clconfig_info_st *config);
309
+
310
+ } clconfig_listener;
599
311
 
600
312
  /* Method-specific setup methods.. */
601
313
 
314
+ clconfig_provider * lcb_clconfig_create_http(lcb_confmon *mon);
315
+ clconfig_provider * lcb_clconfig_create_cccp(lcb_confmon *mon);
316
+ clconfig_provider * lcb_clconfig_create_file(lcb_confmon *mon);
317
+ clconfig_provider * lcb_clconfig_create_user(lcb_confmon *mon);
318
+ clconfig_provider * lcb_clconfig_create_mcraw(lcb_confmon *mon);
319
+
320
+ /**@brief Get a provider by its type
321
+ * @param mon the monitor
322
+ * @param ix a clconfig_method_t indicating the type of provider to fetch
323
+ * @return a pointer to the provider of the given type
324
+ */
325
+ #define lcb_confmon_get_provider(mon, ix) (mon)->all_providers[ix]
326
+
327
+ /**
328
+ * @brief Macro used to retrieve a setting from a provider
329
+ * @param p the provider pointer
330
+ * @param n the name of the setting field to retrieve as token
331
+ */
332
+ #define PROVIDER_SETTING(p, n) ((p)->parent->settings->n)
333
+
334
+ /**
335
+ * @brief Macro used by a provider to set the failure code in the parent
336
+ * lcb_confmon object
337
+ * @param p the provider pointer
338
+ * @param e the error code
339
+ */
340
+ #define PROVIDER_SET_ERROR(p, e) (p)->parent->last_error = e
341
+
342
+ /**
343
+ * @brief Create a new configuration monitor.
344
+ * This function creates a new `confmon` object which can be used to manage
345
+ * configurations and their providers.
346
+ *
347
+ * @param settings
348
+ * @param iot
349
+ *
350
+ * Once the confmon object has been created you may enable or disable various
351
+ * providers (see lcb_confmon_set_provider_active()). Once no more providers
352
+ * remain to be activated you should call lcb_confmon_prepare() once. Then
353
+ * call the rest of the functions.
354
+ */
355
+ LIBCOUCHBASE_API
356
+ lcb_confmon *
357
+ lcb_confmon_create(lcb_settings *settings, lcbio_pTABLE iot);
358
+
359
+ /**Destroy the confmon object.
360
+ * @param mon */
361
+ LIBCOUCHBASE_API
362
+ void
363
+ lcb_confmon_destroy(lcb_confmon *mon);
364
+
365
+ /**
366
+ * Prepares the configuration monitor object for operations. This will insert
367
+ * all the enabled providers into a list. Call this function each time a
368
+ * provider has been enabled.
369
+ * @param mon
370
+ */
371
+ LIBCOUCHBASE_API
372
+ void
373
+ lcb_confmon_prepare(lcb_confmon *mon);
374
+
375
+ LCB_INTERNAL_API
376
+ void
377
+ lcb_confmon_set_provider_active(lcb_confmon *mon,
378
+ clconfig_method_t type, int enabled);
379
+
380
+
381
+ /**
382
+ * @brief Request a configuration refresh
383
+ *
384
+ * Start traversing the list of current providers, requesting a new
385
+ * configuration for each. This function will asynchronously loop through all
386
+ * providers until one provides a new configuration.
387
+ *
388
+ * You may call lcb_confmon_stop() to asynchronously break out of the loop.
389
+ * If the confmon is already in a refreshing state
390
+ * (i.e. lcb_confmon_is_refreshing()) returns true then this function does
391
+ * nothing.
392
+ *
393
+ * This function is reentrant safe and may be called at any time.
394
+ *
395
+ * @param mon
396
+ * @see lcb_confmon_add_listener()
397
+ * @see lcb_confmon_stop()
398
+ * @see lcb_confmon_is_refreshing()
399
+ */
400
+ LIBCOUCHBASE_API
401
+ lcb_error_t lcb_confmon_start(lcb_confmon *mon);
402
+
403
+ /**
404
+ * @brief Cancel a pending configuration refresh.
405
+ *
406
+ * Stops the monitor. This will call clconfig_provider::pause() for each active
407
+ * provider. Typically called before destruction or when a new configuration
408
+ * has been found.
409
+ *
410
+ * This function is safe to call anywhere. If the monitor is already stopped
411
+ * then this function does nothing.
412
+ *
413
+ * @param mon
414
+ * @see lcb_confmon_start()
415
+ * @see lcb_confmon_is_refreshing()
416
+ */
417
+ LIBCOUCHBASE_API
418
+ lcb_error_t lcb_confmon_stop(lcb_confmon *mon);
419
+
420
+ /**
421
+ * @brief Check if the monitor is waiting for a new config from a provider
422
+ * @param mon
423
+ * @return true if refreshing, false if idle
424
+ */
425
+ LCB_INTERNAL_API
426
+ int lcb_confmon_is_refreshing(lcb_confmon *mon);
427
+
428
+
429
+ /**@brief Get the current configuration object
430
+ * @return The current configuration */
431
+ #define lcb_confmon_get_config(mon) (mon)->config
432
+
433
+ /**@brief Get the last error code set by a provider
434
+ * @return the last error code (if failure) */
435
+ #define lcb_confmon_last_error(mon) (mon)->last_error
436
+
437
+ /**
438
+ * @brief Indicate that a provider has failed and advance the monitor
439
+ *
440
+ * Indicate that the current provider has failed to obtain a new configuration.
441
+ * This is always called by a provider and should be invoked when the provider
442
+ * has encountered an internal error which caused it to be unable to fetch
443
+ * the configuration.
444
+ *
445
+ * Note that this function is safe to call from any provider at any time. If
446
+ * the provider is not the current provider then it is treated as an async
447
+ * push notification failure and ignored. This function is _not_ safe to call
448
+ * from consumers of providers
449
+ *
450
+ * Once this is called, the confmon instance will either roll over to the next
451
+ * provider or enter the inactive state depending on the configuration and
452
+ * whether the current provider is the last provider in the list.
453
+ *
454
+ * @param provider
455
+ * @param err
456
+ */
457
+ LIBCOUCHBASE_API
458
+ void
459
+ lcb_confmon_provider_failed(clconfig_provider *provider, lcb_error_t err);
460
+
461
+
462
+ /**
463
+ * @brief Indicate that a provider has successfuly retrieved a configuration.
464
+ *
465
+ * Indicates that the provider has fetched a new configuration from the network
466
+ * and that confmon should attempt to propagate it. It has similar semantics
467
+ * to lcb_confmon_provider_failed() except that the second argument is a config
468
+ * object rather than an error code. The second argument must not be `NULL`
469
+ *
470
+ * The monitor will compare the new config against the current config.
471
+ * If the new config does not feature any changes from the current config then
472
+ * it is ignored and the confmon instance will proceed to the next provider.
473
+ * This is done through a direct call to provider_failed(provider, LCB_SUCCESS).
474
+ *
475
+ * This function should _not_ be called outside of an asynchronous provider's
476
+ * handler.
477
+ *
478
+ * @param provider the provider which yielded the new configuration
479
+ * @param info the new configuration
480
+ */
481
+ LIBCOUCHBASE_API
482
+ void
483
+ lcb_confmon_provider_success(clconfig_provider *provider, clconfig_info *info);
484
+
485
+ /**
486
+ * @brief Register a listener to be invoked on state changes and events
487
+ *
488
+ * Adds a 'listener' object to be called at each configuration update. The
489
+ * listener may co-exist with other listeners (though it should never be added
490
+ * twice). When a new configuration is received and accept, the listener's
491
+ * clconfig_listener::callback field will be invoked with it.
492
+ *
493
+ * The callback will continue to be invoked for each new configuration received
494
+ * until remove_listener is called. Note that the listener is not allocated
495
+ * by the confmon and its responsibility is the user's
496
+ *
497
+ * @param mon the monitor
498
+ * @param listener the listener. The listener's contents are not copied into
499
+ * confmon and should thus remain valid until it is removed
500
+ */
501
+ LIBCOUCHBASE_API
502
+ void lcb_confmon_add_listener(lcb_confmon *mon, clconfig_listener *listener);
503
+
504
+ /**
505
+ * @brief Unregister (and remove) a listener added via lcb_confmon_add_listener()
506
+ * @param mon the monitor
507
+ * @param listener the listener
508
+ */
509
+ LIBCOUCHBASE_API
510
+ void lcb_confmon_remove_listener(lcb_confmon *mon, clconfig_listener *listener);
511
+
512
+ /** @brief Possible confmon states */
513
+ typedef enum {
514
+ /** The monitor is idle and not requesting a new configuration */
515
+ CONFMON_S_INACTIVE = 0,
516
+
517
+ /** The monitor is actively requesting a configuration */
518
+ CONFMON_S_ACTIVE = 1 << 0,
519
+
520
+ /** The monitor is fetching a configuration, but is in a throttle state */
521
+ CONFMON_S_ITERGRACE = 1 << 1
522
+ } confmon_state_t;
523
+
524
+ /**
525
+ * @brief Get the current monitor state
526
+ * @param mon the monitor
527
+ * @return a set of flags consisting of confmon_state_t values.
528
+ */
529
+ #define lcb_confmon_get_state(mon) (mon)->state
530
+
531
+ /**
532
+ * Creates a new configuration wrapper object containing the vbucket config
533
+ * pointed to by 'config'. Its initial refcount will be set to 1.
534
+ *
535
+ * @param config a newly parsed configuration
536
+ * @param origin the type of provider from which the config originated.
537
+ */
538
+ clconfig_info *
539
+ lcb_clconfig_create(lcbvb_CONFIG* config, clconfig_method_t origin);
540
+
541
+ /**
542
+ * @brief Compares two info structures and determine which one is newer
543
+ *
544
+ * This function returns an integer less than
545
+ * zero, zero or greater than zero if the first argument is considered older
546
+ * than, equal to, or later than the second argument.
547
+ * @param a
548
+ * @param b
549
+ * @see lcbvb_get_revision
550
+ * @see clconfig_info::cmpclock
551
+ */
552
+ LIBCOUCHBASE_API
553
+ int lcb_clconfig_compare(const clconfig_info *a, const clconfig_info *b);
554
+
555
+ /**
556
+ * @brief Decrement the refcount on a config object.
557
+ * Decrement the refcount. If the internal refcount reaches 0 then the internal
558
+ * members (including the vbucket config handle itself) will be freed.
559
+ * @param info the configuration
560
+ */
561
+ void lcb_clconfig_decref(clconfig_info *info);
562
+
563
+ /**
564
+ * @brief Increment the refcount on a config object
565
+ * @param info the config object
566
+ */
567
+ #define lcb_clconfig_incref(info) (info)->refcount++
568
+
569
+ /** Dump information about the monitor
570
+ * @param mon the monitor object
571
+ * @param fp the file to which information should be written
572
+ */
573
+ void lcb_confmon_dump(lcb_confmon *mon, FILE *fp);
574
+
602
575
  /**
603
576
  * @name File Provider-specific APIs
604
577
  * @{
@@ -610,17 +583,18 @@ struct Listener {
610
583
  * @param p the provider
611
584
  * @param f the filename (if NULL, a temporary filename will be created)
612
585
  * @param ro whether the client will never modify the file
613
- * @return true on success, false on failure.
586
+ * @return zero on success, nonzero on failure.
614
587
  */
615
- bool file_set_filename(Provider *p, const char *f, bool ro);
588
+ int lcb_clconfig_file_set_filename(clconfig_provider *p, const char *f, int ro);
616
589
 
617
590
  /**
618
591
  * Retrieve the filename for the provider
619
592
  * @param p The provider of type LCB_CLCONFIG_FILE
620
593
  * @return the current filename being used.
621
594
  */
622
- const char* file_get_filename(Provider *p);
623
- void file_set_readonly(Provider *p, bool val);
595
+ const char * lcb_clconfig_file_get_filename(clconfig_provider *p);
596
+
597
+ void lcb_clconfig_file_set_readonly(clconfig_provider *p, int val);
624
598
  /**@}*/
625
599
 
626
600
  /**
@@ -634,32 +608,30 @@ void file_set_readonly(Provider *p, bool val);
634
608
  * @param mon
635
609
  * @return
636
610
  */
637
- const lcbio_SOCKET* http_get_conn(const Provider *p);
638
-
639
- static inline const lcbio_SOCKET* http_get_conn(Confmon *c) {
640
- return http_get_conn(c->get_provider(CLCONFIG_HTTP));
641
- }
611
+ lcbio_SOCKET* lcb_confmon_get_rest_connection(lcb_confmon *mon);
642
612
 
643
613
  /**
644
614
  * Get the hostname for the current REST connection to the cluster
645
615
  * @param mon
646
616
  * @return
647
617
  */
648
- const lcb_host_t * http_get_host(const Provider *p);
649
- static inline const lcb_host_t* http_get_host(Confmon *c) {
650
- return http_get_host(c->get_provider(CLCONFIG_HTTP));
651
- }
652
- /**@}*/
618
+ lcb_host_t * lcb_confmon_get_rest_host(lcb_confmon *mon);
653
619
 
654
620
  /**
655
- * @name CCCP Provider-specific APIs
656
- * @{
621
+ * Enables the HTTP provider
622
+ * @param pb a provider of type LCB_CLCONFIG_HTTP
657
623
  */
624
+ LCB_INTERNAL_API
625
+ void lcb_clconfig_http_enable(clconfig_provider *pb);
626
+ #define lcb_clconfig_http_set_nodes lcb_clconfig_cccp_set_nodes
627
+ /**@}*/
658
628
 
659
629
  /**
660
- * Note, to initialize the CCCP provider, you should use
661
- * cccp->enable(instance);
630
+ * @name CCCP Provider-specific APIs
631
+ * @{
662
632
  */
633
+ LCB_INTERNAL_API
634
+ void lcb_clconfig_cccp_enable(clconfig_provider *pb, lcb_t instance);
663
635
 
664
636
  /**
665
637
  * @brief Notify the CCCP provider about a new configuration from a
@@ -675,7 +647,7 @@ static inline const lcb_host_t* http_get_host(Confmon *c) {
675
647
  * set
676
648
  */
677
649
  lcb_error_t
678
- cccp_update(Provider *provider, const char *host, const char *data);
650
+ lcb_cccp_update(clconfig_provider *provider, const char *host, const char *data);
679
651
 
680
652
  /**
681
653
  * @brief Notify the CCCP provider about a configuration received from a
@@ -687,16 +659,23 @@ cccp_update(Provider *provider, const char *host, const char *data);
687
659
  * @param nbytes Size of payload
688
660
  * @param origin Host object from which the packet was received
689
661
  */
690
- void cccp_update(const void *cookie, lcb_error_t err,
691
- const void *bytes, size_t nbytes, const lcb_host_t *origin);
662
+ void
663
+ lcb_cccp_update2(const void *cookie, lcb_error_t err,
664
+ const void *bytes, lcb_size_t nbytes, const lcb_host_t *origin);
692
665
 
666
+ #define lcb_clconfig_cccp_set_nodes(pb, nodes) (pb)->configure_nodes(pb, nodes)
693
667
  /**@}*/
694
668
 
695
669
  /**@name Raw Memcached (MCRAW) Provider-specific APIs
696
670
  * @{*/
671
+ LCB_INTERNAL_API
672
+ lcb_error_t
673
+ lcb_clconfig_mcraw_update(clconfig_provider *pb, const char *nodes);
697
674
  /**@}*/
675
+
698
676
  /**@}*/
699
677
 
700
- } // clconfig
701
- } // lcb
678
+ #ifdef __cplusplus
679
+ }
680
+ #endif /* __cplusplus */
702
681
  #endif /* LCB_CLCONFIG_H */