libcouchbase 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libcouchbase/.gitignore +2 -0
  3. data/ext/libcouchbase/CMakeLists.txt +5 -7
  4. data/ext/libcouchbase/README.markdown +2 -2
  5. data/ext/libcouchbase/RELEASE_NOTES.markdown +49 -0
  6. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
  7. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +2 -0
  8. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +2 -1
  9. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  10. data/ext/libcouchbase/cmake/config-cmake.h.in +2 -0
  11. data/ext/libcouchbase/cmake/defs.mk.in +0 -2
  12. data/ext/libcouchbase/cmake/source_files.cmake +34 -14
  13. data/ext/libcouchbase/configure.pl +1 -1
  14. data/ext/libcouchbase/contrib/genhash/genhash.h +6 -0
  15. data/ext/libcouchbase/include/libcouchbase/auth.h +10 -0
  16. data/ext/libcouchbase/include/libcouchbase/couchbase.h +10 -0
  17. data/ext/libcouchbase/include/libcouchbase/error.h +7 -0
  18. data/ext/libcouchbase/include/libcouchbase/n1ql.h +13 -1
  19. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
  20. data/ext/libcouchbase/include/libcouchbase/subdoc.h +9 -0
  21. data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
  22. data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
  23. data/ext/libcouchbase/include/memcached/protocol_binary.h +21 -1132
  24. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  25. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
  26. data/ext/libcouchbase/src/README.md +0 -2
  27. data/ext/libcouchbase/src/auth-priv.h +1 -0
  28. data/ext/libcouchbase/src/auth.cc +10 -0
  29. data/ext/libcouchbase/src/bootstrap.cc +216 -0
  30. data/ext/libcouchbase/src/bootstrap.h +50 -39
  31. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +455 -0
  32. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
  33. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +528 -0
  34. data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
  35. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +115 -0
  36. data/ext/libcouchbase/src/bucketconfig/clconfig.h +407 -386
  37. data/ext/libcouchbase/src/bucketconfig/confmon.cc +378 -0
  38. data/ext/libcouchbase/src/cbft.cc +22 -27
  39. data/ext/libcouchbase/src/cntl.cc +24 -24
  40. data/ext/libcouchbase/src/connspec.cc +30 -1
  41. data/ext/libcouchbase/src/connspec.h +17 -0
  42. data/ext/libcouchbase/src/dns-srv.cc +143 -0
  43. data/ext/libcouchbase/src/{dump.c → dump.cc} +8 -11
  44. data/ext/libcouchbase/src/getconfig.cc +73 -0
  45. data/ext/libcouchbase/src/handler.cc +84 -85
  46. data/ext/libcouchbase/src/hostlist.cc +0 -1
  47. data/ext/libcouchbase/src/hostlist.h +6 -1
  48. data/ext/libcouchbase/src/http/http-priv.h +125 -112
  49. data/ext/libcouchbase/src/http/http.cc +9 -29
  50. data/ext/libcouchbase/src/http/http.h +1 -34
  51. data/ext/libcouchbase/src/http/http_io.cc +22 -26
  52. data/ext/libcouchbase/src/instance.cc +102 -28
  53. data/ext/libcouchbase/src/internal.h +47 -29
  54. data/ext/libcouchbase/src/jsparse/parser.cc +146 -202
  55. data/ext/libcouchbase/src/jsparse/parser.h +91 -98
  56. data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
  57. data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
  58. data/ext/libcouchbase/src/lcbio/connect.cc +562 -0
  59. data/ext/libcouchbase/src/lcbio/connect.h +9 -2
  60. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  61. data/ext/libcouchbase/src/lcbio/iotable.h +61 -16
  62. data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
  63. data/ext/libcouchbase/src/lcbio/manager.c +2 -2
  64. data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
  65. data/ext/libcouchbase/src/mc/mcreq.h +9 -2
  66. data/ext/libcouchbase/src/mcserver/mcserver.cc +723 -0
  67. data/ext/libcouchbase/src/mcserver/mcserver.h +160 -70
  68. data/ext/libcouchbase/src/mcserver/negotiate.cc +118 -152
  69. data/ext/libcouchbase/src/mcserver/negotiate.h +85 -74
  70. data/ext/libcouchbase/src/mctx-helper.h +51 -0
  71. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
  72. data/ext/libcouchbase/src/n1ql/n1ql.cc +56 -32
  73. data/ext/libcouchbase/src/{newconfig.c → newconfig.cc} +42 -70
  74. data/ext/libcouchbase/src/nodeinfo.cc +4 -8
  75. data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
  76. data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
  77. data/ext/libcouchbase/src/operations/{durability-cas.c → durability-cas.cc} +92 -76
  78. data/ext/libcouchbase/src/operations/{durability-seqno.c → durability-seqno.cc} +55 -49
  79. data/ext/libcouchbase/src/operations/durability.cc +643 -0
  80. data/ext/libcouchbase/src/operations/durability_internal.h +212 -124
  81. data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
  82. data/ext/libcouchbase/src/operations/{observe-seqno.c → observe-seqno.cc} +5 -8
  83. data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +69 -94
  84. data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
  85. data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
  86. data/ext/libcouchbase/src/operations/{stats.c → stats.cc} +66 -78
  87. data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
  88. data/ext/libcouchbase/src/operations/subdoc.cc +38 -18
  89. data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
  90. data/ext/libcouchbase/src/packetutils.h +200 -137
  91. data/ext/libcouchbase/src/probes.d +1 -1
  92. data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +3 -4
  93. data/ext/libcouchbase/src/retryq.cc +394 -0
  94. data/ext/libcouchbase/src/retryq.h +116 -104
  95. data/ext/libcouchbase/src/settings.h +2 -1
  96. data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
  97. data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
  98. data/ext/libcouchbase/src/trace.h +8 -8
  99. data/ext/libcouchbase/src/vbucket/vbucket.c +0 -1
  100. data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
  101. data/ext/libcouchbase/src/views/docreq.h +24 -30
  102. data/ext/libcouchbase/src/views/viewreq.cc +318 -0
  103. data/ext/libcouchbase/src/views/viewreq.h +43 -13
  104. data/ext/libcouchbase/src/{wait.c → wait.cc} +12 -17
  105. data/ext/libcouchbase/tests/basic/t_connstr.cc +89 -50
  106. data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -78
  107. data/ext/libcouchbase/tests/basic/t_packet.cc +35 -42
  108. data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
  109. data/ext/libcouchbase/tests/iotests/t_confmon.cc +94 -111
  110. data/ext/libcouchbase/tests/iotests/t_sched.cc +1 -2
  111. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  112. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
  113. data/lib/libcouchbase/version.rb +1 -1
  114. metadata +36 -39
  115. data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
  116. data/ext/libcouchbase/src/bootstrap.c +0 -269
  117. data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +0 -495
  118. data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
  119. data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
  120. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
  121. data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
  122. data/ext/libcouchbase/src/getconfig.c +0 -100
  123. data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
  124. data/ext/libcouchbase/src/lcbio/connect.c +0 -557
  125. data/ext/libcouchbase/src/mcserver/mcserver.c +0 -784
  126. data/ext/libcouchbase/src/operations/durability.c +0 -668
  127. data/ext/libcouchbase/src/packetutils.c +0 -60
  128. data/ext/libcouchbase/src/retryq.c +0 -424
  129. data/ext/libcouchbase/src/simplestring.c +0 -211
  130. data/ext/libcouchbase/src/simplestring.h +0 -228
  131. data/ext/libcouchbase/src/ssobuf.h +0 -82
  132. data/ext/libcouchbase/src/views/viewreq.c +0 -358
  133. data/ext/libcouchbase/tests/basic/t_string.cc +0 -112
