libcouchbase 0.3.3 → 1.0.0
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.
- checksums.yaml +4 -4
- data/ext/libcouchbase/CMakeLists.txt +6 -8
- data/ext/libcouchbase/README.markdown +2 -2
- data/ext/libcouchbase/RELEASE_NOTES.markdown +229 -2
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +18 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +3 -2
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
- data/ext/libcouchbase/cmake/config-cmake.h.in +4 -0
- data/ext/libcouchbase/cmake/defs.mk.in +0 -2
- data/ext/libcouchbase/cmake/source_files.cmake +21 -5
- data/ext/libcouchbase/contrib/cJSON/cJSON.c +1 -1
- data/ext/libcouchbase/contrib/cbsasl/src/client.c +2 -0
- data/ext/libcouchbase/example/users/README +48 -0
- data/ext/libcouchbase/example/users/users.c +147 -0
- data/ext/libcouchbase/include/libcouchbase/auth.h +175 -31
- data/ext/libcouchbase/include/libcouchbase/cntl.h +82 -1
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +45 -3
- data/ext/libcouchbase/include/libcouchbase/error.h +19 -1
- data/ext/libcouchbase/include/libcouchbase/iops.h +3 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +31 -1
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +4 -1
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +36 -2
- data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
- data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
- data/ext/libcouchbase/include/memcached/protocol_binary.h +24 -1146
- data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
- data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
- data/ext/libcouchbase/src/README.md +0 -2
- data/ext/libcouchbase/src/auth-priv.h +23 -4
- data/ext/libcouchbase/src/auth.cc +51 -43
- data/ext/libcouchbase/src/bootstrap.cc +244 -0
- data/ext/libcouchbase/src/bootstrap.h +58 -38
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +120 -158
- data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +526 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
- data/ext/libcouchbase/src/bucketconfig/bc_static.cc +150 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +410 -386
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +393 -0
- data/ext/libcouchbase/src/cbft.cc +22 -27
- data/ext/libcouchbase/src/cntl.cc +56 -22
- data/ext/libcouchbase/src/connspec.cc +47 -6
- data/ext/libcouchbase/src/connspec.h +27 -0
- data/ext/libcouchbase/src/dns-srv.cc +147 -0
- data/ext/libcouchbase/src/dump.cc +3 -3
- data/ext/libcouchbase/src/errmap.cc +173 -0
- data/ext/libcouchbase/src/errmap.h +198 -0
- data/ext/libcouchbase/src/getconfig.cc +7 -33
- data/ext/libcouchbase/src/handler.cc +118 -7
- data/ext/libcouchbase/src/hostlist.cc +0 -36
- data/ext/libcouchbase/src/hostlist.h +44 -62
- data/ext/libcouchbase/src/http/http-priv.h +125 -112
- data/ext/libcouchbase/src/http/http.cc +27 -35
- data/ext/libcouchbase/src/http/http.h +1 -34
- data/ext/libcouchbase/src/http/http_io.cc +28 -36
- data/ext/libcouchbase/src/instance.cc +131 -34
- data/ext/libcouchbase/src/internal.h +58 -26
- data/ext/libcouchbase/src/jsparse/parser.cc +136 -210
- data/ext/libcouchbase/src/jsparse/parser.h +84 -98
- data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
- data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
- data/ext/libcouchbase/src/lcbio/connect.cc +569 -0
- data/ext/libcouchbase/src/lcbio/connect.h +16 -7
- data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
- data/ext/libcouchbase/src/lcbio/iotable.h +101 -16
- data/ext/libcouchbase/src/lcbio/{ioutils.c → ioutils.cc} +30 -51
- data/ext/libcouchbase/src/lcbio/ioutils.h +29 -90
- data/ext/libcouchbase/src/lcbio/manager.cc +543 -0
- data/ext/libcouchbase/src/lcbio/manager.h +133 -96
- data/ext/libcouchbase/src/lcbio/protoctx.c +2 -2
- data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
- data/ext/libcouchbase/src/mc/mcreq.c +11 -2
- data/ext/libcouchbase/src/mc/mcreq.h +9 -2
- data/ext/libcouchbase/src/mcserver/mcserver.cc +175 -43
- data/ext/libcouchbase/src/mcserver/mcserver.h +9 -13
- data/ext/libcouchbase/src/mcserver/negotiate.cc +181 -62
- data/ext/libcouchbase/src/mcserver/negotiate.h +1 -3
- data/ext/libcouchbase/src/mctx-helper.h +51 -0
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
- data/ext/libcouchbase/src/n1ql/n1ql.cc +74 -42
- data/ext/libcouchbase/src/netbuf/netbuf.c +4 -4
- data/ext/libcouchbase/src/newconfig.cc +6 -6
- data/ext/libcouchbase/src/nodeinfo.cc +2 -2
- data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
- data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
- data/ext/libcouchbase/src/operations/durability.cc +6 -26
- data/ext/libcouchbase/src/operations/durability_internal.h +6 -3
- data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
- data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +68 -93
- data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
- data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
- data/ext/libcouchbase/src/operations/stats.cc +3 -8
- data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
- data/ext/libcouchbase/src/operations/subdoc.cc +129 -42
- data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
- data/ext/libcouchbase/src/packetutils.h +30 -2
- data/ext/libcouchbase/src/probes.d +1 -1
- data/ext/libcouchbase/src/rdb/rope.c +1 -1
- data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +2 -3
- data/ext/libcouchbase/src/retryq.cc +52 -14
- data/ext/libcouchbase/src/retryq.h +3 -3
- data/ext/libcouchbase/src/settings.c +5 -0
- data/ext/libcouchbase/src/settings.h +11 -0
- data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
- data/ext/libcouchbase/src/ssl/ssl_common.c +2 -0
- data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
- data/ext/libcouchbase/src/strcodecs/strcodecs.h +1 -1
- data/ext/libcouchbase/src/trace.h +4 -4
- data/ext/libcouchbase/src/vbucket/vbucket.c +6 -10
- data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
- data/ext/libcouchbase/src/views/docreq.h +24 -30
- data/ext/libcouchbase/src/views/viewreq.cc +318 -0
- data/ext/libcouchbase/src/views/viewreq.h +43 -13
- data/ext/libcouchbase/tests/basic/t_connstr.cc +88 -50
- data/ext/libcouchbase/tests/basic/t_creds.cc +47 -5
- data/ext/libcouchbase/tests/basic/t_host.cc +67 -75
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -82
- data/ext/libcouchbase/tests/basic/t_misc.cc +1 -1
- data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +0 -1
- data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
- data/ext/libcouchbase/tests/ioserver/connection.cc +1 -1
- data/ext/libcouchbase/tests/ioserver/ioserver.cc +19 -6
- data/ext/libcouchbase/tests/iotests/mock-environment.cc +28 -2
- data/ext/libcouchbase/tests/iotests/mock-environment.h +51 -1
- data/ext/libcouchbase/tests/iotests/t_behavior.cc +1 -7
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +97 -115
- data/ext/libcouchbase/tests/iotests/t_durability.cc +0 -1
- data/ext/libcouchbase/tests/iotests/t_eerrs.cc +119 -0
- data/ext/libcouchbase/tests/iotests/t_errmap.cc +178 -0
- data/ext/libcouchbase/tests/iotests/t_misc.cc +3 -3
- data/ext/libcouchbase/tests/iotests/t_netfail.cc +1 -1
- data/ext/libcouchbase/tests/iotests/t_obseqno.cc +0 -1
- data/ext/libcouchbase/tests/iotests/t_subdoc.cc +18 -11
- data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
- data/ext/libcouchbase/tests/socktests/socktest.cc +7 -10
- data/ext/libcouchbase/tests/socktests/socktest.h +2 -3
- data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
- data/ext/libcouchbase/tests/socktests/t_manager.cc +5 -6
- data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
- data/ext/libcouchbase/tests/vbucket/confdata/ketama_expected.json +2562 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_ketama_config.json +31 -0
- data/ext/libcouchbase/tests/vbucket/t_config.cc +35 -5
- data/ext/libcouchbase/tools/CMakeLists.txt +2 -2
- data/ext/libcouchbase/tools/cbc-handlers.h +128 -0
- data/ext/libcouchbase/tools/cbc-n1qlback.cc +64 -10
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +2 -2
- data/ext/libcouchbase/tools/cbc.cc +143 -10
- data/ext/libcouchbase/tools/docgen/loc.h +1 -1
- data/lib/libcouchbase/connection.rb +4 -3
- data/lib/libcouchbase/version.rb +1 -1
- metadata +37 -28
- data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
- data/ext/libcouchbase/src/bootstrap.c +0 -269
- data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
- data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
- data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
- data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
- data/ext/libcouchbase/src/lcbio/connect.c +0 -557
- data/ext/libcouchbase/src/lcbio/manager.c +0 -584
- data/ext/libcouchbase/src/packetutils.c +0 -37
- data/ext/libcouchbase/src/simplestring.c +0 -211
- data/ext/libcouchbase/src/simplestring.h +0 -228
- data/ext/libcouchbase/src/ssobuf.h +0 -82
- data/ext/libcouchbase/src/views/viewreq.c +0 -358
- data/ext/libcouchbase/tests/basic/t_string.cc +0 -112
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2013 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 "internal.h"
|
|
19
|
+
#include "clconfig.h"
|
|
20
|
+
#include <list>
|
|
21
|
+
#include <algorithm>
|
|
22
|
+
|
|
23
|
+
#define LOGARGS(mon, lvlbase) mon->settings, "confmon", LCB_LOG_##lvlbase, __FILE__, __LINE__
|
|
24
|
+
#define LOG(mon, lvlbase, msg) lcb_log(mon->settings, "confmon", LCB_LOG_##lvlbase, __FILE__, __LINE__, msg)
|
|
25
|
+
|
|
26
|
+
using namespace lcb::clconfig;
|
|
27
|
+
|
|
28
|
+
Provider* Confmon::next_active(Provider *cur) {
|
|
29
|
+
ProviderList::iterator ii = std::find(
|
|
30
|
+
active_providers.begin(), active_providers.end(), cur);
|
|
31
|
+
|
|
32
|
+
if (ii == active_providers.end() || (++ii) == active_providers.end()) {
|
|
33
|
+
return NULL;
|
|
34
|
+
} else {
|
|
35
|
+
return *ii;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Provider* Confmon::first_active()
|
|
40
|
+
{
|
|
41
|
+
if (active_providers.empty()) {
|
|
42
|
+
return NULL;
|
|
43
|
+
} else {
|
|
44
|
+
return active_providers.front();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static const char *
|
|
49
|
+
provider_string(Method type) {
|
|
50
|
+
if (type == CLCONFIG_HTTP) { return "HTTP"; }
|
|
51
|
+
if (type == CLCONFIG_CCCP) { return "CCCP"; }
|
|
52
|
+
if (type == CLCONFIG_FILE) { return "FILE"; }
|
|
53
|
+
if (type == CLCONFIG_MCRAW) { return "MCRAW"; }
|
|
54
|
+
if (type == CLCONFIG_CLADMIN) { return "CLADMIN"; }
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Confmon::Confmon(lcb_settings *settings_, lcbio_pTABLE iot_)
|
|
59
|
+
: cur_provider(NULL),
|
|
60
|
+
config(NULL),
|
|
61
|
+
settings(settings_),
|
|
62
|
+
last_error(LCB_SUCCESS),
|
|
63
|
+
iot(iot_),
|
|
64
|
+
as_start(iot_, this),
|
|
65
|
+
as_stop(iot_, this),
|
|
66
|
+
state(0),
|
|
67
|
+
last_stop_us(0) {
|
|
68
|
+
|
|
69
|
+
lcbio_table_ref(iot);
|
|
70
|
+
lcb_settings_ref(settings);
|
|
71
|
+
|
|
72
|
+
all_providers[CLCONFIG_FILE] = new_file_provider(this);
|
|
73
|
+
all_providers[CLCONFIG_CCCP] = new_cccp_provider(this);
|
|
74
|
+
all_providers[CLCONFIG_HTTP] = new_http_provider(this);
|
|
75
|
+
all_providers[CLCONFIG_MCRAW] = new_mcraw_provider(this);
|
|
76
|
+
all_providers[CLCONFIG_CLADMIN] = new_cladmin_provider(this);
|
|
77
|
+
|
|
78
|
+
for (size_t ii = 0; ii < CLCONFIG_MAX; ii++) {
|
|
79
|
+
all_providers[ii]->parent = this;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
void Confmon::prepare() {
|
|
84
|
+
active_providers.clear();
|
|
85
|
+
lcb_log(LOGARGS(this, DEBUG), "Preparing providers (this may be called multiple times)");
|
|
86
|
+
|
|
87
|
+
for (size_t ii = 0; ii < CLCONFIG_MAX; ii++) {
|
|
88
|
+
Provider *cur = all_providers[ii];
|
|
89
|
+
if (cur) {
|
|
90
|
+
if (cur->enabled) {
|
|
91
|
+
active_providers.push_back(cur);
|
|
92
|
+
lcb_log(LOGARGS(this, DEBUG), "Provider %s is ENABLED", provider_string(cur->type));
|
|
93
|
+
} else if (cur->pause()) {
|
|
94
|
+
lcb_log(LOGARGS(this, DEBUG), "Provider %s is DISABLED", provider_string(cur->type));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
lcb_assert(!active_providers.empty());
|
|
100
|
+
cur_provider = first_active();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
Confmon::~Confmon() {
|
|
104
|
+
as_start.release();
|
|
105
|
+
as_stop.release();
|
|
106
|
+
|
|
107
|
+
if (config) {
|
|
108
|
+
config->decref();
|
|
109
|
+
config = NULL;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
for (size_t ii = 0; ii < CLCONFIG_MAX; ii++) {
|
|
113
|
+
Provider *provider = all_providers[ii];
|
|
114
|
+
if (provider == NULL) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
delete provider;
|
|
118
|
+
all_providers[ii] = NULL;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
lcbio_table_unref(iot);
|
|
122
|
+
lcb_settings_unref(settings);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
int Confmon::do_set_next(ConfigInfo *new_config, bool notify_miss)
|
|
126
|
+
{
|
|
127
|
+
unsigned ii;
|
|
128
|
+
|
|
129
|
+
if (config && new_config == config) {
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
if (config) {
|
|
133
|
+
lcbvb_CHANGETYPE chstatus = LCBVB_NO_CHANGES;
|
|
134
|
+
lcbvb_CONFIGDIFF *diff = lcbvb_compare(config->vbc, new_config->vbc);
|
|
135
|
+
|
|
136
|
+
if (!diff) {
|
|
137
|
+
lcb_log(LOGARGS(this, DEBUG), "Couldn't create vbucket diff");
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
chstatus = lcbvb_get_changetype(diff);
|
|
142
|
+
lcbvb_free_diff(diff);
|
|
143
|
+
|
|
144
|
+
if (chstatus == 0 || config->compare(*new_config) >= 0) {
|
|
145
|
+
const lcbvb_CONFIG *ca, *cb;
|
|
146
|
+
|
|
147
|
+
ca = config->vbc;
|
|
148
|
+
cb = new_config->vbc;
|
|
149
|
+
|
|
150
|
+
lcb_log(LOGARGS(this, INFO), "Not applying configuration received via %s. No changes detected. A.rev=%d, B.rev=%d", provider_string(new_config->get_origin()), ca->revid, cb->revid);
|
|
151
|
+
if (notify_miss) {
|
|
152
|
+
invoke_listeners(CLCONFIG_EVENT_GOT_ANY_CONFIG, new_config);
|
|
153
|
+
}
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
lcb_log(LOGARGS(this, INFO), "Setting new configuration. Received via %s", provider_string(new_config->get_origin()));
|
|
159
|
+
|
|
160
|
+
if (config) {
|
|
161
|
+
/** DECREF the old one */
|
|
162
|
+
config->decref();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (ii = 0; ii < CLCONFIG_MAX; ii++) {
|
|
166
|
+
Provider *cur = all_providers[ii];
|
|
167
|
+
if (cur && cur->enabled) {
|
|
168
|
+
cur->config_updated(new_config->vbc);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
new_config->incref();
|
|
173
|
+
config = new_config;
|
|
174
|
+
stop();
|
|
175
|
+
|
|
176
|
+
invoke_listeners(CLCONFIG_EVENT_GOT_NEW_CONFIG, new_config);
|
|
177
|
+
|
|
178
|
+
return 1;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
void Confmon::provider_failed(Provider *provider, lcb_error_t reason) {
|
|
182
|
+
lcb_log(LOGARGS(this, INFO), "Provider '%s' failed", provider_string(provider->type));
|
|
183
|
+
|
|
184
|
+
if (provider != cur_provider) {
|
|
185
|
+
lcb_log(LOGARGS(this, TRACE), "Ignoring failure. Current=%p (%s)", (void*)cur_provider, provider_string(cur_provider->type));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (!is_refreshing()) {
|
|
189
|
+
lcb_log(LOGARGS(this, DEBUG), "Ignoring failure. Refresh not active");
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (reason != LCB_SUCCESS) {
|
|
193
|
+
if (settings->detailed_neterr && last_error != LCB_SUCCESS) {
|
|
194
|
+
/* Filter out any artificial 'connect error' or 'network error' codes */
|
|
195
|
+
if (reason != LCB_CONNECT_ERROR && reason != LCB_NETWORK_ERROR) {
|
|
196
|
+
last_error = reason;
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
last_error = reason;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (settings->conntype == LCB_TYPE_CLUSTER && provider->type == CLCONFIG_HTTP) {
|
|
204
|
+
Provider *cladmin = get_provider(CLCONFIG_CLADMIN);
|
|
205
|
+
if (!cladmin->enabled) {
|
|
206
|
+
cladmin->enable();
|
|
207
|
+
cladmin->configure_nodes(*provider->get_nodes());
|
|
208
|
+
active_providers.push_back(cladmin);
|
|
209
|
+
lcb_log(LOGARGS(this, DEBUG), "Static configuration provider has been enabled");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
cur_provider = next_active(cur_provider);
|
|
214
|
+
|
|
215
|
+
if (!cur_provider) {
|
|
216
|
+
LOG(this, TRACE, "Maximum provider reached. Resetting index");
|
|
217
|
+
invoke_listeners(CLCONFIG_EVENT_PROVIDERS_CYCLED, NULL);
|
|
218
|
+
cur_provider = first_active();
|
|
219
|
+
stop();
|
|
220
|
+
} else {
|
|
221
|
+
uint32_t interval = 0;
|
|
222
|
+
if (config) {
|
|
223
|
+
/* Not first */
|
|
224
|
+
interval = settings->grace_next_provider;
|
|
225
|
+
}
|
|
226
|
+
lcb_log(LOGARGS(this, DEBUG), "Will try next provider in %uus", interval);
|
|
227
|
+
state |= CONFMON_S_ITERGRACE;
|
|
228
|
+
as_start.rearm(interval);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
void Confmon::provider_got_config(Provider *, ConfigInfo *config_) {
|
|
233
|
+
do_set_next(config_, true);
|
|
234
|
+
stop();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
void Confmon::do_next_provider()
|
|
238
|
+
{
|
|
239
|
+
state &= ~CONFMON_S_ITERGRACE;
|
|
240
|
+
for (ProviderList::const_iterator ii = active_providers.begin();
|
|
241
|
+
ii != active_providers.end(); ++ii) {
|
|
242
|
+
ConfigInfo *info;
|
|
243
|
+
Provider* cached_provider = *ii;
|
|
244
|
+
info = cached_provider->get_cached();
|
|
245
|
+
if (!info) {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (do_set_next(info, false)) {
|
|
250
|
+
LOG(this, DEBUG, "Using cached configuration");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
lcb_log(LOGARGS(this, TRACE), "Attempting to retrieve cluster map via %s", provider_string(cur_provider->type));
|
|
255
|
+
|
|
256
|
+
cur_provider->refresh();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
void Confmon::start() {
|
|
260
|
+
lcb_U32 tmonext = 0;
|
|
261
|
+
as_stop.cancel();
|
|
262
|
+
if (is_refreshing()) {
|
|
263
|
+
LOG(this, DEBUG, "Cluster map refresh already in progress");
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
LOG(this, TRACE, "Refreshing current cluster map");
|
|
268
|
+
lcb_assert(cur_provider);
|
|
269
|
+
state = CONFMON_S_ACTIVE|CONFMON_S_ITERGRACE;
|
|
270
|
+
|
|
271
|
+
if (last_stop_us > 0) {
|
|
272
|
+
lcb_U32 diff = LCB_NS2US(gethrtime()) - last_stop_us;
|
|
273
|
+
if (diff <= settings->grace_next_cycle) {
|
|
274
|
+
tmonext = settings->grace_next_cycle - diff;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
as_start.rearm(tmonext);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
void Confmon::stop_real() {
|
|
282
|
+
ProviderList::const_iterator ii;
|
|
283
|
+
for (ii = active_providers.begin(); ii != active_providers.end(); ++ii) {
|
|
284
|
+
(*ii)->pause();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
last_stop_us = LCB_NS2US(gethrtime());
|
|
288
|
+
invoke_listeners(CLCONFIG_EVENT_MONITOR_STOPPED, NULL);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
void Confmon::stop() {
|
|
292
|
+
if (!is_refreshing()) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
as_start.cancel();
|
|
296
|
+
as_stop.cancel();
|
|
297
|
+
state = CONFMON_S_INACTIVE;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
Provider::Provider(Confmon *parent_, Method type_)
|
|
301
|
+
: type(type_), enabled(false), parent(parent_) {
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
Provider::~Provider() {
|
|
305
|
+
parent = NULL;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
ConfigInfo::~ConfigInfo() {
|
|
309
|
+
if (vbc) {
|
|
310
|
+
lcbvb_destroy(vbc);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
int ConfigInfo::compare(const ConfigInfo& other) {
|
|
315
|
+
/** First check if both have revisions */
|
|
316
|
+
int rev_a, rev_b;
|
|
317
|
+
rev_a = lcbvb_get_revision(this->vbc);
|
|
318
|
+
rev_b = lcbvb_get_revision(other.vbc);
|
|
319
|
+
if (rev_a >= 0 && rev_b >= 0) {
|
|
320
|
+
return rev_a - rev_b;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (this->cmpclock == other.cmpclock) {
|
|
324
|
+
return 0;
|
|
325
|
+
|
|
326
|
+
} else if (this->cmpclock < other.cmpclock) {
|
|
327
|
+
return -1;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return 1;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
ConfigInfo::ConfigInfo(lcbvb_CONFIG *config_, Method origin_)
|
|
334
|
+
: vbc(config_), cmpclock(gethrtime()), refcount(1), origin(origin_) {
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
void Confmon::add_listener(Listener *lsn) {
|
|
338
|
+
listeners.push_back(lsn);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
void Confmon::remove_listener(Listener *lsn) {
|
|
342
|
+
listeners.remove(lsn);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
void Confmon::invoke_listeners(EventType event, ConfigInfo *info) {
|
|
346
|
+
ListenerList::iterator ii = listeners.begin();
|
|
347
|
+
while (ii != listeners.end()) {
|
|
348
|
+
ListenerList::iterator cur = ii++;
|
|
349
|
+
(*cur)->clconfig_lsn(event, info);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
void Confmon::set_active(Method type, bool enabled)
|
|
355
|
+
{
|
|
356
|
+
Provider *provider = all_providers[type];
|
|
357
|
+
if (provider->enabled == enabled) {
|
|
358
|
+
return;
|
|
359
|
+
} else {
|
|
360
|
+
provider->enabled = enabled;
|
|
361
|
+
}
|
|
362
|
+
prepare();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
void Confmon::dump(FILE *fp) {
|
|
366
|
+
fprintf(fp, "CONFMON=%p\n", (void*)this);
|
|
367
|
+
fprintf(fp, "STATE= (0x%x)", state);
|
|
368
|
+
if (state & CONFMON_S_ACTIVE) {
|
|
369
|
+
fprintf(fp, "ACTIVE|");
|
|
370
|
+
}
|
|
371
|
+
if (state == CONFMON_S_INACTIVE) {
|
|
372
|
+
fprintf(fp, "INACTIVE/IDLE");
|
|
373
|
+
}
|
|
374
|
+
if (state & CONFMON_S_ITERGRACE) {
|
|
375
|
+
fprintf(fp, "ITERGRACE");
|
|
376
|
+
}
|
|
377
|
+
fprintf(fp, "\n");
|
|
378
|
+
fprintf(fp, "LAST ERROR: 0x%x\n", last_error);
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
for (size_t ii = 0; ii < CLCONFIG_MAX; ii++) {
|
|
382
|
+
Provider *cur = all_providers[ii];
|
|
383
|
+
if (!cur) {
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
fprintf(fp, "** PROVIDER: 0x%x (%s) %p\n", cur->type, provider_string(cur->type), (void*)cur);
|
|
388
|
+
fprintf(fp, "** ENABLED: %s\n", cur->enabled ? "YES" : "NO");
|
|
389
|
+
fprintf(fp, "** CURRENT: %s\n", cur == cur_provider ? "YES" : "NO");
|
|
390
|
+
cur->dump(fp);
|
|
391
|
+
fprintf(fp, "\n");
|
|
392
|
+
}
|
|
393
|
+
}
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
#define LOGID(req) static_cast<const void*>(req)
|
|
28
28
|
#define LOGARGS(req, lvl) req->instance->settings, "n1ql", LCB_LOG_##lvl, __FILE__, __LINE__
|
|
29
29
|
|
|
30
|
-
struct lcb_FTSREQ {
|
|
30
|
+
struct lcb_FTSREQ : lcb::jsparse::Parser::Actions {
|
|
31
31
|
const lcb_RESPHTTP *cur_htresp;
|
|
32
32
|
lcb_http_request_t htreq;
|
|
33
|
-
|
|
33
|
+
lcb::jsparse::Parser *parser;
|
|
34
34
|
const void *cookie;
|
|
35
35
|
lcb_FTSCALLBACK callback;
|
|
36
36
|
lcb_t instance;
|
|
@@ -41,25 +41,20 @@ struct lcb_FTSREQ {
|
|
|
41
41
|
|
|
42
42
|
lcb_FTSREQ(lcb_t, const void *, const lcb_CMDFTS *);
|
|
43
43
|
~lcb_FTSREQ();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
lcb_RESPFTS resp = { 0 };
|
|
51
|
-
|
|
52
|
-
if (datum->type == LCBJSP_TYPE_ROW) {
|
|
53
|
-
resp.row = static_cast<const char*>(datum->row.iov_base);
|
|
54
|
-
resp.nrow = datum->row.iov_len;
|
|
55
|
-
req->nrows++;
|
|
56
|
-
req->invoke_row(&resp);
|
|
57
|
-
} else if (datum->type == LCBJSP_TYPE_ERROR) {
|
|
58
|
-
req->lasterr = resp.rc = LCB_PROTOCOL_ERROR;
|
|
59
|
-
} else if (datum->type == LCBJSP_TYPE_COMPLETE) {
|
|
60
|
-
/* Nothing */
|
|
44
|
+
void JSPARSE_on_row(const lcb::jsparse::Row& datum) {
|
|
45
|
+
lcb_RESPFTS resp = { 0 };
|
|
46
|
+
resp.row = static_cast<const char*>(datum.row.iov_base);
|
|
47
|
+
resp.nrow = datum.row.iov_len;
|
|
48
|
+
nrows++;
|
|
49
|
+
invoke_row(&resp);
|
|
61
50
|
}
|
|
62
|
-
|
|
51
|
+
void JSPARSE_on_error(const std::string&) {
|
|
52
|
+
lasterr = LCB_PROTOCOL_ERROR;
|
|
53
|
+
}
|
|
54
|
+
void JSPARSE_on_complete(const std::string&) {
|
|
55
|
+
// Nothing
|
|
56
|
+
}
|
|
57
|
+
};
|
|
63
58
|
|
|
64
59
|
static void
|
|
65
60
|
chunk_callback(lcb_t, int, const lcb_RESPBASE *rb)
|
|
@@ -83,7 +78,7 @@ chunk_callback(lcb_t, int, const lcb_RESPBASE *rb)
|
|
|
83
78
|
* should remain alive (so we can cancel it later on) */
|
|
84
79
|
delete req;
|
|
85
80
|
} else {
|
|
86
|
-
|
|
81
|
+
req->parser->feed(static_cast<const char*>(rh->body), rh->nbody);
|
|
87
82
|
}
|
|
88
83
|
}
|
|
89
84
|
|
|
@@ -107,7 +102,7 @@ lcb_FTSREQ::invoke_last()
|
|
|
107
102
|
|
|
108
103
|
if (parser) {
|
|
109
104
|
lcb_IOV meta;
|
|
110
|
-
|
|
105
|
+
parser->get_postmortem(meta);
|
|
111
106
|
resp.row = static_cast<const char*>(meta.iov_base);
|
|
112
107
|
resp.nrow = meta.iov_len;
|
|
113
108
|
}
|
|
@@ -116,7 +111,9 @@ lcb_FTSREQ::invoke_last()
|
|
|
116
111
|
}
|
|
117
112
|
|
|
118
113
|
lcb_FTSREQ::lcb_FTSREQ(lcb_t instance_, const void *cookie_, const lcb_CMDFTS *cmd)
|
|
119
|
-
:
|
|
114
|
+
: lcb::jsparse::Parser::Actions(),
|
|
115
|
+
cur_htresp(NULL), htreq(NULL),
|
|
116
|
+
parser(new lcb::jsparse::Parser(lcb::jsparse::Parser::MODE_FTS, this)),
|
|
120
117
|
cookie(cookie_), callback(cmd->callback), instance(instance_), nrows(0),
|
|
121
118
|
lasterr(LCB_SUCCESS)
|
|
122
119
|
{
|
|
@@ -165,12 +162,10 @@ lcb_FTSREQ::lcb_FTSREQ(lcb_t instance_, const void *cookie_, const lcb_CMDFTS *c
|
|
|
165
162
|
std::string qbody(Json::FastWriter().write(root));
|
|
166
163
|
htcmd.body = qbody.c_str();
|
|
167
164
|
htcmd.nbody = qbody.size();
|
|
168
|
-
parser->data = this;
|
|
169
|
-
parser->callback = row_callback;
|
|
170
165
|
|
|
171
166
|
lasterr = lcb_http3(instance, this, &htcmd);
|
|
172
167
|
if (lasterr == LCB_SUCCESS) {
|
|
173
|
-
|
|
168
|
+
htreq->set_callback(chunk_callback);
|
|
174
169
|
if (cmd->handle) {
|
|
175
170
|
*cmd->handle = reinterpret_cast<lcb_FTSREQ*>(this);
|
|
176
171
|
}
|
|
@@ -184,7 +179,7 @@ lcb_FTSREQ::~lcb_FTSREQ()
|
|
|
184
179
|
htreq = NULL;
|
|
185
180
|
}
|
|
186
181
|
if (parser) {
|
|
187
|
-
|
|
182
|
+
delete parser;
|
|
188
183
|
parser = NULL;
|
|
189
184
|
}
|
|
190
185
|
}
|