libcouchbase 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libcouchbase/.gitignore +2 -0
- data/ext/libcouchbase/CMakeLists.txt +5 -7
- data/ext/libcouchbase/README.markdown +2 -2
- data/ext/libcouchbase/RELEASE_NOTES.markdown +49 -0
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +2 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +2 -1
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
- data/ext/libcouchbase/cmake/config-cmake.h.in +2 -0
- data/ext/libcouchbase/cmake/defs.mk.in +0 -2
- data/ext/libcouchbase/cmake/source_files.cmake +34 -14
- data/ext/libcouchbase/configure.pl +1 -1
- data/ext/libcouchbase/contrib/genhash/genhash.h +6 -0
- data/ext/libcouchbase/include/libcouchbase/auth.h +10 -0
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +10 -0
- data/ext/libcouchbase/include/libcouchbase/error.h +7 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +13 -1
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +9 -0
- 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 +21 -1132
- 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 +1 -0
- data/ext/libcouchbase/src/auth.cc +10 -0
- data/ext/libcouchbase/src/bootstrap.cc +216 -0
- data/ext/libcouchbase/src/bootstrap.h +50 -39
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +455 -0
- data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +528 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +115 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +407 -386
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +378 -0
- data/ext/libcouchbase/src/cbft.cc +22 -27
- data/ext/libcouchbase/src/cntl.cc +24 -24
- data/ext/libcouchbase/src/connspec.cc +30 -1
- data/ext/libcouchbase/src/connspec.h +17 -0
- data/ext/libcouchbase/src/dns-srv.cc +143 -0
- data/ext/libcouchbase/src/{dump.c → dump.cc} +8 -11
- data/ext/libcouchbase/src/getconfig.cc +73 -0
- data/ext/libcouchbase/src/handler.cc +84 -85
- data/ext/libcouchbase/src/hostlist.cc +0 -1
- data/ext/libcouchbase/src/hostlist.h +6 -1
- data/ext/libcouchbase/src/http/http-priv.h +125 -112
- data/ext/libcouchbase/src/http/http.cc +9 -29
- data/ext/libcouchbase/src/http/http.h +1 -34
- data/ext/libcouchbase/src/http/http_io.cc +22 -26
- data/ext/libcouchbase/src/instance.cc +102 -28
- data/ext/libcouchbase/src/internal.h +47 -29
- data/ext/libcouchbase/src/jsparse/parser.cc +146 -202
- data/ext/libcouchbase/src/jsparse/parser.h +91 -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 +562 -0
- data/ext/libcouchbase/src/lcbio/connect.h +9 -2
- data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
- data/ext/libcouchbase/src/lcbio/iotable.h +61 -16
- data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
- data/ext/libcouchbase/src/lcbio/manager.c +2 -2
- data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
- data/ext/libcouchbase/src/mc/mcreq.h +9 -2
- data/ext/libcouchbase/src/mcserver/mcserver.cc +723 -0
- data/ext/libcouchbase/src/mcserver/mcserver.h +160 -70
- data/ext/libcouchbase/src/mcserver/negotiate.cc +118 -152
- data/ext/libcouchbase/src/mcserver/negotiate.h +85 -74
- 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 +56 -32
- data/ext/libcouchbase/src/{newconfig.c → newconfig.cc} +42 -70
- data/ext/libcouchbase/src/nodeinfo.cc +4 -8
- 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-cas.c → durability-cas.cc} +92 -76
- data/ext/libcouchbase/src/operations/{durability-seqno.c → durability-seqno.cc} +55 -49
- data/ext/libcouchbase/src/operations/durability.cc +643 -0
- data/ext/libcouchbase/src/operations/durability_internal.h +212 -124
- data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
- data/ext/libcouchbase/src/operations/{observe-seqno.c → observe-seqno.cc} +5 -8
- data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +69 -94
- 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.c → stats.cc} +66 -78
- data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
- data/ext/libcouchbase/src/operations/subdoc.cc +38 -18
- data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
- data/ext/libcouchbase/src/packetutils.h +200 -137
- data/ext/libcouchbase/src/probes.d +1 -1
- data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +3 -4
- data/ext/libcouchbase/src/retryq.cc +394 -0
- data/ext/libcouchbase/src/retryq.h +116 -104
- data/ext/libcouchbase/src/settings.h +2 -1
- data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
- data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
- data/ext/libcouchbase/src/trace.h +8 -8
- data/ext/libcouchbase/src/vbucket/vbucket.c +0 -1
- 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/src/{wait.c → wait.cc} +12 -17
- data/ext/libcouchbase/tests/basic/t_connstr.cc +89 -50
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -78
- data/ext/libcouchbase/tests/basic/t_packet.cc +35 -42
- data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +94 -111
- data/ext/libcouchbase/tests/iotests/t_sched.cc +1 -2
- data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
- data/lib/libcouchbase/version.rb +1 -1
- metadata +36 -39
- data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
- data/ext/libcouchbase/src/bootstrap.c +0 -269
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +0 -495
- 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/getconfig.c +0 -100
- data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
- data/ext/libcouchbase/src/lcbio/connect.c +0 -557
- data/ext/libcouchbase/src/mcserver/mcserver.c +0 -784
- data/ext/libcouchbase/src/operations/durability.c +0 -668
- data/ext/libcouchbase/src/packetutils.c +0 -60
- data/ext/libcouchbase/src/retryq.c +0 -424
- 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
@@ -198,7 +198,7 @@ HANDLER(get_kvb) {
|
|
198
198
|
|
199
199
|
|
200
200
|
HANDLER(conninfo) {
|
201
|
-
lcbio_SOCKET *sock;
|
201
|
+
const lcbio_SOCKET *sock;
|
202
202
|
lcb_cntl_server_st *si = reinterpret_cast<lcb_cntl_server_st*>(arg);
|
203
203
|
const lcb_host_t *host;
|
204
204
|
|
@@ -206,25 +206,25 @@ HANDLER(conninfo) {
|
|
206
206
|
if (si->version < 0 || si->version > 1) { return LCB_ECTL_BADARG; }
|
207
207
|
|
208
208
|
if (cmd == LCB_CNTL_MEMDNODE_INFO) {
|
209
|
-
|
209
|
+
lcb::Server *server;
|
210
210
|
int ix = si->v.v0.index;
|
211
211
|
|
212
212
|
if (ix < 0 || ix > (int)LCBT_NSERVERS(instance)) {
|
213
213
|
return LCB_ECTL_BADARG;
|
214
214
|
}
|
215
|
-
server =
|
215
|
+
server = instance->get_server(ix);
|
216
216
|
if (!server) {
|
217
217
|
return LCB_NETWORK_ERROR;
|
218
218
|
}
|
219
219
|
sock = server->connctx->sock;
|
220
220
|
if (si->version == 1 && sock) {
|
221
|
-
|
222
|
-
if (
|
223
|
-
si->v.v1.sasl_mech =
|
221
|
+
lcb::SessionInfo *info = lcb::SessionInfo::get(server->connctx->sock);
|
222
|
+
if (info) {
|
223
|
+
si->v.v1.sasl_mech = info->get_mech().c_str();
|
224
224
|
}
|
225
225
|
}
|
226
226
|
} else if (cmd == LCB_CNTL_CONFIGNODE_INFO) {
|
227
|
-
sock =
|
227
|
+
sock = lcb::clconfig::http_get_conn(instance->confmon);
|
228
228
|
} else {
|
229
229
|
return LCB_ECTL_BADARG;
|
230
230
|
}
|
@@ -246,7 +246,8 @@ HANDLER(conninfo) {
|
|
246
246
|
|
247
247
|
HANDLER(config_cache_loaded_handler) {
|
248
248
|
if (mode != LCB_CNTL_GET) { return LCB_ECTL_UNSUPPMODE; }
|
249
|
-
*(int *)arg = instance->cur_configinfo &&
|
249
|
+
*(int *)arg = instance->cur_configinfo &&
|
250
|
+
instance->cur_configinfo->get_origin() == lcb::clconfig::CLCONFIG_FILE;
|
250
251
|
(void)cmd; return LCB_SUCCESS;
|
251
252
|
}
|
252
253
|
|
@@ -282,9 +283,9 @@ HANDLER(config_transport) {
|
|
282
283
|
if (mode == LCB_CNTL_SET) { return LCB_ECTL_UNSUPPMODE; }
|
283
284
|
if (!instance->cur_configinfo) { return LCB_CLIENT_ETMPFAIL; }
|
284
285
|
|
285
|
-
switch (instance->cur_configinfo->
|
286
|
-
case
|
287
|
-
case
|
286
|
+
switch (instance->cur_configinfo->get_origin()) {
|
287
|
+
case lcb::clconfig::CLCONFIG_HTTP: *val = LCB_CONFIG_TRANSPORT_HTTP; break;
|
288
|
+
case lcb::clconfig::CLCONFIG_CCCP: *val = LCB_CONFIG_TRANSPORT_CCCP; break;
|
288
289
|
default: return LCB_CLIENT_ETMPFAIL;
|
289
290
|
}
|
290
291
|
(void)cmd; return LCB_SUCCESS;
|
@@ -292,7 +293,7 @@ HANDLER(config_transport) {
|
|
292
293
|
|
293
294
|
HANDLER(config_nodes) {
|
294
295
|
const char *node_strs = reinterpret_cast<const char*>(arg);
|
295
|
-
|
296
|
+
lcb::clconfig::Provider *target;
|
296
297
|
lcb::Hostlist hostlist;
|
297
298
|
lcb_error_t err;
|
298
299
|
|
@@ -309,13 +310,13 @@ HANDLER(config_nodes) {
|
|
309
310
|
}
|
310
311
|
|
311
312
|
if (cmd == LCB_CNTL_CONFIG_HTTP_NODES) {
|
312
|
-
target =
|
313
|
-
lcb_clconfig_http_set_nodes(target, &hostlist);
|
313
|
+
target = instance->confmon->get_provider(lcb::clconfig::CLCONFIG_HTTP);
|
314
314
|
} else {
|
315
|
-
target =
|
316
|
-
lcb_clconfig_cccp_set_nodes(target, &hostlist);
|
315
|
+
target = instance->confmon->get_provider(lcb::clconfig::CLCONFIG_CCCP);
|
317
316
|
}
|
318
317
|
|
318
|
+
target->configure_nodes(hostlist);
|
319
|
+
|
319
320
|
return LCB_SUCCESS;
|
320
321
|
}
|
321
322
|
|
@@ -327,22 +328,22 @@ HANDLER(init_providers) {
|
|
327
328
|
}
|
328
329
|
|
329
330
|
HANDLER(config_cache_handler) {
|
330
|
-
|
331
|
+
using namespace lcb::clconfig;
|
332
|
+
Provider *provider;
|
331
333
|
|
332
|
-
provider =
|
334
|
+
provider = instance->confmon->get_provider(lcb::clconfig::CLCONFIG_FILE);
|
333
335
|
if (mode == LCB_CNTL_SET) {
|
334
|
-
|
335
|
-
rv = lcb_clconfig_file_set_filename(provider,
|
336
|
+
bool rv = file_set_filename(provider,
|
336
337
|
reinterpret_cast<const char*>(arg),
|
337
338
|
cmd == LCB_CNTL_CONFIGCACHE_RO);
|
338
339
|
|
339
|
-
if (rv
|
340
|
+
if (rv) {
|
340
341
|
instance->settings->bc_http_stream_time = LCB_MS2US(10000);
|
341
342
|
return LCB_SUCCESS;
|
342
343
|
}
|
343
344
|
return LCB_ERROR;
|
344
345
|
} else {
|
345
|
-
*(const char **)arg =
|
346
|
+
*(const char **)arg = file_get_filename(provider);
|
346
347
|
return LCB_SUCCESS;
|
347
348
|
}
|
348
349
|
}
|
@@ -470,8 +471,7 @@ HANDLER(mutation_tokens_supported_handler) {
|
|
470
471
|
*(int *)arg = 0;
|
471
472
|
|
472
473
|
for (ii = 0; ii < LCBT_NSERVERS(instance); ii++) {
|
473
|
-
|
474
|
-
if (s->mutation_tokens) {
|
474
|
+
if (instance->get_server(ii)->supports_mutation_tokens()) {
|
475
475
|
*(int *)arg = 1;
|
476
476
|
break;
|
477
477
|
}
|
@@ -31,6 +31,8 @@
|
|
31
31
|
#define F_HASUSER (1<<2)
|
32
32
|
#define F_SSLSCHEME (1<<3)
|
33
33
|
#define F_FILEONLY (1<<4)
|
34
|
+
#define F_DNSSRV (1<<5)
|
35
|
+
#define F_DNSSRV_EXPLICIT ( (1<<6) |F_DNSSRV)
|
34
36
|
|
35
37
|
using namespace lcb;
|
36
38
|
|
@@ -104,6 +106,14 @@ Connspec::parse_hosts(const char *hostbegin,
|
|
104
106
|
port = scratch.substr(colonpos + 1);
|
105
107
|
}
|
106
108
|
|
109
|
+
if (m_flags & F_DNSSRV_EXPLICIT) {
|
110
|
+
if (!m_hosts.empty()) {
|
111
|
+
SET_ERROR("Only a single host is allowed with DNS SRV");
|
112
|
+
} else if (!port.empty()) {
|
113
|
+
SET_ERROR("Port cannot be specified with DNS SRV");
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
107
117
|
m_hosts.resize(m_hosts.size() + 1);
|
108
118
|
Spechost *dh = &m_hosts.back();
|
109
119
|
dh->hostname = scratch.substr(0, hostlen);
|
@@ -288,10 +298,17 @@ Connspec::parse(const char *connstr_, const char **errmsg)
|
|
288
298
|
m_implicit_port = 0;
|
289
299
|
} else if (SCHEME_MATCHES(LCB_SPECSCHEME_MCCOMPAT)) {
|
290
300
|
m_implicit_port = LCB_CONFIG_MCCOMPAT_PORT;
|
301
|
+
} else if (SCHEME_MATCHES(LCB_SPECSCHEME_SRV)) {
|
302
|
+
m_implicit_port = LCB_CONFIG_MCD_PORT;
|
303
|
+
m_flags |= F_DNSSRV_EXPLICIT;
|
304
|
+
} else if (SCHEME_MATCHES(LCB_SPECSCHEME_SRV_SSL)) {
|
305
|
+
m_implicit_port = LCB_CONFIG_MCD_SSL_PORT;
|
306
|
+
m_sslopts |= LCB_SSL_ENABLED;
|
307
|
+
m_flags |= F_SSLSCHEME | F_DNSSRV_EXPLICIT;
|
291
308
|
} else {
|
292
309
|
/* If we don't have a scheme at all: */
|
293
310
|
if (strstr(connstr_, "://")) {
|
294
|
-
SET_ERROR("String must begin with '
|
311
|
+
SET_ERROR("String must begin with 'couchbase://, 'couchbases://', or 'http://'");
|
295
312
|
} else {
|
296
313
|
found_scheme = "";
|
297
314
|
m_implicit_port = LCB_CONFIG_HTTP_PORT;
|
@@ -345,6 +362,8 @@ Connspec::parse(const char *connstr_, const char **errmsg)
|
|
345
362
|
if (m_hosts.empty()) {
|
346
363
|
m_hosts.resize(m_hosts.size()+1);
|
347
364
|
m_hosts.back().hostname = "localhost";
|
365
|
+
} else if (m_hosts.size() == 1 && m_hosts[0].isTypeless()) {
|
366
|
+
m_flags |= F_DNSSRV;
|
348
367
|
}
|
349
368
|
|
350
369
|
if (options_ != NULL) {
|
@@ -460,3 +479,13 @@ Connspec::load(const lcb_create_st& cropts)
|
|
460
479
|
GT_DONE:
|
461
480
|
return err;
|
462
481
|
}
|
482
|
+
|
483
|
+
bool
|
484
|
+
Connspec::can_dnssrv() const {
|
485
|
+
return m_flags & F_DNSSRV;
|
486
|
+
}
|
487
|
+
|
488
|
+
bool
|
489
|
+
Connspec::is_explicit_dnssrv() const {
|
490
|
+
return (m_flags & F_DNSSRV_EXPLICIT) == F_DNSSRV_EXPLICIT;
|
491
|
+
}
|
@@ -73,6 +73,18 @@ public:
|
|
73
73
|
bool is_bs_http() const { return has_bsmode(LCB_CONFIG_TRANSPORT_HTTP); }
|
74
74
|
bool is_bs_cccp() const { return has_bsmode(LCB_CONFIG_TRANSPORT_CCCP); }
|
75
75
|
bool is_bs_file() const { return m_flags & LCB_CONNSPEC_F_FILEONLY; }
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Whether a DNS SRV lookup can be performed on this connection string.
|
79
|
+
* @return true if a DNS SRV lookup is possible, or false if there is
|
80
|
+
* a parameter or format of the connection string preventing a lookup
|
81
|
+
*/
|
82
|
+
bool can_dnssrv() const;
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Whether the explicit `couchbase{s}+dnssrv` internal scheme is used
|
86
|
+
*/
|
87
|
+
bool is_explicit_dnssrv() const;
|
76
88
|
uint16_t default_port() const { return m_implicit_port; }
|
77
89
|
const std::vector<Spechost>& hosts() const { return m_hosts; }
|
78
90
|
const std::string& bucket() const { return m_bucket; }
|
@@ -83,6 +95,8 @@ public:
|
|
83
95
|
const Options& options() const { return m_ctlopts; }
|
84
96
|
unsigned loglevel() const { return m_loglevel; }
|
85
97
|
const std::string& connstr() const { return m_connstr; }
|
98
|
+
void clear_hosts() { m_hosts.clear(); }
|
99
|
+
void add_host(const Spechost& host) { m_hosts.push_back(host); }
|
86
100
|
private:
|
87
101
|
Options m_ctlopts;
|
88
102
|
std::string m_bucket;
|
@@ -110,7 +124,10 @@ private:
|
|
110
124
|
#define LCB_SPECSCHEME_HTTP "http://"
|
111
125
|
#define LCB_SPECSCHEME_HTTP_SSL "https-internal://"
|
112
126
|
#define LCB_SPECSCHEME_MCCOMPAT "memcached://"
|
127
|
+
#define LCB_SPECSCHEME_SRV "couchbase+dnssrv://"
|
128
|
+
#define LCB_SPECSCHEME_SRV_SSL "couchbases+dnssrv://"
|
113
129
|
} // namespace
|
130
|
+
|
114
131
|
#endif
|
115
132
|
|
116
133
|
#ifdef _MSC_VER
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#include <libcouchbase/couchbase.h>
|
2
|
+
|
3
|
+
#include "config.h"
|
4
|
+
#include "hostlist.h"
|
5
|
+
|
6
|
+
#ifndef _WIN32
|
7
|
+
#include <string>
|
8
|
+
|
9
|
+
#ifdef HAVE_ARPA_NAMESER_H
|
10
|
+
#include <arpa/nameser.h>
|
11
|
+
#if __NAMESER < 19991006
|
12
|
+
#undef HAVE_RES_SEARCH
|
13
|
+
#endif /* __NAMESER < NNN */
|
14
|
+
#endif /* HAVE_ARPA_NAMESER_H */
|
15
|
+
|
16
|
+
#if defined(HAVE_ARPA_NAMESER_H) && defined(HAVE_RES_SEARCH)
|
17
|
+
#define CAN_SRV_LOOKUP
|
18
|
+
#include <cstdio>
|
19
|
+
#include <sys/types.h>
|
20
|
+
#include <netinet/in.h>
|
21
|
+
#include <resolv.h>
|
22
|
+
|
23
|
+
LCB_INTERNAL_API
|
24
|
+
lcb_error_t
|
25
|
+
lcb_dnssrv_query(const char *name, hostlist_t hostlist)
|
26
|
+
{
|
27
|
+
ns_msg msg;
|
28
|
+
|
29
|
+
int rv = 0, nresp, ii;
|
30
|
+
lcb_U16 dns_rv;
|
31
|
+
|
32
|
+
std::vector<unsigned char> pkt(NS_PACKETSZ);
|
33
|
+
nresp = res_search(name, ns_c_in, ns_t_srv, &pkt[0], NS_PACKETSZ);
|
34
|
+
if (nresp < 0) {
|
35
|
+
return LCB_UNKNOWN_HOST;
|
36
|
+
}
|
37
|
+
|
38
|
+
rv = ns_initparse(&pkt[0], nresp, &msg);
|
39
|
+
if (rv != 0) {
|
40
|
+
return LCB_PROTOCOL_ERROR;
|
41
|
+
}
|
42
|
+
|
43
|
+
dns_rv = ns_msg_getflag(msg, ns_f_rcode);
|
44
|
+
if (dns_rv != ns_r_noerror) {
|
45
|
+
return LCB_UNKNOWN_HOST;
|
46
|
+
}
|
47
|
+
|
48
|
+
if (!ns_msg_count(msg, ns_s_an)) {
|
49
|
+
return LCB_UNKNOWN_HOST;
|
50
|
+
}
|
51
|
+
|
52
|
+
for (ii = 0; ii < ns_msg_count(msg, ns_s_an); ii++) {
|
53
|
+
lcb_U16 srv_prio, srv_weight, srv_port;
|
54
|
+
ns_rr rr;
|
55
|
+
const lcb_U8 *rdata;
|
56
|
+
size_t rdlen;
|
57
|
+
|
58
|
+
if (ns_parserr(&msg, ns_s_an, ii, &rr) != 0) {
|
59
|
+
continue;
|
60
|
+
}
|
61
|
+
|
62
|
+
if (ns_rr_type(rr) != ns_t_srv) {
|
63
|
+
continue;
|
64
|
+
}
|
65
|
+
|
66
|
+
/* Get the rdata and length fields */
|
67
|
+
rdata = ns_rr_rdata(rr);
|
68
|
+
rdlen = ns_rr_rdlen(rr);
|
69
|
+
|
70
|
+
if (rdlen < 6) {
|
71
|
+
continue;
|
72
|
+
}
|
73
|
+
|
74
|
+
#define do_get16(t) t = ns_get16(rdata); rdata += 2; rdlen -=2
|
75
|
+
do_get16(srv_prio);
|
76
|
+
do_get16(srv_weight);
|
77
|
+
do_get16(srv_port);
|
78
|
+
#undef do_get_16
|
79
|
+
|
80
|
+
(void)srv_prio; (void)srv_weight; /* Handle these in the future */
|
81
|
+
std::vector<char> dname(NS_MAXDNAME + 1);
|
82
|
+
ns_name_uncompress(
|
83
|
+
ns_msg_base(msg), ns_msg_end(msg),
|
84
|
+
rdata, &dname[0], NS_MAXDNAME);
|
85
|
+
hostlist->add(&dname[0], srv_port);
|
86
|
+
}
|
87
|
+
return LCB_SUCCESS;
|
88
|
+
}
|
89
|
+
#endif /* HAVE_RES_SEARCH */
|
90
|
+
|
91
|
+
#else
|
92
|
+
#include <windns.h>
|
93
|
+
#define CAN_SRV_LOOKUP
|
94
|
+
/* Implement via DnsQuery() */
|
95
|
+
LCB_INTERNAL_API
|
96
|
+
lcb_error_t
|
97
|
+
lcb_dnssrv_query(const char *addr, hostlist_t hs)
|
98
|
+
{
|
99
|
+
DNS_STATUS status;
|
100
|
+
PDNS_RECORDA root, cur;
|
101
|
+
|
102
|
+
status = DnsQuery_A(
|
103
|
+
addr, DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, (PDNS_RECORD*)&root, NULL);
|
104
|
+
if (status != 0) {
|
105
|
+
return LCB_UNKNOWN_HOST;
|
106
|
+
}
|
107
|
+
|
108
|
+
for (cur = root; cur; cur = cur->pNext) {
|
109
|
+
// Use the ASCII version of the DNS lookup structure
|
110
|
+
const DNS_SRV_DATAA *srv = &cur->Data.SRV;
|
111
|
+
hostlist_add_stringz(hs, srv->pNameTarget, srv->wPort);
|
112
|
+
}
|
113
|
+
DnsRecordListFree(root, DnsFreeRecordList);
|
114
|
+
return LCB_SUCCESS;
|
115
|
+
}
|
116
|
+
|
117
|
+
#endif /* !WIN32 */
|
118
|
+
|
119
|
+
|
120
|
+
#ifndef CAN_SRV_LOOKUP
|
121
|
+
LCB_INTERNAL_API lcb_error_t lcb_dnssrv_query(const char *, hostlist_t) {
|
122
|
+
return LCB_CLIENT_FEATURE_UNAVAILABLE;
|
123
|
+
}
|
124
|
+
#endif
|
125
|
+
|
126
|
+
#define SVCNAME_PLAIN "_couchbase._tcp."
|
127
|
+
#define SVCNAME_SSL "_couchbases._tcp."
|
128
|
+
|
129
|
+
LCB_INTERNAL_API
|
130
|
+
hostlist_st*
|
131
|
+
lcb_dnssrv_getbslist(const char *addr, int is_ssl, lcb_error_t *errp) {
|
132
|
+
std::string ss;
|
133
|
+
lcb::Hostlist *ret = new lcb::Hostlist();
|
134
|
+
ss.append(is_ssl ? SVCNAME_SSL : SVCNAME_PLAIN);
|
135
|
+
ss.append(addr);
|
136
|
+
|
137
|
+
*errp = lcb_dnssrv_query(ss.c_str(), ret);
|
138
|
+
if (*errp != LCB_SUCCESS) {
|
139
|
+
delete ret;
|
140
|
+
ret = NULL;
|
141
|
+
}
|
142
|
+
return static_cast<hostlist_st*>(ret);
|
143
|
+
}
|
@@ -34,7 +34,7 @@ lcb_dump(lcb_t instance, FILE *fp, lcb_U32 flags)
|
|
34
34
|
fprintf(fp, "Settings=%p\n", (void*)instance->settings);
|
35
35
|
|
36
36
|
if (instance->cur_configinfo) {
|
37
|
-
|
37
|
+
lcb::clconfig::ConfigInfo *cfg = instance->cur_configinfo;
|
38
38
|
fprintf(fp, "Current VBC=%p\n", (void*)cfg->vbc);
|
39
39
|
fprintf(fp, "Config RevID=%d\n", cfg->vbc->revid);
|
40
40
|
if (flags & LCB_DUMP_VBCONFIG) {
|
@@ -50,10 +50,10 @@ lcb_dump(lcb_t instance, FILE *fp, lcb_U32 flags)
|
|
50
50
|
} else {
|
51
51
|
fprintf(fp, "NO CLUSTER CONFIG\n");
|
52
52
|
}
|
53
|
-
fprintf(fp,"Retry queue has items: %s\n",
|
53
|
+
fprintf(fp,"Retry queue has items: %s\n", instance->retryq->empty() ? "No" : "Yes");
|
54
54
|
if (flags & LCB_DUMP_PKTINFO) {
|
55
55
|
fprintf(fp, "=== BEGIN RETRY QUEUE DUMP ===\n");
|
56
|
-
|
56
|
+
instance->retryq->dump(fp, NULL);
|
57
57
|
fprintf(fp, "=== END RETRY QUEUE DUMP ===\n");
|
58
58
|
} else {
|
59
59
|
fprintf(fp, "=== NOT DUMPING PACKET INFO. LCB_DUMP_PKTINFO not passed\n");
|
@@ -61,10 +61,7 @@ lcb_dump(lcb_t instance, FILE *fp, lcb_U32 flags)
|
|
61
61
|
|
62
62
|
fprintf(fp, "=== BEGIN PIPELINE DUMP ===\n");
|
63
63
|
for (ii = 0; ii < instance->cmdq.npipelines; ii++) {
|
64
|
-
|
65
|
-
mc_PIPELINE *pl = instance->cmdq.pipelines[ii];
|
66
|
-
|
67
|
-
server = (mc_SERVER *)pl;
|
64
|
+
lcb::Server *server = static_cast<lcb::Server*>(instance->cmdq.pipelines[ii]);
|
68
65
|
fprintf(fp, "** [%u] SERVER %s:%s\n", ii, server->curhost->host, server->curhost->port);
|
69
66
|
if (server->connctx) {
|
70
67
|
fprintf(fp, "** == BEGIN SOCKET INFO\n");
|
@@ -77,14 +74,14 @@ lcb_dump(lcb_t instance, FILE *fp, lcb_U32 flags)
|
|
77
74
|
}
|
78
75
|
if (flags & LCB_DUMP_BUFINFO) {
|
79
76
|
fprintf(fp, "** == DUMPING NETBUF INFO (For packet network data)\n");
|
80
|
-
netbuf_dump_status(&
|
77
|
+
netbuf_dump_status(&server->nbmgr, fp);
|
81
78
|
fprintf(fp, "** == DUMPING NETBUF INFO (For packet structures)\n");
|
82
|
-
netbuf_dump_status(&
|
79
|
+
netbuf_dump_status(&server->reqpool, fp);
|
83
80
|
} else {
|
84
81
|
fprintf(fp, "** == NOT DUMPING NETBUF INFO. LCB_DUMP_BUFINFO not passed\n");
|
85
82
|
}
|
86
83
|
if (flags & LCB_DUMP_PKTINFO) {
|
87
|
-
mcreq_dump_chain(
|
84
|
+
mcreq_dump_chain(server, fp, NULL);
|
88
85
|
} else {
|
89
86
|
fprintf(fp, "** == NOT DUMPING PACKETS. LCB_DUMP_PKTINFO not passed\n");
|
90
87
|
}
|
@@ -93,6 +90,6 @@ lcb_dump(lcb_t instance, FILE *fp, lcb_U32 flags)
|
|
93
90
|
fprintf(fp, "=== END PIPELINE DUMP ===\n");
|
94
91
|
|
95
92
|
fprintf(fp, "=== BEGIN CONFMON DUMP ===\n");
|
96
|
-
|
93
|
+
instance->confmon->dump(fp);
|
97
94
|
fprintf(fp, "=== END CONFMON DUMP ===\n");
|
98
95
|
}
|
@@ -0,0 +1,73 @@
|
|
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 "internal.h"
|
19
|
+
#include "packetutils.h"
|
20
|
+
#include <bucketconfig/clconfig.h>
|
21
|
+
|
22
|
+
static void
|
23
|
+
ext_callback_proxy(mc_PIPELINE *pl, mc_PACKET *req, lcb_error_t rc,
|
24
|
+
const void *resdata)
|
25
|
+
{
|
26
|
+
lcb::Server *server = static_cast<lcb::Server*>(pl);
|
27
|
+
mc_REQDATAEX *rd = req->u_rdata.exdata;
|
28
|
+
const lcb::MemcachedResponse *res =
|
29
|
+
reinterpret_cast<const lcb::MemcachedResponse*>(resdata);
|
30
|
+
|
31
|
+
lcb::clconfig::cccp_update(
|
32
|
+
rd->cookie, rc, res->body<const char*>(), res->bodylen(),
|
33
|
+
&server->get_host());
|
34
|
+
free(rd);
|
35
|
+
}
|
36
|
+
|
37
|
+
static mc_REQDATAPROCS procs = { ext_callback_proxy };
|
38
|
+
|
39
|
+
lcb_error_t
|
40
|
+
lcb_st::request_config(const void *cookie_, lcb::Server *server)
|
41
|
+
{
|
42
|
+
lcb_error_t err;
|
43
|
+
mc_PACKET *packet;
|
44
|
+
mc_REQDATAEX *rd;
|
45
|
+
|
46
|
+
packet = mcreq_allocate_packet(server);
|
47
|
+
if (!packet) {
|
48
|
+
return LCB_CLIENT_ENOMEM;
|
49
|
+
}
|
50
|
+
|
51
|
+
err = mcreq_reserve_header(server, packet, 24);
|
52
|
+
if (err != LCB_SUCCESS) {
|
53
|
+
mcreq_release_packet(server, packet);
|
54
|
+
return err;
|
55
|
+
}
|
56
|
+
|
57
|
+
rd = reinterpret_cast<mc_REQDATAEX*>(calloc(1, sizeof(*rd)));
|
58
|
+
rd->procs = &procs;
|
59
|
+
rd->cookie = cookie_;
|
60
|
+
rd->start = gethrtime();
|
61
|
+
packet->u_rdata.exdata = rd;
|
62
|
+
packet->flags |= MCREQ_F_REQEXT;
|
63
|
+
|
64
|
+
lcb::MemcachedRequest hdr(
|
65
|
+
PROTOCOL_BINARY_CMD_GET_CLUSTER_CONFIG, packet->opaque);
|
66
|
+
hdr.opaque(packet->opaque);
|
67
|
+
memcpy(SPAN_BUFFER(&packet->kh_span), hdr.data(), hdr.size());
|
68
|
+
|
69
|
+
mcreq_sched_enter(&cmdq);
|
70
|
+
mcreq_sched_add(server, packet);
|
71
|
+
mcreq_sched_leave(&cmdq, 1);
|
72
|
+
return LCB_SUCCESS;
|
73
|
+
}
|