@@ -26,57 +26,82 @@
26
26
 
27
27
  #include "config.h"
28
28
  #include "hostlist.h"
29
- #include "simplestring.h"
30
29
  #include "clconfig.h"
31
30
  #include <lcbht/lcbht.h>
32
31
 
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"
32
+ #define REQBUCKET_COMPAT_PREFIX "/pools/default/bucketsStreaming/"
33
+ #define REQBUCKET_TERSE_PREFIX "/pools/default/bs/"
34
+
35
+ #define REQPOOLS_URI "/pools/"
36
36
  #define HOSTHDR_FMT "Host: %s:%s\r\n"
37
- #define AUTHDR_FMT "Authorization: Basic %s\r\n"
38
37
  #define LAST_HTTP_HEADER "X-Libcouchbase: " LCB_VERSION_STRING "\r\n"
39
38
  #define CONFIG_DELIMITER "\n\n\n\n"
40
39
 
41
- #ifdef __cplusplus
42
- extern "C" {
43
- #endif
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 */
44
72
 
45
- typedef struct clprovider_http_st {
46
73
  /** Base configuration structure */
47
- clconfig_provider base;
48
74
  lcbio_pCONNSTART creq;
49
75
  lcbio_CTX *ioctx;
50
- lcbht_pPARSER htp;
76
+ lcb::htparse::Parser* htp;
51
77
 
52
78
  /**
53
79
  * Buffer to use for writing our request header. Recreated for each
54
80
  * connection because of the Host: header
55
81
  */
56
- char request_buf[1024];
82
+ std::string request_buf;
57
83
 
58
84
  /**
59
85
  * We only recreate the connection if our current stream 'times out'. This
60
86
  * timer waits until the current stream times out and then proceeds to the
61
87
  * next connection.
62
88
  */
63
- lcbio_pTIMER disconn_timer;
64
- lcbio_pTIMER io_timer;
65
- lcbio_pTIMER as_reconnect;
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;
66
92
 
67
93
  /** List of hosts to try */
68
- hostlist_t nodes;
94
+ lcb::Hostlist *nodes;
69
95
 
70
96
  /** The cached configuration. */
71
- clconfig_info *current_config;
72
- clconfig_info *last_parsed;
73
- int generation;
74
- int try_nexturi;
75
- lcb_HTCONFIG_URLTYPE uritype;
76
- } http_provider;
97
+ ConfigInfo *current_config;
98
+ ConfigInfo *last_parsed;
77
99
 
78
- #ifdef __cplusplus
79
- }
80
- #endif
100
+ int generation;
101
+ bool try_nexturi;
102
+ int uritype;
103
+ };
81
104
 
