libcouchbase 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -19,8 +19,6 @@ lcb_error_t
19
19
  lcb_observe_seqno3(lcb_t instance, const void *cookie, const lcb_CMDOBSEQNO *cmd)
20
20
  {
21
21
  mc_PACKET *pkt;
22
- mc_SERVER *server;
23
- mc_PIPELINE *pl;
24
22
  protocol_binary_request_header hdr;
25
23
  lcb_U64 uuid;
26
24
 
@@ -28,11 +26,10 @@ lcb_observe_seqno3(lcb_t instance, const void *cookie, const lcb_CMDOBSEQNO *cmd
28
26
  return LCB_EINVAL;
29
27
  }
30
28
 
31
- server = LCBT_GET_SERVER(instance, cmd->server_index);
32
- pl = &server->pipeline;
33
- pkt = mcreq_allocate_packet(pl);
34
- mcreq_reserve_header(pl, pkt, MCREQ_PKT_BASESIZE);
35
- mcreq_reserve_value2(pl, pkt, 8);
29
+ lcb::Server *server = instance->get_server(cmd->server_index);
30
+ pkt = mcreq_allocate_packet(server);
31
+ mcreq_reserve_header(server, pkt, MCREQ_PKT_BASESIZE);
32
+ mcreq_reserve_value2(server, pkt, 8);
36
33
 
37
34
  /* Set the static fields */
38
35
  MCREQ_PKT_RDATA(pkt)->cookie = cookie;
@@ -52,7 +49,7 @@ lcb_observe_seqno3(lcb_t instance, const void *cookie, const lcb_CMDOBSEQNO *cmd
52
49
 
53
50
  uuid = lcb_htonll(cmd->uuid);
54
51
  memcpy(SPAN_BUFFER(&pkt->u_value.single), &uuid, sizeof uuid);
55
- LCB_SCHED_ADD(instance, pl, pkt);
52
+ LCB_SCHED_ADD(instance, server, pkt);
56
53
  return LCB_SUCCESS;
57
54
  }
58
55
 
@@ -18,20 +18,26 @@
18
18
  #include "internal.h"
19
19
  #include "durability_internal.h"
20
20
  #include "trace.h"
21
+ #include "mctx-helper.h"
21
22
 
22
- typedef struct {
23
- mc_REQDATAEX base;
24
- lcb_MULTICMD_CTX mctx;
25
- lcb_t instance;
23
+ struct ObserveCtx : mc_REQDATAEX, lcb::MultiCmdContext {
24
+ void clear_requests() { requests.clear(); }
25
+ ObserveCtx(lcb_t instance_);
26
+
27
+ // Overrides
28
+ lcb_error_t MCTX_addcmd(const lcb_CMDBASE*);
29
+ lcb_error_t MCTX_done(const void *);
30
+ void MCTX_fail();
26
31
 
32
+ lcb_t instance;
27
33
  size_t remaining;
28
34
  unsigned oflags;
29
35
 
36
+ typedef std::vector<uint8_t> ServerBuf;
30
37
  /* requests array contains one buffer per server. nrequest essentially
31
38
  * says how many elements (and thus how many servers) */
32
- size_t nrequests;
33
- lcb_string requests[1];
34
- } OBSERVECTX;
39
+ std::vector<ServerBuf> requests;
40
+ };
35
41
 
36
42
  typedef enum {
37
43
  F_DURABILITY = 0x01,
@@ -39,12 +45,20 @@ typedef enum {
39
45
  F_SCHEDFAILED = 0x04
40
46
  } obs_flags;
41
47
 
48
+ // TODO: Move this to a common file
49
+ template <typename ContainerType, typename ValueType>
50
+ void add_to_buf(ContainerType& c, ValueType v) {
51
+ typename ContainerType::value_type *p =
52
+ reinterpret_cast<typename ContainerType::value_type*>(&v);
53
+ c.insert(c.end(), p, p + sizeof(ValueType));
54
+ }
55
+
42
56
  static void
43
57
  handle_observe_callback(mc_PIPELINE *pl,
44
58
  mc_PACKET *pkt, lcb_error_t err, const void *arg)
45
59
  {
46
- OBSERVECTX *oc = (void *)pkt->u_rdata.exdata;
47
- lcb_RESPOBSERVE *resp = (void *)arg;
60
+ ObserveCtx *oc = static_cast<ObserveCtx*>(pkt->u_rdata.exdata);
61
+ lcb_RESPOBSERVE *resp = reinterpret_cast<lcb_RESPOBSERVE*>(const_cast<void*>(arg));
48
62
  lcb_t instance = oc->instance;
49
63
 
50
64
  (void)pl;
@@ -67,7 +81,7 @@ handle_observe_callback(mc_PIPELINE *pl,
67
81
  memset(&cur, 0, sizeof(cur));
68
82
  cur.key = ptr;
69
83
  cur.nkey = nkey;
70
- cur.cookie = (void *)oc->base.cookie;
84
+ cur.cookie = (void *)oc->cookie;
71
85
  cur.rc = err;
72
86
  handle_observe_callback(NULL, pkt, err, &cur);
73
87
  ptr += nkey;
@@ -77,12 +91,11 @@ handle_observe_callback(mc_PIPELINE *pl,
77
91
  return;
78
92
  }
79
93
 
80
- resp->cookie = (void *)oc->base.cookie;
94
+ resp->cookie = (void *)oc->cookie;
81
95
  resp->rc = err;
82
96
  if (oc->oflags & F_DURABILITY) {
83
97
  resp->ttp = pl ? pl->index : -1;
84
- lcbdur_cas_update( instance,
85
- (lcb_DURSET *)MCREQ_PKT_COOKIE(pkt), err, resp);
98
+ lcbdur_cas_update(instance, (void*)MCREQ_PKT_COOKIE(pkt), err, resp);
86
99
 
87
100
  } else if ((oc->oflags & F_SCHEDFAILED) == 0) {
88
101
  lcb_RESPCALLBACK callback = lcb_find_callback(instance, LCB_CALLBACK_OBSERVE);
@@ -101,36 +114,23 @@ handle_observe_callback(mc_PIPELINE *pl,
101
114
  resp2.rflags = LCB_RESP_F_CLIENTGEN|LCB_RESP_F_FINAL;
102
115
  oc->oflags |= F_DESTROY;
103
116
  handle_observe_callback(NULL, pkt, err, &resp2);
104
- free(oc);
117
+ delete oc;
105
118
  }
106
119
  }
107
120
 
108
121
  static void
109
122
  handle_schedfail(mc_PACKET *pkt)
110
123
  {
111
- OBSERVECTX *oc = (void *)pkt->u_rdata.exdata;
124
+ ObserveCtx *oc = static_cast<ObserveCtx*>(pkt->u_rdata.exdata);
112
125
  oc->oflags |= F_SCHEDFAILED;
113
126
  handle_observe_callback(NULL, pkt, LCB_SCHEDFAIL_INTERNAL, NULL);
114
127
  }
115
128
 
116
- static void destroy_requests(OBSERVECTX *reqs)
117
- {
118
- size_t ii;
119
- for (ii = 0; ii < reqs->nrequests; ii++) {
120
- lcb_string_release(reqs->requests + ii);
121
- }
122
- }
123
-
124
- #define CTX_FROM_MULTI(mcmd) (void *) ((((char *) (mcmd))) - offsetof(OBSERVECTX, mctx))
125
-
126
- static lcb_error_t
127
- obs_ctxadd(lcb_MULTICMD_CTX *mctx, const lcb_CMDBASE *cmdbase)
129
+ lcb_error_t ObserveCtx::MCTX_addcmd(const lcb_CMDBASE *cmdbase)
128
130
  {
129
131
  int vbid, srvix_dummy;
130
132
  unsigned ii;
131
133
  const lcb_CMDOBSERVE *cmd = (const lcb_CMDOBSERVE *)cmdbase;
132
- OBSERVECTX *ctx = CTX_FROM_MULTI(mctx);
133
- lcb_t instance = ctx->instance;
134
134
  mc_CMDQUEUE *cq = &instance->cmdq;
135
135
  lcb_U16 servers_s[4];
136
136
  const lcb_U16 *servers;
@@ -178,23 +178,18 @@ obs_ctxadd(lcb_MULTICMD_CTX *mctx, const lcb_CMDBASE *cmdbase)
178
178
  }
179
179
 
180
180
  for (ii = 0; ii < nservers; ii++) {
181
- lcb_string *rr;
182
- lcb_U16 vb16, klen16;
183
181
  lcb_U16 ix = servers[ii];
184
182
 
185
- lcb_assert(ix < ctx->nrequests);
186
- rr = ctx->requests + ix;
187
- if (0 != lcb_string_reserve(rr, 4 + cmd->key.contig.nbytes)) {
188
- return LCB_CLIENT_ENOMEM;
189
- }
190
-
191
- vb16 = htons((lcb_U16)vbid);
192
- klen16 = htons((lcb_U16)cmd->key.contig.nbytes);
193
- lcb_string_append(rr, &vb16, sizeof vb16);
194
- lcb_string_append(rr, &klen16, sizeof klen16);
195
- lcb_string_append(rr, cmd->key.contig.bytes, cmd->key.contig.nbytes);
183
+ lcb_assert(ix < requests.size());
196
184
 
197
- ctx->remaining++;
185
+ ServerBuf& rr = requests[ix];
186
+ add_to_buf(rr, uint16_t(htons(vbid)));
187
+ add_to_buf(rr, uint16_t(htons(cmd->key.contig.nbytes)));
188
+ rr.insert(rr.end(),
189
+ reinterpret_cast<const uint8_t*>(cmd->key.contig.bytes),
190
+ reinterpret_cast<const uint8_t*>(cmd->key.contig.bytes) +
191
+ cmd->key.contig.nbytes);
192
+ remaining++;
198
193
  }
199
194
  return LCB_SUCCESS;
200
195
  }
@@ -204,21 +199,19 @@ static mc_REQDATAPROCS obs_procs = {
204
199
  handle_schedfail
205
200
  };
206
201
 
207
- static lcb_error_t
208
- obs_ctxdone(lcb_MULTICMD_CTX *mctx, const void *cookie)
202
+ lcb_error_t ObserveCtx::MCTX_done(const void *cookie_)
209
203
  {
210
204
  unsigned ii;
211
- OBSERVECTX *ctx = CTX_FROM_MULTI(mctx);
212
- mc_CMDQUEUE *cq = &ctx->instance->cmdq;
205
+ mc_CMDQUEUE *cq = &instance->cmdq;
213
206
 
214
- for (ii = 0; ii < ctx->nrequests; ii++) {
207
+ for (ii = 0; ii < requests.size(); ii++) {
215
208
  protocol_binary_request_header hdr;
216
209
  mc_PACKET *pkt;
217
210
  mc_PIPELINE *pipeline;
218
- lcb_string *rr = ctx->requests + ii;
211
+ ServerBuf& rr = requests[ii];
219
212
  pipeline = cq->pipelines[ii];
220
213
 
221
- if (!rr->nused) {
214
+ if (rr.empty()) {
222
215
  continue;
223
216
  }
224
217
 
@@ -226,7 +219,7 @@ obs_ctxdone(lcb_MULTICMD_CTX *mctx, const void *cookie)
226
219
  lcb_assert(pkt);
227
220
 
228
221
  mcreq_reserve_header(pipeline, pkt, MCREQ_PKT_BASESIZE);
229
- mcreq_reserve_value2(pipeline, pkt, rr->nused);
222
+ mcreq_reserve_value2(pipeline, pkt, rr.size());
230
223
 
231
224
  hdr.request.magic = PROTOCOL_BINARY_REQ;
232
225
  hdr.request.opcode = PROTOCOL_BINARY_CMD_OBSERVE;
@@ -236,70 +229,52 @@ obs_ctxdone(lcb_MULTICMD_CTX *mctx, const void *cookie)
236
229
  hdr.request.vbucket = 0;
237
230
  hdr.request.extlen = 0;
238
231
  hdr.request.opaque = pkt->opaque;
239
- hdr.request.bodylen = htonl((lcb_uint32_t)rr->nused);
232
+ hdr.request.bodylen = htonl((lcb_uint32_t)rr.size());
240
233
 
241
234
  memcpy(SPAN_BUFFER(&pkt->kh_span), hdr.bytes, sizeof(hdr.bytes));
242
- memcpy(SPAN_BUFFER(&pkt->u_value.single), rr->base, rr->nused);
235
+ memcpy(SPAN_BUFFER(&pkt->u_value.single), &rr[0], rr.size());
243
236
 
244
237
  pkt->flags |= MCREQ_F_REQEXT;
245
- pkt->u_rdata.exdata = (mc_REQDATAEX *)ctx;
238
+ pkt->u_rdata.exdata = this;
246
239
  mcreq_sched_add(pipeline, pkt);
247
240
  TRACE_OBSERVE_BEGIN(&hdr, SPAN_BUFFER(&pkt->u_value.single));
248
241
  }
249
242
 
250
- destroy_requests(ctx);
251
- ctx->base.start = gethrtime();
252
- ctx->base.cookie = cookie;
253
- ctx->base.procs = &obs_procs;
243
+ start = gethrtime();
244
+ cookie = cookie_;
254
245
 
255
- if (ctx->nrequests == 0 || ctx->remaining == 0) {
256
- free(ctx);
246
+ if (requests.size() == 0 || remaining == 0) {
247
+ delete this;
257
248
  return LCB_EINVAL;
258
249
  } else {
259
- MAYBE_SCHEDLEAVE(ctx->instance);
250
+ MAYBE_SCHEDLEAVE(instance);
260
251
  return LCB_SUCCESS;
261
252
  }
262
253
  }
263
254
 
264
- static void
265
- obs_ctxfail(lcb_MULTICMD_CTX *mctx)
266
- {
267
- OBSERVECTX *ctx = CTX_FROM_MULTI(mctx);
268
- destroy_requests(ctx);
269
- free(ctx);
255
+ void ObserveCtx::MCTX_fail() {
256
+ delete this;
270
257
  }
271
258
 
272
- LIBCOUCHBASE_API
273
- lcb_MULTICMD_CTX *
274
- lcb_observe3_ctxnew(lcb_t instance)
275
- {
276
- OBSERVECTX *ctx;
277
- size_t ii, n_extra = LCBT_NSERVERS(instance)-1;
278
- ctx = calloc(1, sizeof(*ctx) + sizeof(ctx->requests) * n_extra);
279
- ctx->instance = instance;
280
- ctx->nrequests = n_extra + 1;
281
- ctx->mctx.addcmd = obs_ctxadd;
282
- ctx->mctx.done = obs_ctxdone;
283
- ctx->mctx.fail = obs_ctxfail;
284
-
285
- /* note this block doesn't do anything not done with calloc, but makes for
286
- * easier reading/tracking */
287
- for (ii = 0; ii < ctx->nrequests; ii++) {
288
- lcb_string_init(ctx->requests + ii);
289
- }
259
+ ObserveCtx::ObserveCtx(lcb_t instance_)
260
+ : mc_REQDATAEX(NULL, obs_procs, 0),
261
+ instance(instance_),
262
+ remaining(0),
263
+ oflags(0) {
264
+
265
+ requests.resize(LCBT_NSERVERS(instance));
266
+ }
290
267
 
291
- return &ctx->mctx;
268
+ LIBCOUCHBASE_API
269
+ lcb_MULTICMD_CTX * lcb_observe3_ctxnew(lcb_t instance) {
270
+ return new ObserveCtx(instance);
292
271
  }
293
272
 
294
273
  lcb_MULTICMD_CTX *
295
- lcb_observe_ctx_dur_new(lcb_t instance)
296
- {
297
- lcb_MULTICMD_CTX *mctx = lcb_observe3_ctxnew(instance);
298
- if (mctx) {
299
- OBSERVECTX *ctx = CTX_FROM_MULTI(mctx);
300
- ctx->oflags |= F_DURABILITY;
301
- }
302
- return mctx;
274
+ lcb_observe_ctx_dur_new(lcb_t instance) {
275
+ ObserveCtx *ctx = new ObserveCtx(instance);
276
+ ctx->oflags |= F_DURABILITY;
277
+ return ctx;
303
278
  }
304
279
 
305
280
  LIBCOUCHBASE_API
@@ -17,32 +17,44 @@
17
17
 
18
18
  #include "internal.h"
19
19
 
20
- typedef struct {
21
- mc_REQDATAEX base;
20
+ struct BcastCookie : mc_REQDATAEX {
22
21
  lcb_CALLBACKTYPE type;
23
22
  int remaining;
24
- } bcast_cookie;
23
+
24
+ BcastCookie(lcb_CALLBACKTYPE type_,
25
+ const mc_REQDATAPROCS* procs_, const void *cookie_)
26
+ : mc_REQDATAEX(cookie_, *procs_, gethrtime()),
27
+ type(type_), remaining(0) {
28
+ }
29
+ };
25
30
 
26
31
  static void
27
32
  refcnt_dtor_common(mc_PACKET *pkt)
28
33
  {
29
- bcast_cookie *ck = (bcast_cookie *)pkt->u_rdata.exdata;
34
+ BcastCookie *ck = static_cast<BcastCookie *>(pkt->u_rdata.exdata);
30
35
  if (!--ck->remaining) {
31
- free(ck);
36
+ delete ck;
32
37
  }
33
38
  }
34
39
 
40
+ static const char *
41
+ make_hp_string(const lcb::Server& server, std::string& out) {
42
+ out.assign(server.get_host().host);
43
+ out.append(":");
44
+ out.append(server.get_host().port);
45
+ return out.c_str();
46
+ }
47
+
35
48
  static void
36
49
  stats_handler(mc_PIPELINE *pl, mc_PACKET *req, lcb_error_t err, const void *arg)
37
50
  {
38
- bcast_cookie *ck = (bcast_cookie *)req->u_rdata.exdata;
39
- mc_SERVER *server = (mc_SERVER *)pl;
40
- lcb_RESPSTATS *resp = (void *)arg;
41
- char epbuf[NI_MAXHOST + NI_MAXSERV + 4];
51
+ BcastCookie *ck = static_cast<BcastCookie *>(req->u_rdata.exdata);
52
+ lcb::Server *server = static_cast<lcb::Server*>(pl);
53
+ lcb_RESPSTATS *resp = reinterpret_cast<lcb_RESPSTATS*>(const_cast<void*>(arg));
54
+
42
55
  lcb_RESPCALLBACK callback;
43
- lcb_t instance = server->instance;
56
+ lcb_t instance = server->get_instance();
44
57
 
45
- sprintf(epbuf, "%s:%s", mcserver_get_host(server), mcserver_get_port(server));
46
58
  callback = lcb_find_callback(instance, LCB_CALLBACK_STATS);
47
59
 
48
60
  if (!arg) {
@@ -53,14 +65,15 @@ stats_handler(mc_PIPELINE *pl, mc_PACKET *req, lcb_error_t err, const void *arg)
53
65
  }
54
66
 
55
67
  s_resp.rc = err;
56
- s_resp.cookie = (void *)ck->base.cookie;
68
+ s_resp.cookie = const_cast<void *>(ck->cookie);
57
69
  s_resp.rflags = LCB_RESP_F_CLIENTGEN|LCB_RESP_F_FINAL;
58
70
  callback(instance, LCB_CALLBACK_STATS, (lcb_RESPBASE *)&s_resp);
59
- free(ck);
71
+ delete ck;
60
72
 
61
73
  } else {
62
- resp->server = epbuf;
63
- resp->cookie = (void *)ck->base.cookie;
74
+ std::string epbuf;
75
+ resp->server = make_hp_string(*server, epbuf);
76
+ resp->cookie = const_cast<void *>(ck->cookie);
64
77
  callback(instance, LCB_CALLBACK_STATS, (lcb_RESPBASE *)resp);
65
78
  return;
66
79
  }
@@ -79,7 +92,6 @@ lcb_stats3(lcb_t instance, const void *cookie, const lcb_CMDSTATS * cmd)
79
92
  int vbid = -1;
80
93
  char ksbuf[512] = { 0 };
81
94
  mc_CMDQUEUE *cq = &instance->cmdq;
82
- bcast_cookie *ckwrap = NULL;
83
95
  lcbvb_CONFIG *vbc = cq->config;
84
96
  const lcb_CONTIGBUF *kbuf_in = &cmd->key.contig;
85
97
  lcb_KEYBUF kbuf_out;
@@ -113,10 +125,8 @@ lcb_stats3(lcb_t instance, const void *cookie, const lcb_CMDSTATS * cmd)
113
125
  kbuf_out.contig = *kbuf_in;
114
126
  }
115
127
 
116
- ckwrap = calloc(1, sizeof(*ckwrap));
117
- ckwrap->base.cookie = cookie;
118
- ckwrap->base.start = gethrtime();
119
- ckwrap->base.procs = &stats_procs;
128
+ BcastCookie *ckwrap = new BcastCookie(LCB_CALLBACK_STATS,
129
+ &stats_procs, cookie);
120
130
 
121
131
  for (ii = 0; ii < cq->npipelines; ii++) {
122
132
  mc_PACKET *pkt;
@@ -143,7 +153,7 @@ lcb_stats3(lcb_t instance, const void *cookie, const lcb_CMDSTATS * cmd)
143
153
  mcreq_reserve_header(pl, pkt, MCREQ_PKT_BASESIZE);
144
154
  }
145
155
 
146
- pkt->u_rdata.exdata = &ckwrap->base;
156
+ pkt->u_rdata.exdata = ckwrap;
147
157
  pkt->flags |= MCREQ_F_REQEXT;
148
158
 
149
159
  ckwrap->remaining++;
@@ -153,7 +163,7 @@ lcb_stats3(lcb_t instance, const void *cookie, const lcb_CMDSTATS * cmd)
153
163
  }
154
164
 
155
165
  if (!ii) {
156
- free(ckwrap);
166
+ delete ckwrap;
157
167
  return LCB_NO_MATCHING_SERVER;
158
168
  }
159
169
 
@@ -165,9 +175,8 @@ static void
165
175
  handle_bcast(mc_PIPELINE *pipeline, mc_PACKET *req, lcb_error_t err,
166
176
  const void *arg)
167
177
  {
168
- mc_SERVER *server = (mc_SERVER *)pipeline;
169
- char epbuf[NI_MAXHOST + NI_MAXSERV + 4];
170
- bcast_cookie *ck = (bcast_cookie *)req->u_rdata.exdata;
178
+ lcb::Server *server = static_cast<lcb::Server*>(pipeline);
179
+ BcastCookie *ck = (BcastCookie *)req->u_rdata.exdata;
171
180
  lcb_RESPCALLBACK callback;
172
181
 
173
182
  union {
@@ -187,19 +196,20 @@ handle_bcast(mc_PIPELINE *pipeline, mc_PACKET *req, lcb_error_t err,
187
196
  memset(&u_empty, 0, sizeof(u_empty));
188
197
 
189
198
  if (arg) {
190
- u_resp.base = (void *)arg;
199
+ u_resp.base = (lcb_RESPSERVERBASE*)arg;
191
200
  } else {
192
201
  u_resp.base = &u_empty.base;
193
202
  u_resp.base->rflags = LCB_RESP_F_CLIENTGEN;
194
203
  }
195
204
 
196
205
  u_resp.base->rc = err;
197
- u_resp.base->cookie = (void *)ck->base.cookie;
198
- u_resp.base->server = epbuf;
199
- sprintf(epbuf, "%s:%s", mcserver_get_host(server), mcserver_get_port(server));
206
+ u_resp.base->cookie = const_cast<void*>(ck->cookie);
207
+
208
+ std::string epbuf;
209
+ u_resp.base->server = make_hp_string(*server, epbuf);
200
210
 
201
- callback = lcb_find_callback(server->instance, ck->type);
202
- callback(server->instance, ck->type, (lcb_RESPBASE *)u_resp.base);
211
+ callback = lcb_find_callback(server->get_instance(), ck->type);
212
+ callback(server->get_instance(), ck->type, (lcb_RESPBASE *)u_resp.base);
203
213
  if (--ck->remaining) {
204
214
  return;
205
215
  }
@@ -207,9 +217,9 @@ handle_bcast(mc_PIPELINE *pipeline, mc_PACKET *req, lcb_error_t err,
207
217
  u_empty.base.server = NULL;
208
218
  u_empty.base.rc = err;
209
219
  u_empty.base.rflags = LCB_RESP_F_CLIENTGEN|LCB_RESP_F_FINAL;
210
- u_empty.base.cookie = (void *)ck->base.cookie;
211
- callback(server->instance, ck->type, (lcb_RESPBASE *)&u_empty.base);
212
- free(ck);
220
+ u_empty.base.cookie = const_cast<void*>(ck->cookie);
221
+ callback(server->get_instance(), ck->type, (lcb_RESPBASE *)&u_empty.base);
222
+ delete ck;
213
223
  }
214
224
 
215
225
  static mc_REQDATAPROCS bcast_procs = {
@@ -222,17 +232,12 @@ pkt_bcast_simple(lcb_t instance, const void *cookie, lcb_CALLBACKTYPE type)
222
232
  {
223
233
  mc_CMDQUEUE *cq = &instance->cmdq;
224
234
  unsigned ii;
225
- bcast_cookie *ckwrap;
226
235
 
227
236
  if (!cq->config) {
228
237
  return LCB_CLIENT_ETMPFAIL;
229
238
  }
230
239
 
231
- ckwrap = calloc(1, sizeof(*ckwrap));
232
- ckwrap->base.cookie = cookie;
233
- ckwrap->base.start = gethrtime();
234
- ckwrap->base.procs = &bcast_procs;
235
- ckwrap->type = type;
240
+ BcastCookie *ckwrap = new BcastCookie(type, &bcast_procs, cookie);
236
241
 
237
242
  for (ii = 0; ii < cq->npipelines; ii++) {
238
243
  mc_PIPELINE *pl = cq->pipelines[ii];
@@ -244,7 +249,7 @@ pkt_bcast_simple(lcb_t instance, const void *cookie, lcb_CALLBACKTYPE type)
244
249
  return LCB_CLIENT_ENOMEM;
245
250
  }
246
251
 
247
- pkt->u_rdata.exdata = &ckwrap->base;
252
+ pkt->u_rdata.exdata = ckwrap;
248
253
  pkt->flags |= MCREQ_F_REQEXT;
249
254
 
250
255
  hdr.request.magic = PROTOCOL_BINARY_REQ;
@@ -265,7 +270,7 @@ pkt_bcast_simple(lcb_t instance, const void *cookie, lcb_CALLBACKTYPE type)
265
270
  }
266
271
 
267
272
  if (ii == 0) {
268
- free(ckwrap);
273
+ delete ckwrap;
269
274
  return LCB_NO_MATCHING_SERVER;
270
275
  }
271
276
  MAYBE_SCHEDLEAVE(instance);
@@ -274,18 +279,16 @@ pkt_bcast_simple(lcb_t instance, const void *cookie, lcb_CALLBACKTYPE type)
274
279
 
275
280
  LIBCOUCHBASE_API
276
281
  lcb_error_t
277
- lcb_server_versions3(lcb_t instance, const void *cookie, const lcb_CMDBASE * cmd)
282
+ lcb_server_versions3(lcb_t instance, const void *cookie, const lcb_CMDBASE *)
278
283
  {
279
- (void)cmd;
280
284
  return pkt_bcast_simple(instance, cookie, LCB_CALLBACK_VERSIONS);
281
285
  }
282
286
 
283
287
 
284
288
  LIBCOUCHBASE_API
285
289
  lcb_error_t
286
- lcb_flush3(lcb_t instance, const void *cookie, const lcb_CMDFLUSH *cmd)
290
+ lcb_flush3(lcb_t instance, const void *cookie, const lcb_CMDFLUSH *)
287
291
  {
288
- (void)cmd;
289
292
  return pkt_bcast_simple(instance, cookie, LCB_CALLBACK_FLUSH);
290
293
  }
291
294
 
@@ -296,30 +299,24 @@ lcb_server_verbosity3(lcb_t instance, const void *cookie,
296
299
  {
297
300
  mc_CMDQUEUE *cq = &instance->cmdq;
298
301
  unsigned ii;
299
- bcast_cookie *ckwrap;
300
302
 
301
303
  if (!cq->config) {
302
304
  return LCB_CLIENT_ETMPFAIL;
303
305
  }
304
306
 
305
- ckwrap = calloc(1, sizeof(*ckwrap));
306
- ckwrap->base.cookie = cookie;
307
- ckwrap->base.start = gethrtime();
308
- ckwrap->base.procs = &bcast_procs;
309
- ckwrap->type = LCB_CALLBACK_VERBOSITY;
307
+ BcastCookie *ckwrap = new BcastCookie(
308
+ LCB_CALLBACK_VERBOSITY, &bcast_procs, cookie);
310
309
 
311
310
  for (ii = 0; ii < cq->npipelines; ii++) {
312
311
  mc_PACKET *pkt;
313
- mc_PIPELINE *pl = cq->pipelines[ii];
314
- mc_SERVER *server = (mc_SERVER *)pl;
315
- char cmpbuf[NI_MAXHOST + NI_MAXSERV + 4];
312
+ lcb::Server *server = static_cast<lcb::Server*>(cq->pipelines[ii]);
316
313
  protocol_binary_request_verbosity vcmd;
317
314
  protocol_binary_request_header *hdr = &vcmd.message.header;
318
315
  uint32_t level;
319
316
 
320
- sprintf(cmpbuf, "%s:%s",
321
- mcserver_get_host(server), mcserver_get_port(server));
322
- if (cmd->server && strncmp(cmpbuf, cmd->server, strlen(cmd->server))) {
317
+ std::string cmpbuf;
318
+ make_hp_string(*server, cmpbuf);
319
+ if (cmd->server && cmpbuf != cmd->server) {
323
320
  continue;
324
321
  }
325
322
 
@@ -333,15 +330,15 @@ lcb_server_verbosity3(lcb_t instance, const void *cookie,
333
330
  level = 0;
334
331
  }
335
332
 
336
- pkt = mcreq_allocate_packet(pl);
333
+ pkt = mcreq_allocate_packet(server);
337
334
  if (!pkt) {
338
335
  return LCB_CLIENT_ENOMEM;
339
336
  }
340
337
 
341
- pkt->u_rdata.exdata = &ckwrap->base;
338
+ pkt->u_rdata.exdata = ckwrap;
342
339
  pkt->flags |= MCREQ_F_REQEXT;
343
340
 
344
- mcreq_reserve_header(pl, pkt, MCREQ_PKT_BASESIZE + 4);
341
+ mcreq_reserve_header(server, pkt, MCREQ_PKT_BASESIZE + 4);
345
342
  hdr->request.magic = PROTOCOL_BINARY_REQ;
346
343
  hdr->request.opcode = PROTOCOL_BINARY_CMD_VERBOSITY;
347
344
  hdr->request.datatype = PROTOCOL_BINARY_RAW_BYTES;
@@ -354,12 +351,12 @@ lcb_server_verbosity3(lcb_t instance, const void *cookie,
354
351
  vcmd.message.body.level = htonl((uint32_t)level);
355
352
 
356
353
  memcpy(SPAN_BUFFER(&pkt->kh_span), vcmd.bytes, sizeof(vcmd.bytes));
357
- mcreq_sched_add(pl, pkt);
354
+ mcreq_sched_add(server, pkt);
358
355
  ckwrap->remaining++;
359
356
  }
360
357
 
361
358
  if (!ckwrap->remaining) {
362
- free(ckwrap);
359
+ delete ckwrap;
363
360
  return LCB_NO_MATCHING_SERVER;
364
361
  }
365
362
  MAYBE_SCHEDLEAVE(instance);
@@ -371,10 +368,8 @@ lcb_error_t
371
368
  lcb_server_stats(lcb_t instance, const void *cookie, lcb_size_t num,
372
369
  const lcb_server_stats_cmd_t * const * items)
373
370
  {
374
- unsigned ii;
375
-
376
371
  lcb_sched_enter(instance);
377
- for (ii = 0; ii < num; ii++) {
372
+ for (size_t ii = 0; ii < num; ii++) {
378
373
  const lcb_server_stats_cmd_t *src = items[ii];
379
374
  lcb_CMDSTATS dst;
380
375
  lcb_error_t err;
@@ -397,10 +392,8 @@ lcb_error_t
397
392
  lcb_set_verbosity(lcb_t instance, const void *cookie, lcb_size_t num,
398
393
  const lcb_verbosity_cmd_t * const * items)
399
394
  {
400
- unsigned ii;
401
-
402
395
  lcb_sched_enter(instance);
403
- for (ii = 0; ii < num; ii++) {
396
+ for (size_t ii = 0; ii < num; ii++) {
404
397
  lcb_CMDVERBOSITY dst;
405
398
  lcb_error_t err;
406
399
  const lcb_verbosity_cmd_t *src = items[ii];
@@ -421,12 +414,10 @@ lcb_set_verbosity(lcb_t instance, const void *cookie, lcb_size_t num,
421
414
  LIBCOUCHBASE_API
422
415
  lcb_error_t
423
416
  lcb_flush(lcb_t instance, const void *cookie, lcb_size_t num,
424
- const lcb_flush_cmd_t * const * items)
417
+ const lcb_flush_cmd_t * const *)
425
418
  {
426
- unsigned ii;
427
-
428
419
  lcb_sched_enter(instance);
429
- for (ii = 0; ii < num; ii++) {
420
+ for (size_t ii = 0; ii < num; ii++) {
430
421
  lcb_error_t rc = lcb_flush3(instance, cookie, NULL);
431
422
  if (rc != LCB_SUCCESS) {
432
423
  lcb_sched_fail(instance);
@@ -434,20 +425,17 @@ lcb_flush(lcb_t instance, const void *cookie, lcb_size_t num,
434
425
  }
435
426
  }
436
427
  lcb_sched_leave(instance);
437
- (void)items;
438
428
  SYNCMODE_INTERCEPT(instance)
439
429
  }
440
430
 
441
431
  LIBCOUCHBASE_API
442
432
  lcb_error_t
443
433
  lcb_server_versions(lcb_t instance, const void *cookie, lcb_size_t num,
444
- const lcb_server_version_cmd_t * const * items)
434
+ const lcb_server_version_cmd_t * const *)
445
435
  {
446
- unsigned ii;
447
- (void)items;
448
436
  lcb_sched_enter(instance);
449
437
 
450
- for (ii = 0; ii < num; ii++) {
438
+ for (size_t ii = 0; ii < num; ii++) {
451
439
  lcb_error_t rc = lcb_server_versions3(instance, cookie, NULL);
452
440
  if (rc != LCB_SUCCESS) {
453
441
  lcb_sched_fail(instance);