libcouchbase 0.2.0 → 0.3.1

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 (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
@@ -0,0 +1,42 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2014 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #ifndef MEMCACHED_VBUCKET_H
19
+ #define MEMCACHED_VBUCKET_H 1
20
+
21
+ #ifdef __cplusplus
22
+ extern "C"
23
+ {
24
+ #endif
25
+
26
+ typedef enum {
27
+ vbucket_state_active = 1, /**< Actively servicing a vbucket. */
28
+ vbucket_state_replica, /**< Servicing a vbucket as a replica only. */
29
+ vbucket_state_pending, /**< Pending active. */
30
+ vbucket_state_dead /**< Not in use, pending deletion. */
31
+ } vbucket_state_t;
32
+
33
+ #define is_valid_vbucket_state_t(state) \
34
+ (state == vbucket_state_active || \
35
+ state == vbucket_state_replica || \
36
+ state == vbucket_state_pending || \
37
+ state == vbucket_state_dead)
38
+
39
+ #ifdef __cplusplus
40
+ }
41
+ #endif
42
+ #endif
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env perl
1
+ #!/usr/bin/perl
2
2
 
3
3
  use strict;
4
4
  use warnings;
@@ -48,12 +48,11 @@ extern "C" {
48
48
  * Create an instance of an event handler that utilize libev for
49
49
  * event notification.
50
50
  *
51
- * @param version Set this to 0. This may be used in the future to allow
52
- * variation on the third argument (`void*` currently).
53
- * @param[out] io a pointer to a newly created and initialized event handler
51
+ * @param version the API version to use
54
52
  * @param loop the event loop (struct ev_loop *) to hook use (please
55
53
  * note that you shouldn't reference the event loop from
56
54
  * multiple threads)
55
+ * @param io a pointer to a newly created and initialized event handler
57
56
  * @return status of the operation
58
57
  */
59
58
  LIBCOUCHBASE_API
@@ -43,6 +43,8 @@ listing of the various subcomponents and what they do:
43
43
 
44
44
  * `sllist.h, sllist-inl.h` contain the implementation for a single-linked list
45
45
 
46
+ * `simplestring.{c,h}` contains the implementation for a dynamically sized string
47
+
46
48
  * `logging.{c,h}` contains the implementation for the library's logging mechanism
47
49
 
48
50
  * `hostlist.{c,h}` defines a list of hosts, with features for de-duping and converting
@@ -14,7 +14,6 @@ public:
14
14
  const std::string& password() const { return m_password; }
15
15
  const Map& buckets() const { return m_buckets; }
16
16
  Authenticator() : m_refcount(1) {}
17
- Authenticator(const Authenticator&);
18
17
 
19
18
  size_t refcount() const { return m_refcount; }
20
19
  void incref() { ++m_refcount; }
@@ -90,16 +90,10 @@ Authenticator::init(const std::string& username_, const std::string& bucket,
90
90
  m_username = (!username_.empty()) ? username_ : bucket;
91
91
  m_password = passwd;
92
92
 
93
+ if (conntype == LCB_TYPE_BUCKET && m_username != bucket) {
94
+ return LCB_INVALID_USERNAME;
95
+ }
96
+
93
97
  m_buckets[bucket] = m_password;
94
98
  return LCB_SUCCESS;
95
99
  }
96
-
97
- Authenticator::Authenticator(const Authenticator& other)
98
- : m_buckets(other.m_buckets), m_username(other.m_username),
99
- m_password(other.m_password), m_refcount(1) {
100
- }
101
-
102
- lcb_AUTHENTICATOR *
103
- lcbauth_clone(const lcb_AUTHENTICATOR *src) {
104
- return new Authenticator(*src);
105
- }
@@ -0,0 +1,269 @@
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
+ #define LCB_BOOTSTRAP_DEFINE_STRUCT 1
19
+ #include "internal.h"
20
+
21
+
22
+ #define LOGARGS(instance, lvl) instance->settings, "bootstrap", LCB_LOG_##lvl, __FILE__, __LINE__
23
+
24
+ static void async_step_callback(clconfig_listener*,clconfig_event_t,clconfig_info*);
25
+ static void initial_bootstrap_error(lcb_t, lcb_error_t,const char*);
26
+
27
+ /**
28
+ * This function is where the configuration actually takes place. We ensure
29
+ * in other functions that this is only ever called directly from an event
30
+ * loop stack frame (or one of the small mini functions here) so that we
31
+ * don't accidentally end up destroying resources underneath us.
32
+ */
33
+ static void
34
+ config_callback(clconfig_listener *listener, clconfig_event_t event,
35
+ clconfig_info *info)
36
+ {
37
+ struct lcb_BOOTSTRAP *bs = (struct lcb_BOOTSTRAP *)listener;
38
+ lcb_t instance = bs->parent;
39
+
40
+ if (event != CLCONFIG_EVENT_GOT_NEW_CONFIG) {
41
+ if (event == CLCONFIG_EVENT_PROVIDERS_CYCLED) {
42
+ if (!LCBT_VBCONFIG(instance)) {
43
+ initial_bootstrap_error(
44
+ instance, LCB_ERROR, "No more bootstrap providers remain");
45
+ }
46
+ }
47
+ return;
48
+ }
49
+
50
+ instance->last_error = LCB_SUCCESS;
51
+ /** Ensure we're not called directly twice again */
52
+ listener->callback = async_step_callback;
53
+ lcbio_timer_disarm(bs->tm);
54
+
55
+ lcb_log(LOGARGS(instance, DEBUG), "Instance configured!");
56
+
57
+ if (info->origin != LCB_CLCONFIG_FILE) {
58
+ /* Set the timestamp for the current config to control throttling,
59
+ * but only if it's not an initial file-based config. See CCBC-482 */
60
+ bs->last_refresh = gethrtime();
61
+ bs->errcounter = 0;
62
+ }
63
+
64
+ if (info->origin == LCB_CLCONFIG_CCCP) {
65
+ /* Disable HTTP provider if we've received something via CCCP */
66
+
67
+ if (instance->cur_configinfo == NULL ||
68
+ instance->cur_configinfo->origin != LCB_CLCONFIG_HTTP) {
69
+ /* Never disable HTTP if it's still being used */
70
+ lcb_confmon_set_provider_active(
71
+ instance->confmon, LCB_CLCONFIG_HTTP, 0);
72
+ }
73
+ }
74
+
75
+ if (instance->type != LCB_TYPE_CLUSTER) {
76
+ lcb_update_vbconfig(instance, info);
77
+ }
78
+
79
+ if (!bs->bootstrapped) {
80
+ bs->bootstrapped = 1;
81
+ lcb_aspend_del(&instance->pendops, LCB_PENDTYPE_COUNTER, NULL);
82
+
83
+ if (instance->type == LCB_TYPE_BUCKET &&
84
+ LCBVB_DISTTYPE(LCBT_VBCONFIG(instance)) == LCBVB_DIST_KETAMA &&
85
+ instance->cur_configinfo->origin != LCB_CLCONFIG_MCRAW) {
86
+
87
+ lcb_log(LOGARGS(instance, INFO), "Reverting to HTTP Config for memcached buckets");
88
+ instance->settings->bc_http_stream_time = -1;
89
+ lcb_confmon_set_provider_active(
90
+ instance->confmon, LCB_CLCONFIG_HTTP, 1);
91
+ lcb_confmon_set_provider_active(
92
+ instance->confmon, LCB_CLCONFIG_CCCP, 0);
93
+ }
94
+ instance->callbacks.bootstrap(instance, LCB_SUCCESS);
95
+ }
96
+
97
+ lcb_maybe_breakout(instance);
98
+ }
99
+
100
+
101
+ static void
102
+ initial_bootstrap_error(lcb_t instance, lcb_error_t err, const char *errinfo)
103
+ {
104
+ struct lcb_BOOTSTRAP *bs = instance->bootstrap;
105
+
106
+ instance->last_error = lcb_confmon_last_error(instance->confmon);
107
+ if (instance->last_error == LCB_SUCCESS) {
108
+ instance->last_error = err;
109
+ }
110
+ instance->callbacks.error(instance, instance->last_error, errinfo);
111
+ lcb_log(LOGARGS(instance, ERR), "Failed to bootstrap client=%p. Code=0x%x, Message=%s", (void *)instance, err, errinfo);
112
+ lcbio_timer_disarm(bs->tm);
113
+
114
+ instance->callbacks.bootstrap(instance, instance->last_error);
115
+
116
+ lcb_aspend_del(&instance->pendops, LCB_PENDTYPE_COUNTER, NULL);
117
+ lcb_maybe_breakout(instance);
118
+ }
119
+
120
+ /**
121
+ * This it the initial bootstrap timeout handler. This timeout pins down the
122
+ * instance. It is only scheduled during the initial bootstrap and is only
123
+ * triggered if the initial bootstrap fails to configure in time.
124
+ */
125
+ static void initial_timeout(void *arg)
126
+ {
127
+ struct lcb_BOOTSTRAP *bs = arg;
128
+ initial_bootstrap_error(bs->parent, LCB_ETIMEDOUT, "Failed to bootstrap in time");
129
+ }
130
+
131
+ /**
132
+ * Proxy async call to config_callback
133
+ */
134
+ static void async_refresh(void *arg)
135
+ {
136
+ /** Get the best configuration and run stuff.. */
137
+ struct lcb_BOOTSTRAP *bs = arg;
138
+ clconfig_info *info;
139
+
140
+ info = lcb_confmon_get_config(bs->parent->confmon);
141
+ config_callback(&bs->listener, CLCONFIG_EVENT_GOT_NEW_CONFIG, info);
142
+ }
143
+
144
+ /**
145
+ * set_next listener callback which schedules an async call to our config
146
+ * callback.
147
+ */
148
+ static void
149
+ async_step_callback(clconfig_listener *listener, clconfig_event_t event,
150
+ clconfig_info *info)
151
+ {
152
+ struct lcb_BOOTSTRAP *bs = (struct lcb_BOOTSTRAP *)listener;
153
+
154
+ if (event != CLCONFIG_EVENT_GOT_NEW_CONFIG) {
155
+ return;
156
+ }
157
+
158
+ if (lcbio_timer_armed(bs->tm) && lcbio_timer_get_target(bs->tm) == async_refresh) {
159
+ lcb_log(LOGARGS(bs->parent, DEBUG), "Timer already present..");
160
+ return;
161
+ }
162
+
163
+ lcb_log(LOGARGS(bs->parent, INFO), "Got async step callback..");
164
+ lcbio_timer_set_target(bs->tm, async_refresh);
165
+ lcbio_async_signal(bs->tm);
166
+ (void)info;
167
+ }
168
+
169
+ lcb_error_t
170
+ lcb_bootstrap_common(lcb_t instance, int options)
171
+ {
172
+ struct lcb_BOOTSTRAP *bs = instance->bootstrap;
173
+ hrtime_t now = gethrtime();
174
+
175
+ if (!bs) {
176
+ bs = calloc(1, sizeof(*instance->bootstrap));
177
+ if (!bs) {
178
+ return LCB_CLIENT_ENOMEM;
179
+ }
180
+
181
+ bs->tm = lcbio_timer_new(instance->iotable, bs, initial_timeout);
182
+ instance->bootstrap = bs;
183
+ bs->parent = instance;
184
+ lcb_confmon_add_listener(instance->confmon, &bs->listener);
185
+ }
186
+
187
+ if (lcb_confmon_is_refreshing(instance->confmon)) {
188
+ return LCB_SUCCESS;
189
+ }
190
+
191
+ if (options & LCB_BS_REFRESH_THROTTLE) {
192
+ /* Refresh throttle requested. This is not true if options == ALWAYS */
193
+ hrtime_t next_ts;
194
+ unsigned errthresh = LCBT_SETTING(instance, weird_things_threshold);
195
+
196
+ if (options & LCB_BS_REFRESH_INCRERR) {
197
+ bs->errcounter++;
198
+ }
199
+ next_ts = bs->last_refresh;
200
+ next_ts += LCB_US2NS(LCBT_SETTING(instance, weird_things_delay));
201
+ if (now < next_ts && bs->errcounter < errthresh) {
202
+ lcb_log(LOGARGS(instance, INFO),
203
+ "Not requesting a config refresh because of throttling parameters. Next refresh possible in %ums or %u errors. "
204
+ "See LCB_CNTL_CONFDELAY_THRESH and LCB_CNTL_CONFERRTHRESH to modify the throttling settings",
205
+ LCB_NS2US(next_ts-now)/1000, (unsigned)errthresh-bs->errcounter);
206
+ return LCB_SUCCESS;
207
+ }
208
+ }
209
+
210
+ if (options == LCB_BS_REFRESH_INITIAL) {
211
+ lcb_confmon_prepare(instance->confmon);
212
+
213
+ bs->listener.callback = config_callback;
214
+ lcbio_timer_set_target(bs->tm, initial_timeout);
215
+ lcbio_timer_rearm(bs->tm, LCBT_SETTING(instance, config_timeout));
216
+ lcb_aspend_add(&instance->pendops, LCB_PENDTYPE_COUNTER, NULL);
217
+ } else {
218
+ /** No initial timer */
219
+ bs->listener.callback = async_step_callback;
220
+ }
221
+
222
+ /* Reset the counters */
223
+ bs->errcounter = 0;
224
+ if (options != LCB_BS_REFRESH_INITIAL) {
225
+ bs->last_refresh = now;
226
+ }
227
+ return lcb_confmon_start(instance->confmon);
228
+ }
229
+
230
+ void lcb_bootstrap_destroy(lcb_t instance)
231
+ {
232
+ struct lcb_BOOTSTRAP *bs = instance->bootstrap;
233
+ if (!bs) {
234
+ return;
235
+ }
236
+ if (bs->tm) {
237
+ lcbio_timer_destroy(bs->tm);
238
+ }
239
+
240
+ lcb_confmon_remove_listener(instance->confmon, &bs->listener);
241
+ free(bs);
242
+ instance->bootstrap = NULL;
243
+ }
244
+
245
+ LIBCOUCHBASE_API
246
+ lcb_error_t
247
+ lcb_get_bootstrap_status(lcb_t instance)
248
+ {
249
+ if (instance->cur_configinfo) {
250
+ return LCB_SUCCESS;
251
+ }
252
+ if (instance->last_error != LCB_SUCCESS) {
253
+ return instance->last_error;
254
+ }
255
+ if (instance->type == LCB_TYPE_CLUSTER) {
256
+ lcbio_SOCKET *restconn = lcb_confmon_get_rest_connection(instance->confmon);
257
+ if (restconn) {
258
+ return LCB_SUCCESS;
259
+ }
260
+ }
261
+ return LCB_ERROR;
262
+ }
263
+
264
+ LIBCOUCHBASE_API
265
+ void
266
+ lcb_refresh_config(lcb_t instance)
267
+ {
268
+ lcb_bootstrap_common(instance, LCB_BS_REFRESH_ALWAYS);
269
+ }
@@ -17,6 +17,9 @@
17
17
 
18
18
  #ifndef LCB_BOOTSTRAP_H
19
19
  #define LCB_BOOTSTRAP_H
20
+ #ifdef __cplusplus
21
+ extern "C" {
22
+ #endif
20
23
 
21
24
  /**@file
22
25
  * Core bootstrap/cluster configuration routines */
@@ -26,43 +29,19 @@
26
29
  * @{
27
30
  */
28
31
 
29
- #ifdef __cplusplus
32
+ #if defined(__LCB_DOXYGEN__) || defined(LCB_BOOTSTRAP_DEFINE_STRUCT)
30
33
  #include "bucketconfig/clconfig.h"
31
- #include <lcbio/timer-cxx.h>
32
34
 
33
- namespace lcb {
34
35
  /**
35
36
  * Structure containing the bootstrap state for the instance.
36
- *
37
- * Derived from Listener,
38
- * used to react when a new configuration is received. This
39
- * is used for both requested configurations (i.e. an explicit call to
40
- * lcb_bootstrap_common()) as well as unsolicited updates such as
41
- * HTTP streaming configurations or Not-My-Vbucket "Carrier" updates.
42
37
  */
43
- class Bootstrap : lcb::clconfig::Listener {
44
- public:
45
- Bootstrap(lcb_t);
46
- ~Bootstrap();
47
- lcb_error_t bootstrap(unsigned options);
48
-
49
- hrtime_t get_last_refresh() const {
50
- return last_refresh;
51
- }
52
- void reset_last_refresh() {
53
- last_refresh = 0;
54
- }
55
- size_t get_errcounter() const {
56
- return errcounter;
57
- }
58
-
59
- private:
60
- // Override
61
- void clconfig_lsn(lcb::clconfig::EventType e, lcb::clconfig::ConfigInfo* i);
62
-
63
- inline void config_callback(lcb::clconfig::EventType, lcb::clconfig::ConfigInfo*);
64
- inline void initial_error(lcb_error_t, const char *);
65
- void timer_dispatch();
38
+ struct lcb_BOOTSTRAP {
39
+ /**Listener object used to react when a new configuration is received. This
40
+ * is used for both requested configurations (i.e. an explicit call to
41
+ * lcb_bootstrap_common()) as well as unsolicited updates such as
42
+ * HTTP streaming configurations or Not-My-Vbucket "Carrier" updates.
43
+ */
44
+ clconfig_listener listener;
66
45
 
67
46
  lcb_t parent;
68
47
 
@@ -70,7 +49,7 @@ private:
70
49
  * updates as an asynchronous event (to allow safe updates and avoid
71
50
  * reentrancy issues)
72
51
  */
73
- lcb::io::Timer<Bootstrap, &Bootstrap::timer_dispatch> tm;
52
+ lcbio_pTIMER tm;
74
53
 
75
54
  /**
76
55
  * Timestamp indicating the most recent configuration activity. This
@@ -94,47 +73,57 @@ private:
94
73
  */
95
74
  unsigned errcounter;
96
75
 
97
- enum State {
98
- /** Initial 'blank' state */
99
- S_INITIAL_PRE = 0,
100
- /** We got something after our initial callback */
101
- S_INITIAL_TRIGGERED,
102
- /** Have received at least one valid configuration */
103
- S_BOOTSTRAPPED
104
- };
105
- State state;
76
+ /** Flag indicating whether the _initial_ configuration has been received */
77
+ int bootstrapped;
106
78
  };
79
+ #endif
107
80
 
108
81
  /**
109
82
  * These flags control the bootstrap refreshing mode that will take place
110
83
  * when lcb_bootstrap_common() is invoked. These options may be OR'd with
111
84
  * each other (with the exception of ::LCB_BS_REFRESH_ALWAYS).
112
85
  */
113
- enum BootstrapOptions {
86
+ typedef enum {
114
87
  /** Always fetch a new configuration. No throttling checks are performed */
115
- BS_REFRESH_ALWAYS = 0x00,
88
+ LCB_BS_REFRESH_ALWAYS = 0x00,
116
89
  /** Special mode used to fetch the first configuration */
117
- BS_REFRESH_INITIAL = 0x02,
90
+ LCB_BS_REFRESH_INITIAL = 0x02,
118
91
 
119
92
  /** Make the request for a new configuration subject to throttling
120
93
  * limitations. Currently this will be subject to the interval specified
121
94
  * in the @ref LCB_CNTL_CONFDELAY_THRESH setting and the @ref
122
95
  * LCB_CNTL_CONFERRTHRESH setting. If the refresh has been throttled
123
96
  * the lcb_confmon_is_refreshing() function will return false */
124
- BS_REFRESH_THROTTLE = 0x04,
97
+ LCB_BS_REFRESH_THROTTLE = 0x04,
125
98
 
126
99
  /** To be used in conjunction with ::LCB_BS_REFRESH_THROTTLE, this will
127
100
  * increment the error counter in case the current refresh is throttled,
128
101
  * such that when the error counter reaches the threshold, the throttle
129
102
  * limitations will expire and a new refresh will take place */
130
- BS_REFRESH_INCRERR = 0x08
131
- };
103
+ LCB_BS_REFRESH_INCRERR = 0x08
104
+ } lcb_BSFLAGS;
105
+
106
+ /**
107
+ * @brief Request that the handle update its configuration.
108
+ *
109
+ * This function acts as a gateway to the more abstract confmon interface.
110
+ *
111
+ * @param instance The instance
112
+ * @param options A set of options specified as flags, indicating under what
113
+ * conditions a new configuration should be refetched.
114
+ *
115
+ * @return
116
+ */
117
+ LCB_INTERNAL_API
118
+ lcb_error_t
119
+ lcb_bootstrap_common(lcb_t instance, int options);
132
120
 
133
121
  void
134
122
  lcb_bootstrap_destroy(lcb_t instance);
135
123
 
136
124
  /**@}*/
137
125
 
138
- } // namespace lcb
139
- #endif // __cplusplus
126
+ #ifdef __cplusplus
127
+ }
128
+ #endif
140
129
  #endif /* LCB_BOOTSTRAP_H */