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
@@ -30,19 +30,13 @@ using namespace lcb::http;
30
30
  #define LOGARGS(req, lvl) req->instance->settings, "http-io", LCB_LOG_##lvl, __FILE__, __LINE__
31
31
 
32
32
  void
33
- Request::assign_response_headers(const lcbht_RESPONSE *resp)
33
+ Request::assign_response_headers(const lcb::htparse::Response& resp)
34
34
  {
35
- response_headers.clear();
35
+ response_headers.assign(resp.headers.begin(), resp.headers.end());
36
36
  response_headers_clist.clear();
37
37
 
38
- sllist_node *curnode;
39
- SLLIST_ITERBASIC(&resp->headers, curnode) {
40
- lcbht_MIMEHDR *hdr = SLLIST_ITEM(curnode, lcbht_MIMEHDR, slnode);
41
- response_headers.push_back(Header(hdr->key, hdr->value));
42
- }
43
-
44
- std::vector<Header>::const_iterator ii = response_headers.begin();
45
- for (; ii != response_headers.end(); ++ii) {
38
+ std::vector<lcb::htparse::MimeHeader>::const_iterator ii;
39
+ for (ii = response_headers.begin(); ii != response_headers.end(); ++ii) {
46
40
  response_headers_clist.push_back(ii->key.c_str());
47
41
  response_headers_clist.push_back(ii->value.c_str());
48
42
  }
@@ -53,29 +47,30 @@ int
53
47
  Request::handle_parse_chunked(const char *buf, unsigned nbuf)
54
48
  {
55
49
  int parse_state, oldstate, diff;
56
- lcbht_RESPONSE *res = lcbht_get_response(parser);
50
+ using lcb::htparse::Parser;
51
+ lcb::htparse::Response& res = parser->get_cur_response();
57
52
 
58
53
  do {
59
54
  const char *rbody;
60
55
  unsigned nused = -1, nbody = -1;
61
- oldstate = res->state;
56
+ oldstate = res.state;
62
57
 
63
- parse_state = lcbht_parse_ex(parser, buf, nbuf, &nused, &nbody, &rbody);
58
+ parse_state = parser->parse_ex(buf, nbuf, &nused, &nbody, &rbody);
64
59
  diff = oldstate ^ parse_state;
65
60
 
66
61
  /* Got headers now for the first time */
67
- if (diff & LCBHT_S_HEADER) {
62
+ if (diff & Parser::S_HEADER) {
68
63
  assign_response_headers(res);
69
- if (res->status >= 300 && res->status <= 400) {
70
- const char *redir = lcbht_get_resphdr(res, "Location");
64
+ if (res.status >= 300 && res.status <= 400) {
65
+ const char *redir = res.get_header_value("Location");
71
66
  if (redir != NULL) {
72
67
  pending_redirect.assign(redir);
73
- return LCBHT_S_DONE;
68
+ return Parser::S_DONE;
74
69
  }
75
70
  }
76
71
  }
77
72
 
78
- if (parse_state & LCBHT_S_ERROR) {
73
+ if (parse_state & Parser::S_ERROR) {
79
74
  /* nothing to do here */
80
75
  return parse_state;
81
76
  }
@@ -91,22 +86,22 @@ Request::handle_parse_chunked(const char *buf, unsigned nbuf)
91
86
  callback(instance, LCB_CALLBACK_HTTP, (const lcb_RESPBASE *)&htresp);
92
87
 
93
88
  } else {
94
- lcb_string_append(&res->body, rbody, nbody);
89
+ res.body.append(rbody, nbody);
95
90
  }
96
91
  }
97
92
 
98
93
  buf += nused;
99
94
  nbuf -= nused;
100
- } while ((parse_state & LCBHT_S_DONE) == 0 && is_ongoing() && nbuf);
95
+ } while ((parse_state & Parser::S_DONE) == 0 && is_ongoing() && nbuf);
101
96
 
102
- if ( (parse_state & LCBHT_S_DONE) && is_ongoing()) {
97
+ if ( (parse_state & Parser::S_DONE) && is_ongoing()) {
103
98
  lcb_RESPHTTP resp = { 0 };
104
99
  if (chunked) {
105
100
  buf = NULL;
106
101
  nbuf = 0;
107
102
  } else {
108
- buf = res->body.base;
109
- nbuf = res->body.nused;
103
+ buf = res.body.c_str();
104
+ nbuf = res.body.size();
110
105
  }
111
106
 
112
107
  init_resp(&resp);
@@ -143,7 +138,8 @@ io_read(lcbio_CTX *ctx, unsigned nr)
143
138
  nbuf = lcbio_ctx_risize(&iter);
144
139
  parse_state = req->handle_parse_chunked(buf, nbuf);
145
140
 
146
- if ((parse_state & LCBHT_S_ERROR) || req->has_pending_redirect()) {
141
+ if ((parse_state & lcb::htparse::Parser::S_ERROR) ||
142
+ req->has_pending_redirect()) {
147
143
  rv = -1;
148
144
  break;
149
145
  } else if (!req->is_ongoing()) {
@@ -156,7 +152,7 @@ io_read(lcbio_CTX *ctx, unsigned nr)
156
152
  // parse error or redirect
157
153
  lcb_error_t err;
158
154
  if (req->has_pending_redirect()) {
159
- lcb_bootstrap_common(instance, LCB_BS_REFRESH_THROTTLE);
155
+ instance->bootstrap(lcb::BS_REFRESH_THROTTLE);
160
156
  // Transfer control to redirect function()
161
157
  lcb_log(LOGARGS(req, DEBUG), LOGFMT "Attempting redirect to %s", LOGID(req), req->pending_redirect.c_str());
162
158
  req->redirect();
@@ -297,7 +293,7 @@ Request::close_io()
297
293
  int can_ka;
298
294
 
299
295
  if (parser && is_data_request()) {
300
- can_ka = lcbht_can_keepalive(parser);
296
+ can_ka = parser->can_keepalive();
301
297
  } else {
302
298
  can_ka = 0;
303
299
  }
@@ -116,17 +116,57 @@ lcb_st::populate_nodes(const Connspec& spec)
116
116
  }
117
117
  }
118
118
 
119
+ lcb_error_t
120
+ lcb_st::process_dns_srv(Connspec& spec)
121
+ {
122
+ if (!spec.can_dnssrv()) {
123
+ return LCB_SUCCESS;
124
+ }
125
+ if (spec.hosts().empty()) {
126
+ lcb_log(LOGARGS(this, ERR), "Cannot use DNS SRV without a hostname");
127
+ return spec.is_explicit_dnssrv() ? LCB_EINVAL : LCB_SUCCESS;
128
+ }
129
+
130
+ const Spechost& host = spec.hosts().front();
131
+ lcb_error_t rc = LCB_ERROR;
132
+ Hostlist* hl = lcb_dnssrv_getbslist(host.hostname.c_str(), host.isSSL(), &rc);
133
+
134
+ if (hl == NULL) {
135
+ lcb_log(LOGARGS(this, INFO), "DNS SRV lookup failed: %s. Ignore this if not relying on DNS SRV records", lcb_strerror(this, rc));
136
+ if (spec.is_explicit_dnssrv()) {
137
+ return rc;
138
+ } else {
139
+ return LCB_SUCCESS;
140
+ }
141
+ }
142
+
143
+ spec.clear_hosts();
144
+ for (size_t ii = 0; ii < hl->size(); ++ii) {
145
+ const lcb_host_t& src = (*hl)[ii];
146
+ Spechost sh;
147
+ sh.hostname = src.host;
148
+ sh.port = std::atoi(src.port);
149
+ sh.type = spec.default_port();
150
+ spec.add_host(sh);
151
+ lcb_log(LOGARGS(this, INFO), "Found host %s:%d via DNS SRV", sh.hostname.c_str(), sh.port);
152
+ }
153
+ delete hl;
154
+
155
+ return LCB_SUCCESS;
156
+ }
157
+
119
158
  static lcb_error_t
120
159
  init_providers(lcb_t obj, const Connspec &spec)
121
160
  {
122
- clconfig_provider *http, *cccp, *mcraw;
123
- http = lcb_confmon_get_provider(obj->confmon, LCB_CLCONFIG_HTTP);
124
- cccp = lcb_confmon_get_provider(obj->confmon, LCB_CLCONFIG_CCCP);
125
- mcraw = lcb_confmon_get_provider(obj->confmon, LCB_CLCONFIG_MCRAW);
161
+ using namespace lcb::clconfig;
162
+ Provider *http, *cccp, *mcraw;
163
+ http = obj->confmon->get_provider(CLCONFIG_HTTP);
164
+ cccp = obj->confmon->get_provider(CLCONFIG_CCCP);
165
+ mcraw = obj->confmon->get_provider(CLCONFIG_MCRAW);
126
166
 
127
167
  if (spec.default_port() == LCB_CONFIG_MCCOMPAT_PORT) {
128
- lcb_confmon_set_provider_active(obj->confmon, LCB_CLCONFIG_MCRAW, 1);
129
- mcraw->configure_nodes(mcraw, obj->mc_nodes);
168
+ obj->confmon->set_active(CLCONFIG_MCRAW, true);
169
+ mcraw->configure_nodes(*obj->mc_nodes);
130
170
  return LCB_SUCCESS;
131
171
  }
132
172
 
@@ -155,7 +195,7 @@ init_providers(lcb_t obj, const Connspec &spec)
155
195
  if (spec.is_bs_file()) {
156
196
  /* If the 'file_only' provider is set, just assume something else
157
197
  * will provide us with the config, and forget about it. */
158
- clconfig_provider *prov = lcb_confmon_get_provider(obj->confmon, LCB_CLCONFIG_FILE);
198
+ Provider *prov = obj->confmon->get_provider(CLCONFIG_FILE);
159
199
  if (prov && prov->enabled) {
160
200
  return LCB_SUCCESS;
161
201
  }
@@ -164,17 +204,17 @@ init_providers(lcb_t obj, const Connspec &spec)
164
204
  }
165
205
 
166
206
  if (http_enabled) {
167
- lcb_clconfig_http_enable(http);
168
- lcb_clconfig_http_set_nodes(http, obj->ht_nodes);
207
+ http->enable();
208
+ http->configure_nodes(*obj->ht_nodes);
169
209
  } else {
170
- lcb_confmon_set_provider_active(obj->confmon, LCB_CLCONFIG_HTTP, 0);
210
+ obj->confmon->set_active(CLCONFIG_HTTP, false);
171
211
  }
172
212
 
173
213
  if (cccp_enabled && obj->type != LCB_TYPE_CLUSTER) {
174
- lcb_clconfig_cccp_enable(cccp, obj);
175
- lcb_clconfig_cccp_set_nodes(cccp, obj->mc_nodes);
214
+ cccp->enable(obj);
215
+ cccp->configure_nodes(*obj->mc_nodes);
176
216
  } else {
177
- lcb_confmon_set_provider_active(obj->confmon, LCB_CLCONFIG_CCCP, 0);
217
+ obj->confmon->set_active(CLCONFIG_CCCP, false);
178
218
  }
179
219
  return LCB_SUCCESS;
180
220
  }
@@ -379,10 +419,10 @@ lcb_error_t lcb_create(lcb_t *instance,
379
419
  obj->memd_sockpool->tmoidle = 10000000;
380
420
  obj->http_sockpool->maxidle = 1;
381
421
  obj->http_sockpool->tmoidle = 10000000;
382
- obj->confmon = lcb_confmon_create(settings, obj->iotable);
422
+ obj->confmon = new clconfig::Confmon(settings, obj->iotable);
383
423
  obj->ht_nodes = new Hostlist();
384
424
  obj->mc_nodes = new Hostlist();
385
- obj->retryq = lcb_retryq_new(&obj->cmdq, obj->iotable, obj->settings);
425
+ obj->retryq = new RetryQueue(&obj->cmdq, obj->iotable, obj->settings);
386
426
  obj->n1ql_cache = lcb_n1qlcache_create();
387
427
  lcb_initialize_packet_handlers(obj);
388
428
  lcb_aspend_init(&obj->pendops);
@@ -398,8 +438,15 @@ lcb_error_t lcb_create(lcb_t *instance,
398
438
  goto GT_DONE;
399
439
  }
400
440
 
441
+ if ((err = obj->process_dns_srv(spec)) != LCB_SUCCESS) {
442
+ goto GT_DONE;
443
+ }
444
+
401
445
  obj->populate_nodes(spec);
402
- err = init_providers(obj, spec);
446
+ if ((err = init_providers(obj, spec)) != LCB_SUCCESS) {
447
+ goto GT_DONE;
448
+ }
449
+
403
450
  if (err != LCB_SUCCESS) {
404
451
  lcb_destroy(obj);
405
452
  return err;
@@ -433,6 +480,10 @@ sync_dtor_cb(void *arg)
433
480
  }
434
481
  }
435
482
 
483
+ extern "C" {
484
+ void lcbdur_destroy(void*);
485
+ }
486
+
436
487
  LIBCOUCHBASE_API
437
488
  void lcb_destroy(lcb_t instance)
438
489
  {
@@ -442,10 +493,12 @@ void lcb_destroy(lcb_t instance)
442
493
  lcb_ASPEND_SETTYPE::iterator it;
443
494
  lcb_ASPEND_SETTYPE *pendq;
444
495
 
445
- DESTROY(lcb_clconfig_decref, cur_configinfo);
496
+ if (instance->cur_configinfo) {
497
+ instance->cur_configinfo->decref();
498
+ instance->cur_configinfo = NULL;
499
+ }
446
500
  instance->cmdq.config = NULL;
447
-
448
- lcb_bootstrap_destroy(instance);
501
+ DESTROY(delete, bs_state);
449
502
  DESTROY(delete, ht_nodes);
450
503
  DESTROY(delete, mc_nodes);
451
504
 
@@ -458,26 +511,25 @@ void lcb_destroy(lcb_t instance)
458
511
  if ((pendq = po->items[LCB_PENDTYPE_DURABILITY])) {
459
512
  std::vector<void*> dsets(pendq->begin(), pendq->end());
460
513
  for (size_t ii = 0; ii < dsets.size(); ++ii) {
461
- lcbdur_destroy(reinterpret_cast<lcb_DURSET_st*>(dsets[ii]));
514
+ lcbdur_destroy(dsets[ii]);
462
515
  }
463
516
  pendq->clear();
464
517
  }
465
518
 
466
519
  for (size_t ii = 0; ii < LCBT_NSERVERS(instance); ++ii) {
467
- mc_SERVER *server = LCBT_GET_SERVER(instance, ii);
468
- mcserver_close(server);
520
+ instance->get_server(ii)->close();
469
521
  }
470
522
 
471
523
  if ((pendq = po->items[LCB_PENDTYPE_HTTP])) {
472
524
  for (it = pendq->begin(); it != pendq->end(); ++it) {
473
- lcb_http_request_t htreq = reinterpret_cast<lcb_http_request_t>(*it);
474
- lcb_htreq_block_callback(htreq);
475
- lcb_htreq_finish(instance, htreq, LCB_ERROR);
525
+ http::Request *htreq = reinterpret_cast<http::Request*>(*it);
526
+ htreq->block_callback();
527
+ htreq->finish(LCB_ERROR);
476
528
  }
477
529
  }
478
530
 
479
- DESTROY(lcb_retryq_destroy, retryq);
480
- DESTROY(lcb_confmon_destroy, confmon);
531
+ DESTROY(delete, retryq);
532
+ DESTROY(delete, confmon);
481
533
  DESTROY(lcbio_mgr_destroy, memd_sockpool);
482
534
  DESTROY(lcbio_mgr_destroy, http_sockpool);
483
535
  DESTROY(lcb_vbguess_destroy, vbguess);
@@ -531,10 +583,23 @@ lcb_destroy_async(lcb_t instance, const void *arg)
531
583
  lcbio_async_signal(instance->dtor_timer);
532
584
  }
533
585
 
586
+ lcb::Server *
587
+ lcb_st::find_server(const lcb_host_t& host) const
588
+ {
589
+ unsigned ii;
590
+ for (ii = 0; ii < cmdq.npipelines; ii++) {
591
+ lcb::Server *server = static_cast<lcb::Server*>(cmdq.pipelines[ii]);
592
+ if (lcb_host_equals(&server->get_host(), &host)) {
593
+ return server;
594
+ }
595
+ }
596
+ return NULL;
597
+ }
598
+
534
599
  LIBCOUCHBASE_API
535
600
  lcb_error_t lcb_connect(lcb_t instance)
536
601
  {
537
- lcb_error_t err = lcb_bootstrap_common(instance, LCB_BS_REFRESH_INITIAL);
602
+ lcb_error_t err = instance->bootstrap(BS_REFRESH_INITIAL);
538
603
  if (err == LCB_SUCCESS) {
539
604
  SYNCMODE_INTERCEPT(instance);
540
605
  } else {
@@ -715,6 +780,15 @@ const char *lcb_strerror(lcb_t instance, lcb_error_t error)
715
780
  return "Unknown error";
716
781
  }
717
782
 
783
+ LCB_INTERNAL_API
784
+ const char *lcb_strerror_short(lcb_error_t error)
785
+ {
786
+ #define X(c, v, t, s) if (error == c) { return #c " (" #v ")"; }
787
+ LCB_XERR(X)
788
+ #undef X
789
+ return "<FIXME: Not an LCB error>";
790
+ }
791
+
718
792
  LIBCOUCHBASE_API
719
793
  int lcb_get_errtype(lcb_error_t err)
720
794
  {
@@ -56,12 +56,16 @@
56
56
  namespace lcb {
57
57
  class Connspec;
58
58
  struct Spechost;
59
+ class RetryQueue;
60
+ class Bootstrap;
61
+ namespace clconfig {
62
+ struct Confmon;
63
+ class ConfigInfo;
64
+ }
59
65
  }
60
66
  extern "C" {
61
67
  #endif
62
68
 
63
- struct lcb_string_st;
64
-
65
69
  struct lcb_callback_st {
66
70
  lcb_RESPCALLBACK v3callbacks[LCB_CALLBACK__MAX];
67
71
  lcb_get_callback get;
@@ -86,25 +90,31 @@ struct lcb_callback_st {
86
90
  lcb_pktflushed_callback pktflushed;
87
91
  };
88
92
 
89
- struct lcb_confmon_st;
90
- struct lcb_BOOTSTRAP;
91
93
  struct lcb_GUESSVB_st;
92
94
 
93
95
  #ifdef __cplusplus
94
96
  #include <string>
95
97
  typedef std::string* lcb_pSCRATCHBUF;
98
+ typedef lcb::RetryQueue lcb_RETRYQ;
99
+ typedef lcb::clconfig::Confmon* lcb_pCONFMON;
100
+ typedef lcb::clconfig::ConfigInfo *lcb_pCONFIGINFO;
101
+ typedef lcb::Bootstrap lcb_BOOTSTRAP;
96
102
  #else
97
103
  typedef struct lcb_SCRATCHBUF* lcb_pSCRATCHBUF;
104
+ typedef struct lcb_RETRYQ_st lcb_RETRYQ;
105
+ typedef struct lcb_CONFMON_st* lcb_pCONFMON;
106
+ typedef struct lcb_CONFIGINFO_st* lcb_pCONFIGINFO;
107
+ typedef struct lcb_BOOTSTRAP_st lcb_BOOTSTRAP;
98
108
  #endif
99
109
 
100
110
  struct lcb_st {
101
111
  mc_CMDQUEUE cmdq; /**< Base command queue object */
102
112
  const void *cookie; /**< User defined pointer */
103
- struct lcb_confmon_st *confmon; /**< Cluster config manager */
113
+ lcb_pCONFMON confmon; /**< Cluster config manager */
104
114
  hostlist_t mc_nodes; /**< List of current memcached endpoints */
105
115
  hostlist_t ht_nodes; /**< List of current management endpoints */
106
- struct clconfig_info_st *cur_configinfo; /**< Pointer to current config */
107
- struct lcb_BOOTSTRAP *bootstrap; /**< Bootstrapping state */
116
+ lcb_pCONFIGINFO cur_configinfo; /**< Pointer to current config */
117
+ lcb_BOOTSTRAP *bs_state; /**< Bootstrapping state */
108
118
  struct lcb_callback_st callbacks; /**< Callback table */
109
119
  lcb_HISTOGRAM *kv_timings; /**< Histogram object (for timing) */
110
120
  lcb_ASPEND pendops; /**< Pending asynchronous requests */
@@ -127,7 +137,34 @@ struct lcb_st {
127
137
  lcbio_pTABLE getIOT() { return iotable; }
128
138
  inline void add_bs_host(const char *host, int port, unsigned bstype);
129
139
  inline void add_bs_host(const lcb::Spechost& host, int defl_http, int defl_cccp);
140
+ inline lcb_error_t process_dns_srv(lcb::Connspec& spec);
130
141
  inline void populate_nodes(const lcb::Connspec&);
142
+ lcb::Server *get_server(size_t index) const {
143
+ return static_cast<lcb::Server*>(cmdq.pipelines[index]);
144
+ }
145
+ lcb::Server *find_server(const lcb_host_t& host) const;
146
+ lcb_error_t request_config(const void *cookie, lcb::Server* server);
147
+
148
+ /**
149
+ * @brief Request that the handle update its configuration.
150
+ *
151
+ * This function acts as a gateway to the more abstract confmon interface.
152
+ *
153
+ * @param instance The instance
154
+ * @param options A set of options specified as flags, indicating under what
155
+ * conditions a new configuration should be refetched.
156
+ *
157
+ * This should be a combination of one or more @ref lcb::BootstrapOptions
158
+ *
159
+ * Note, the definition for this function (and the flags)
160
+ * are found in bootstrap.cc
161
+ */
162
+ inline lcb_error_t bootstrap(unsigned options) {
163
+ if (!bs_state) {
164
+ bs_state = new lcb::Bootstrap(this);
165
+ }
166
+ return bs_state->bootstrap(options);
167
+ }
131
168
  #endif
132
169
  };
133
170
 
@@ -135,7 +172,7 @@ struct lcb_st {
135
172
  #define LCBT_NSERVERS(instance) (instance)->cmdq.npipelines
136
173
  #define LCBT_NDATASERVERS(instance) LCBVB_NDATASERVERS(LCBT_VBCONFIG(instance))
137
174
  #define LCBT_NREPLICAS(instance) LCBVB_NREPLICAS(LCBT_VBCONFIG(instance))
138
- #define LCBT_GET_SERVER(instance, ix) (mc_SERVER *)(instance)->cmdq.pipelines[ix]
175
+ #define LCBT_GET_SERVER(instance, ix) (instance)->cmdq.pipelines[ix]
139
176
  #define LCBT_SETTING(instance, name) (instance)->settings->name
140
177
 
141
178
  void lcb_initialize_packet_handlers(lcb_t instance);
@@ -143,18 +180,13 @@ void lcb_initialize_packet_handlers(lcb_t instance);
143
180
  LCB_INTERNAL_API
144
181
  void lcb_maybe_breakout(lcb_t instance);
145
182
 
146
- struct clconfig_info_st;
147
- void lcb_update_vbconfig(lcb_t instance, struct clconfig_info_st *config);
183
+ void lcb_update_vbconfig(lcb_t instance, lcb_pCONFIGINFO config);
148
184
  /**
149
185
  * Hashtable wrappers
150
186
  */
151
187
  genhash_t *lcb_hashtable_nc_new(lcb_size_t est);
152
188
  genhash_t *lcb_hashtable_szt_new(lcb_size_t est);
153
189
 
154
- struct lcb_DURSET_st;
155
- void lcbdur_destroy(struct lcb_DURSET_st *dset);
156
- void lcbdur_maybe_schedfail(struct lcb_DURSET_st *dset);
157
-
158
190
  lcb_error_t lcb_iops_cntl_handler(int mode, lcb_t instance, int cmd, void *arg);
159
191
 
160
192
  /**
@@ -184,22 +216,8 @@ lcb_error_t lcb_init_providers2(lcb_t obj,
184
216
  const struct lcb_create_st2 *e_options);
185
217
  lcb_error_t lcb_reinit3(lcb_t obj, const char *connstr);
186
218
 
187
-
188
- LCB_INTERNAL_API
189
- mc_SERVER *
190
- lcb_find_server_by_host(lcb_t instance, const lcb_host_t *host);
191
-
192
-
193
- LCB_INTERNAL_API
194
- mc_SERVER *
195
- lcb_find_server_by_index(lcb_t instance, int ix);
196
-
197
- LCB_INTERNAL_API
198
- lcb_error_t
199
- lcb_getconfig(lcb_t instance, const void *cookie, mc_SERVER *server);
200
-
201
219
  int
202
- lcb_should_retry(lcb_settings *settings, mc_PACKET *pkt, lcb_error_t err);
220
+ lcb_should_retry(const lcb_settings *settings, const mc_PACKET *pkt, lcb_error_t err);
203
221
 
204
222
  lcb_error_t
205
223
  lcb__synchandler_return(lcb_t instance);