105
+ } // namespace
106
+ } // namespace
82
107
  #endif /* LCB_CLPROVIDER_HTTP_H */
@@ -0,0 +1,115 @@
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 <lcbio/timer-cxx.h>
21
+ #include <libcouchbase/vbucket.h>
22
+ #include "clconfig.h"
23
+
24
+ #define LOGARGS(mcr, lvlbase) mcr->parent->settings, "mcraw", LCB_LOG_##lvlbase, __FILE__, __LINE__
25
+ #define LOGFMT "(MCRAW=%p)> "
26
+ #define LOGID(mcr) (void *)mcr
27
+
28
+ using namespace lcb::clconfig;
29
+
30
+ /* Raw memcached provider */
31
+
32
+ struct McRawProvider : Provider {
33
+ McRawProvider(Confmon*);
34
+ ~McRawProvider();
35
+
36
+ /* Overrides */
37
+ ConfigInfo* get_cached();
38
+ lcb_error_t refresh();
39
+ void configure_nodes(const lcb::Hostlist& l);
40
+ void async_update();
41
+
42
+ /* Current (user defined) configuration */
43
+ ConfigInfo *config;
44
+ lcb::io::Timer<McRawProvider, &McRawProvider::async_update> async;
45
+ };
46
+
47
+
48
+ void McRawProvider::async_update() {
49
+ if (!config) {
50
+ lcb_log(LOGARGS(this, WARN), "No current config set. Not setting configuration");
51
+ return;
52
+ }
53
+ parent->provider_got_config(this, config);
54
+ }
55
+
56
+ ConfigInfo* McRawProvider::get_cached() {
57
+ return config;
58
+ }
59
+
60
+ lcb_error_t McRawProvider::refresh() {
61
+ async.signal();
62
+ return LCB_SUCCESS;
63
+ }
64
+
65
+ void McRawProvider::configure_nodes(const lcb::Hostlist& hl)
66
+ {
67
+ lcbvb_SERVER *servers;
68
+ lcbvb_CONFIG *newconfig;
69
+ unsigned nsrv = hl.size();
70
+
71
+ if (!nsrv) {
72
+ lcb_log(LOGARGS(this, FATAL), "No nodes provided");
73
+ return;
74
+ }
75
+
76
+ servers = reinterpret_cast<lcbvb_SERVER*>(calloc(nsrv, sizeof(*servers)));
77
+ for (size_t ii = 0; ii < nsrv; ii++) {
78
+ const lcb_host_t& curhost = hl[ii];
79
+ lcbvb_SERVER *srv = servers + ii;
80
+
81
+ /* just set the memcached port and hostname */
82
+ srv->hostname = (char *)curhost.host;
83
+ srv->svc.data = std::atoi(curhost.port);
84
+ if (parent->settings->sslopts) {
85
+ srv->svc_ssl.data = srv->svc.data;
86
+ }
87
+ }
88
+
89
+ newconfig = lcbvb_create();
90
+ lcbvb_genconfig_ex(newconfig, "NOBUCKET", "deadbeef", servers, nsrv, 0, 2);
91
+ lcbvb_make_ketama(newconfig);
92
+ newconfig->revid = -1;
93
+
94
+ if (config) {
95
+ config->decref();
96
+ config = NULL;
97
+ }
98
+ config = ConfigInfo::create(newconfig, CLCONFIG_MCRAW);
99
+ }
100
+
101
+ McRawProvider::~McRawProvider() {
102
+ if (config) {
103
+ config->decref();
104
+ }
105
+ async.release();
106
+ }
107
+
108
+ Provider* lcb::clconfig::new_mcraw_provider(Confmon* parent) {
109
+ return new McRawProvider(parent);
110
+ }
111
+
112
+ McRawProvider::McRawProvider(Confmon *parent_)
113
+ : Provider(parent_, CLCONFIG_MCRAW),
114
+ config(NULL), async(parent->iot, this) {
115
+ }
@@ -19,12 +19,9 @@
19
19
  #define LCB_CLCONFIG_H
20
20
 
21
21
  #include "hostlist.h"
22
- #include "list.h"
23
- #include "simplestring.h"
22
+ #include <list>
24
23
  #include <lcbio/timer-ng.h>
25
- #ifdef __cplusplus
26
- extern "C" {
27
- #endif
24
+ #include <lcbio/timer-cxx.h>
28
25
 
29
26
  /** @file */
30
27
 
@@ -45,22 +42,22 @@ extern "C" {
45
42
  * <ol>
46
43
  *
47
44
  * <li>
48
- * There is a _Configuration Monitor_ object (lcb_confmon) which acts
45
+ * There is a _Configuration Monitor_ object (Confmon) which acts
49
46
  * as the configuration supervisor. It is responsible for returning
50
47
  * configuration objects to those entities which request it.
51
48
  * </li>
52
49
  *
53
50
  * <li>
54
- * There are multiple _Configuration Provider_ (clconfig_provider) objects.
51
+ * There are multiple _Configuration Provider_ (Provider) objects.
55
52
  * These providers aggregate configurations from multiple sources and
56
53
  * implement a common interface to:
57
54
  *
58
55
  * <ol>
59
56
  * <li>Return a _quick_ configuration without fetching from network or disk
60
- * (see clconfig_provider::get_cached())</i>
57
+ * (see Provider::get_cached())</i>
61
58
 
62
59
  * <li>Schedule a refresh to retrieve the latest configuration from the
63
- * network (see clconfig_provider::refresh())</li>
60
+ * network (see Provider::refresh())</li>
64
61
  *
65
62
  * <li>Notify the monitor that it has received a new configuration. The
66
63
  * monitor itself will determine whether or not to accept the new
@@ -72,7 +69,7 @@ extern "C" {
72
69
  * _Configuration Info_ objects. These objects are refcounted wrappers
73
70
  * around vbucket configuration handles. They have a refcount and also an
74
71
  * integer which can be used to compare with other objects for 'freshness'.
75
- * See clconfig_info
72
+ * See ConfigInfo
76
73
  * </li>
77
74
  *
78
75
  * <li>
@@ -80,7 +77,7 @@ extern "C" {
80
77
  * and are invoked whenever a new valid configuration is detected. This is
81
78
  * really only ever used during bootstrap or testing where we are explicitly
82
79
  * waiting for a configuration without having any actual commands to schedule.
83
- * See clconfig_listener
80
+ * See Listener
84
81
  * </li>
85
82
  * </ol>
86
83
  */
@@ -90,100 +87,323 @@ extern "C" {
90
87
  *@{
91
88
  */
92
89
 
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
- 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,
97
+ enum Method {
101
98
  /** File-based "configcache" provider. Implemented in bc_file.c */
102
- LCB_CLCONFIG_FILE,
99
+ CLCONFIG_FILE,
103
100
  /** New-style config-over-memcached provider. Implemented in bc_cccp.c */
104
- LCB_CLCONFIG_CCCP,
101
+ CLCONFIG_CCCP,
105
102
  /** Old-style streaming HTTP provider. Implemented in bc_http.c */
106
- LCB_CLCONFIG_HTTP,
103
+ CLCONFIG_HTTP,
107
104
  /** Raw memcached provided */
108
- LCB_CLCONFIG_MCRAW,
105
+ CLCONFIG_MCRAW,
109
106
 
110
- LCB_CLCONFIG_MAX,
107
+ CLCONFIG_MAX,
111
108
 
112
109
  /** Ephemeral source, used for tests */
113
- LCB_CLCONFIG_PHONY
114
- } clconfig_method_t;
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,
115
121
 
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
+ };
116
128
 
117
- struct clconfig_info_st;
118
- struct clconfig_provider_st;
119
- struct clconfig_listener_st;
120
- struct lcb_confmon_st;
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;
121
146
 
122
147
  /**
123
148
  * This object contains the information needed for libcouchbase to deal with
124
149
  * when retrieving new configs.
125
150
  */
126
- typedef struct lcb_confmon_st {
127
- /** Linked list of active/enabled providers */
128
- lcb_clist_t active_providers;
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);
129
352
 
130
353
  /**Current provider. This provider may either fail or succeed.
131
354
  * In either case unless the provider can provide us with a specific
132
355
  * config which is newer than the one we have, it will roll over to the
133
356
  * next provider. */
134
- struct clconfig_provider_st *cur_provider;
357
+ Provider *cur_provider;
135
358
 
136
359
  /** All providers we know about. Currently this means the 'builtin' providers */
137
- struct clconfig_provider_st * all_providers[LCB_CLCONFIG_MAX];
360
+ Provider* all_providers[CLCONFIG_MAX];
138
361
 
139
362
  /** The current configuration pointer. This contains the most recent accepted
140
363
  * configuration */
141
- struct clconfig_info_st * config;
364
+ ConfigInfo * config;
142
365
 
143
- /* CONFMON_S_* values. Used internally */
144
- int state;
366
+ typedef std::list<Listener*> ListenerList;
367
+ /** List of listeners for events */
368
+ ListenerList listeners;
145
369
 
146
- /** Last time the provider was stopped. As a microsecond timestamp */
147
- lcb_uint32_t last_stop_us;
370
+ lcb_settings *settings;
371
+ lcb_error_t last_error;
372
+ lcbio_pTABLE iot;
148
373
 
149
374
  /** This is the async handle for a reentrant start */
150
- lcbio_pTIMER as_start;
375
+ lcb::io::Timer<Confmon, &Confmon::do_next_provider> as_start;
151
376
 
152
377
  /** Async handle for a reentrant stop */
153
- lcbio_pTIMER as_stop;
378
+ lcb::io::Timer<Confmon, &Confmon::stop_real> as_stop;
154
379
 
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;
380
+ /* CONFMON_S_* values. Used internally */
381
+ int state;
382
+
383
+ /** Last time the provider was stopped. As a microsecond timestamp */
384
+ lcb_uint32_t last_stop_us;
385
+
386
+ typedef std::list<Provider*> ProviderList;
387
+ ProviderList active_providers;
388
+ };
161
389
 
162
390
  /**
163
391
  * The base structure of a provider. This structure is intended to be
164
392
  * 'subclassed' by implementors.
165
393
  */
166
- typedef struct clconfig_provider_st {
167
- lcb_list_t ll; /**< Node in linked list of active providers (if active) */
394
+ struct Provider {
395
+ Provider(Confmon*, Method type_);
168
396
 
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;
397
+ /** Destroy the resources created by this provider. */
398
+ virtual ~Provider();
177
399
 
178
400
  /**
179
401
  * Get the current map known to this provider. This should not perform
180
402
  * any blocking operations. Providers which use a push model may use
181
403
  * this method as an asynchronous return value for a previously-received
182
404
  * configuration.
183
- *
184
- * @param pb
185
405
  */
186
- struct clconfig_info_st* (*get_cached)(struct clconfig_provider_st *pb);
406
+ virtual ConfigInfo* get_cached() = 0;
187
407
 
188
408
 
189
409
  /**
@@ -202,7 +422,7 @@ typedef struct clconfig_provider_st {
202
422
  *
203
423
  * @param pb
204
424
  */
205
- lcb_error_t (*refresh)(struct clconfig_provider_st *pb);
425
+ virtual lcb_error_t refresh() = 0;
206
426
 
207
427
  /**
208
428
  * Callback invoked to the provider to indicate that it should cease
@@ -213,8 +433,11 @@ typedef struct clconfig_provider_st {
213
433
  * between 0 seconds and several minutes depending on how a user has
214
434
  * configured the client.
215
435
  * @param pb
436
+ * @return true if actually paused
216
437
  */
217
- lcb_error_t (*pause)(struct clconfig_provider_st *pb);
438
+ virtual bool pause() {
439
+ return false;
440
+ }
218
441
 
219
442
  /**
220
443
  * Called when a new configuration has been received.
@@ -224,64 +447,132 @@ typedef struct clconfig_provider_st {
224
447
  * Note that this should only update the server list and do nothing
225
448
  * else.
226
449
  */
227
- void (*config_updated)(struct clconfig_provider_st *provider,
228
- lcbvb_CONFIG* config);
450
+ virtual void config_updated(lcbvb_CONFIG*) {
451
+ }
229
452
 
230
453
  /**
231
454
  * Retrieve the list of nodes from this provider, if applicable
232
455
  * @param p the provider
233
456
  * @return A list of nodes, or NULL if the provider does not have a list
234
457
  */
235
- hostlist_t (*get_nodes)(const struct clconfig_provider_st *p);
458
+ virtual const lcb::Hostlist* get_nodes() const {
459
+ return NULL;
460
+ }
236
461
 
237
462
  /**
238
463
  * Call to change the configured nodes of this provider.
239
464
  * @param p The provider
240
465
  * @param l The list of nodes to apply
241
466
  */
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 *);
467
+ virtual void configure_nodes(const lcb::Hostlist&) {
468
+ }
246
469
 
247
470
  /**
248
471
  * Dump state information. This callback is optional
249
472
  * @param p the provider
250
473
  * @param f the file to write to
251
474
  */
252
- void (*dump)(struct clconfig_provider_st *p, FILE *f);
253
- } clconfig_provider;
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*);
254
504
 
255
505
 
256
506
  /** @brief refcounted object encapsulating a vbucket config */
257
- typedef struct clconfig_info_st {
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
+
258
559
  /** Actual configuration */
259
560
  lcbvb_CONFIG* vbc;
260
561
 
562
+ private:
563
+ ConfigInfo(lcbvb_CONFIG *vbc, Method origin);
564
+
565
+ ~ConfigInfo();
566
+
261
567
  /** Comparative clock with which to compare */
262
- lcb_uint64_t cmpclock;
568
+ uint64_t cmpclock;
263
569
 
264
570
  /** Reference counter */
265
571
  unsigned int refcount;
266
572
 
267
573
  /** Origin provider type which produced this config */
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;
574
+ Method origin;
575
+ };
285
576
 
286
577
  /**
287
578
  * @brief Listener for events
@@ -289,289 +580,25 @@ typedef enum {
289
580
  * a callback invoked on significant vbucket events. See clconfig_event_t
290
581
  * for a variety of events the listener can know.
291
582
  */
292
- typedef struct clconfig_listener_st {
583
+ struct Listener {
584
+ virtual ~Listener() {
585
+ }
586
+
293
587
  /** Linked list node */
294
588
  lcb_list_t ll;
295
589
 
296
- /** Monitor object */
297
- lcb_confmon *parent;
298
-
299
590
  /**
300
591
  * Callback invoked for significant events
301
592
  *
302
- * @param lsn the listener structure itself
303
593
  * @param event the event which took place
304
594
  * @param config the configuration associated with the event. Note that
305
595
  * `config` may also be NULL
306
596
  */
307
- void (*callback)(struct clconfig_listener_st *lsn, clconfig_event_t event,
308
- struct clconfig_info_st *config);
309
-
310
- } clconfig_listener;
597
+ virtual void clconfig_lsn(EventType event, ConfigInfo *config) = 0;
598
+ };
311
599
 
312
600
  /* Method-specific setup methods.. */
313
601
 
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
-
575
602
  /**
576
603
  * @name File Provider-specific APIs
577
604
  * @{
@@ -583,18 +610,17 @@ void lcb_confmon_dump(lcb_confmon *mon, FILE *fp);
583
610
  * @param p the provider
584
611
  * @param f the filename (if NULL, a temporary filename will be created)
585
612
  * @param ro whether the client will never modify the file
586
- * @return zero on success, nonzero on failure.
613
+ * @return true on success, false on failure.
587
614
  */
588
- int lcb_clconfig_file_set_filename(clconfig_provider *p, const char *f, int ro);
615
+ bool file_set_filename(Provider *p, const char *f, bool ro);
589
616
 
590
617
  /**
591
618
  * Retrieve the filename for the provider
592
619
  * @param p The provider of type LCB_CLCONFIG_FILE
593
620
  * @return the current filename being used.
594
621
  */
595
- const char * lcb_clconfig_file_get_filename(clconfig_provider *p);
596
-
597
- void lcb_clconfig_file_set_readonly(clconfig_provider *p, int val);
622
+ const char* file_get_filename(Provider *p);
623
+ void file_set_readonly(Provider *p, bool val);
598
624
  /**@}*/
599
625
 
600
626
  /**
@@ -608,30 +634,32 @@ void lcb_clconfig_file_set_readonly(clconfig_provider *p, int val);
608
634
  * @param mon
609
635
  * @return
610
636
  */
611
- lcbio_SOCKET* lcb_confmon_get_rest_connection(lcb_confmon *mon);
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
+ }
612
642
 
613
643
  /**
614
644
  * Get the hostname for the current REST connection to the cluster
615
645
  * @param mon
616
646
  * @return
617
647
  */
618
- lcb_host_t * lcb_confmon_get_rest_host(lcb_confmon *mon);
619
-
620
- /**
621
- * Enables the HTTP provider
622
- * @param pb a provider of type LCB_CLCONFIG_HTTP
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
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
+ }
627
652
  /**@}*/
628
653
 
629
654
  /**
630
655
  * @name CCCP Provider-specific APIs
631
656
  * @{
632
657
  */
633
- LCB_INTERNAL_API
634
- void lcb_clconfig_cccp_enable(clconfig_provider *pb, lcb_t instance);
658
+
659
+ /**
660
+ * Note, to initialize the CCCP provider, you should use
661
+ * cccp->enable(instance);
662
+ */
635
663
 
636
664
  /**
637
665
  * @brief Notify the CCCP provider about a new configuration from a
@@ -647,7 +675,7 @@ void lcb_clconfig_cccp_enable(clconfig_provider *pb, lcb_t instance);
647
675
  * set
648
676
  */
649
677
  lcb_error_t
650
- lcb_cccp_update(clconfig_provider *provider, const char *host, lcb_string *data);
678
+ cccp_update(Provider *provider, const char *host, const char *data);
651
679
 
652
680
  /**
653
681
  * @brief Notify the CCCP provider about a configuration received from a
@@ -659,23 +687,16 @@ lcb_cccp_update(clconfig_provider *provider, const char *host, lcb_string *data)
659
687
  * @param nbytes Size of payload
660
688
  * @param origin Host object from which the packet was received
661
689
  */
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);
690
+ void cccp_update(const void *cookie, lcb_error_t err,
691
+ const void *bytes, size_t nbytes, const lcb_host_t *origin);
665
692
 
666
- #define lcb_clconfig_cccp_set_nodes(pb, nodes) (pb)->configure_nodes(pb, nodes)
667
693
  /**@}*/
668
694
 
669
695
  /**@name Raw Memcached (MCRAW) Provider-specific APIs
670
696
  * @{*/
671
- LCB_INTERNAL_API
672
- lcb_error_t
673
- lcb_clconfig_mcraw_update(clconfig_provider *pb, const char *nodes);
674
697
  /**@}*/
675
-
676
698
  /**@}*/
677
699
 
678
- #ifdef __cplusplus
679
- }
680
- #endif /* __cplusplus */
700
+ } // clconfig
701
+ } // lcb
681
702
  #endif /* LCB_CLCONFIG_H */