libcouchbase 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +1 -1
  4. data/ext/libcouchbase/CMakeLists.txt +8 -6
  5. data/ext/libcouchbase/README.markdown +2 -2
  6. data/ext/libcouchbase/RELEASE_NOTES.markdown +0 -86
  7. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +0 -11
  8. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +0 -2
  9. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +1 -2
  10. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  11. data/ext/libcouchbase/cmake/config-cmake.h.in +0 -2
  12. data/ext/libcouchbase/cmake/defs.mk.in +2 -0
  13. data/ext/libcouchbase/cmake/source_files.cmake +5 -21
  14. data/ext/libcouchbase/include/libcouchbase/auth.h +0 -10
  15. data/ext/libcouchbase/include/libcouchbase/cntl.h +1 -27
  16. data/ext/libcouchbase/include/libcouchbase/error.h +1 -15
  17. data/ext/libcouchbase/include/libcouchbase/n1ql.h +1 -13
  18. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
  19. data/ext/libcouchbase/include/libcouchbase/subdoc.h +0 -9
  20. data/ext/libcouchbase/include/libcouchbase/views.h +1 -7
  21. data/ext/libcouchbase/include/libcouchbase/visibility.h +0 -1
  22. data/ext/libcouchbase/include/memcached/protocol_binary.h +1131 -29
  23. data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
  24. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  25. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +2 -3
  26. data/ext/libcouchbase/src/README.md +2 -0
  27. data/ext/libcouchbase/src/auth-priv.h +0 -1
  28. data/ext/libcouchbase/src/auth.cc +4 -10
  29. data/ext/libcouchbase/src/bootstrap.c +269 -0
  30. data/ext/libcouchbase/src/bootstrap.h +39 -50
  31. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +117 -84
  32. data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
  33. data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
  34. data/ext/libcouchbase/src/bucketconfig/bc_http.h +25 -50
  35. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
  36. data/ext/libcouchbase/src/bucketconfig/clconfig.h +386 -407
  37. data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
  38. data/ext/libcouchbase/src/cbft.cc +27 -22
  39. data/ext/libcouchbase/src/cntl.cc +19 -30
  40. data/ext/libcouchbase/src/connspec.cc +1 -48
  41. data/ext/libcouchbase/src/connspec.h +0 -27
  42. data/ext/libcouchbase/src/dump.cc +2 -2
  43. data/ext/libcouchbase/src/getconfig.cc +33 -7
  44. data/ext/libcouchbase/src/handler.cc +2 -0
  45. data/ext/libcouchbase/src/hostlist.cc +36 -0
  46. data/ext/libcouchbase/src/hostlist.h +62 -41
  47. data/ext/libcouchbase/src/http/http-priv.h +112 -125
  48. data/ext/libcouchbase/src/http/http.cc +30 -15
  49. data/ext/libcouchbase/src/http/http.h +34 -1
  50. data/ext/libcouchbase/src/http/http_io.cc +26 -22
  51. data/ext/libcouchbase/src/instance.cc +23 -94
  52. data/ext/libcouchbase/src/internal.h +26 -52
  53. data/ext/libcouchbase/src/jsparse/parser.cc +202 -146
  54. data/ext/libcouchbase/src/jsparse/parser.h +98 -91
  55. data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
  56. data/ext/libcouchbase/src/lcbht/lcbht.h +163 -174
  57. data/ext/libcouchbase/src/lcbio/connect.c +557 -0
  58. data/ext/libcouchbase/src/lcbio/connect.h +2 -9
  59. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  60. data/ext/libcouchbase/src/lcbio/iotable.h +16 -61
  61. data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
  62. data/ext/libcouchbase/src/lcbio/manager.c +2 -2
  63. data/ext/libcouchbase/src/mc/mcreq.h +2 -9
  64. data/ext/libcouchbase/src/mcserver/mcserver.cc +34 -143
  65. data/ext/libcouchbase/src/mcserver/mcserver.h +12 -7
  66. data/ext/libcouchbase/src/mcserver/negotiate.cc +38 -132
  67. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
  68. data/ext/libcouchbase/src/n1ql/n1ql.cc +32 -56
  69. data/ext/libcouchbase/src/newconfig.cc +6 -6
  70. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  71. data/ext/libcouchbase/src/operations/{cbflush.cc → cbflush.c} +15 -7
  72. data/ext/libcouchbase/src/operations/{counter.cc → counter.c} +0 -0
  73. data/ext/libcouchbase/src/operations/durability.cc +26 -6
  74. data/ext/libcouchbase/src/operations/durability_internal.h +3 -6
  75. data/ext/libcouchbase/src/operations/{get.cc → get.c} +26 -24
  76. data/ext/libcouchbase/src/operations/{observe.cc → observe.c} +93 -68
  77. data/ext/libcouchbase/src/operations/{pktfwd.cc → pktfwd.c} +0 -0
  78. data/ext/libcouchbase/src/operations/{remove.cc → remove.c} +0 -0
  79. data/ext/libcouchbase/src/operations/stats.cc +8 -3
  80. data/ext/libcouchbase/src/operations/{store.cc → store.c} +32 -27
  81. data/ext/libcouchbase/src/operations/subdoc.cc +18 -38
  82. data/ext/libcouchbase/src/operations/{touch.cc → touch.c} +0 -0
  83. data/ext/libcouchbase/src/packetutils.c +37 -0
  84. data/ext/libcouchbase/src/packetutils.h +2 -2
  85. data/ext/libcouchbase/src/probes.d +1 -1
  86. data/ext/libcouchbase/src/{retrychk.cc → retrychk.c} +3 -2
  87. data/ext/libcouchbase/src/retryq.cc +4 -4
  88. data/ext/libcouchbase/src/settings.c +0 -3
  89. data/ext/libcouchbase/src/settings.h +0 -5
  90. data/ext/libcouchbase/src/simplestring.c +211 -0
  91. data/ext/libcouchbase/src/simplestring.h +228 -0
  92. data/ext/libcouchbase/src/ssl/ssl_c.c +0 -1
  93. data/ext/libcouchbase/src/ssl/ssl_common.c +0 -2
  94. data/ext/libcouchbase/src/ssl/ssl_e.c +1 -0
  95. data/ext/libcouchbase/src/ssobuf.h +82 -0
  96. data/ext/libcouchbase/src/trace.h +4 -4
  97. data/ext/libcouchbase/src/vbucket/vbucket.c +1 -0
  98. data/ext/libcouchbase/src/views/{docreq.cc → docreq.c} +54 -48
  99. data/ext/libcouchbase/src/views/docreq.h +30 -24
  100. data/ext/libcouchbase/src/views/viewreq.c +358 -0
  101. data/ext/libcouchbase/src/views/viewreq.h +13 -43
  102. data/ext/libcouchbase/tests/basic/t_connstr.cc +50 -89
  103. data/ext/libcouchbase/tests/basic/t_host.cc +75 -67
  104. data/ext/libcouchbase/tests/basic/t_jsparse.cc +78 -27
  105. data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
  106. data/ext/libcouchbase/tests/htparse/t_basic.cc +78 -58
  107. data/ext/libcouchbase/tests/iotests/mock-environment.h +1 -2
  108. data/ext/libcouchbase/tests/iotests/t_confmon.cc +114 -96
  109. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  110. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
  111. data/lib/libcouchbase/ext/tasks.rb +6 -2
  112. data/lib/libcouchbase/query_view.rb +1 -1
  113. data/lib/libcouchbase/results_fiber.rb +6 -6
  114. data/lib/libcouchbase/version.rb +1 -1
  115. metadata +26 -26
  116. data/ext/libcouchbase/src/bootstrap.cc +0 -216
  117. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +0 -281
  118. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +0 -528
  119. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +0 -115
  120. data/ext/libcouchbase/src/bucketconfig/confmon.cc +0 -378
  121. data/ext/libcouchbase/src/dns-srv.cc +0 -142
  122. data/ext/libcouchbase/src/errmap.cc +0 -107
  123. data/ext/libcouchbase/src/errmap.h +0 -113
  124. data/ext/libcouchbase/src/lcbht/lcbht.cc +0 -177
  125. data/ext/libcouchbase/src/lcbio/connect.cc +0 -562
  126. data/ext/libcouchbase/src/lcbio/timer-cxx.h +0 -87
  127. data/ext/libcouchbase/src/mctx-helper.h +0 -51
  128. data/ext/libcouchbase/src/views/viewreq.cc +0 -318
  129. data/ext/libcouchbase/tests/iotests/t_errmap.cc +0 -97
@@ -221,7 +221,7 @@ iterwipe_cb(mc_CMDQUEUE *cq, mc_PIPELINE *oldpl, mc_PACKET *oldpkt, void *)
221
221
  return MCREQ_KEEP_PACKET;
222
222
  }
223
223
 
224
- lcb_log(LOGARGS((lcb_t)cq->cqdata, DEBUG), "Remapped packet %p (SEQ=%u) from " SERVER_FMT " to " SERVER_FMT,
224
+ lcb_log(LOGARGS((lcb_t)cq->cqdata, DEBUG), "Remapped packet %p (SEQ=%u) from "SERVER_FMT " to " SERVER_FMT,
225
225
  (void*)oldpkt, oldpkt->opaque, SERVER_ARGS((lcb::Server*)oldpl), SERVER_ARGS((lcb::Server*)newpl));
226
226
 
227
227
  /** Otherwise, copy over the packet and find the new vBucket to map to */
@@ -256,7 +256,7 @@ replace_config(lcb_t instance, lcbvb_CONFIG *oldconfig, lcbvb_CONFIG *newconfig)
256
256
  cur->set_new_index(newix);
257
257
  ppnew[newix] = cur;
258
258
  ppold[ii] = NULL;
259
- lcb_log(LOGARGS(instance, INFO), "Reusing server " SERVER_FMT ". OldIndex=%d. NewIndex=%d", SERVER_ARGS(cur), ii, newix);
259
+ lcb_log(LOGARGS(instance, INFO), "Reusing server "SERVER_FMT". OldIndex=%d. NewIndex=%d", SERVER_ARGS(cur), ii, newix);
260
260
  }
261
261
  }
262
262
 
@@ -305,14 +305,14 @@ replace_config(lcb_t instance, lcbvb_CONFIG *oldconfig, lcbvb_CONFIG *newconfig)
305
305
  free(ppold);
306
306
  }
307
307
 
308
- void lcb_update_vbconfig(lcb_t instance, lcb_pCONFIGINFO config)
308
+ void lcb_update_vbconfig(lcb_t instance, clconfig_info *config)
309
309
  {
310
310
  lcb_configuration_t change_status;
311
- lcb::clconfig::ConfigInfo *old_config = instance->cur_configinfo;
311
+ clconfig_info *old_config = instance->cur_configinfo;
312
312
  mc_CMDQUEUE *q = &instance->cmdq;
313
313
 
314
314
  instance->cur_configinfo = config;
315
- config->incref();
315
+ lcb_clconfig_incref(config);
316
316
  q->config = instance->cur_configinfo->vbc;
317
317
  q->cqdata = instance;
318
318
 
@@ -328,7 +328,7 @@ void lcb_update_vbconfig(lcb_t instance, lcb_pCONFIGINFO config)
328
328
  lcb_vbguess_newconfig(instance, config->vbc, instance->vbguess);
329
329
 
330
330
  replace_config(instance, old_config->vbc, config->vbc);
331
- old_config->decref();
331
+ lcb_clconfig_decref(old_config);
332
332
  change_status = LCB_CONFIGURATION_CHANGED;
333
333
  } else {
334
334
  size_t nservers = VB_NSERVERS(config->vbc);
@@ -70,7 +70,7 @@ lcb_get_node(lcb_t instance, lcb_GETNODETYPE type, unsigned ix)
70
70
 
71
71
  if (type & LCB_NODE_HTCONFIG) {
72
72
  if (type & LCB_NODE_CONNECTED) {
73
- const lcb_host_t *host = lcb::clconfig::http_get_host(instance->confmon);
73
+ const lcb_host_t *host = lcb_confmon_get_rest_host(instance->confmon);
74
74
  if (host) {
75
75
  return mk_scratch_host(instance, host);
76
76
  } else {
@@ -167,7 +167,7 @@ lcb_int32_t lcb_get_num_nodes(lcb_t instance)
167
167
  LIBCOUCHBASE_API
168
168
  const char *const *lcb_get_server_list(lcb_t instance)
169
169
  {
170
- return instance->ht_nodes->get_strlist();
170
+ return hostlist_strents(instance->ht_nodes);
171
171
  }
172
172
 
173
173
  LIBCOUCHBASE_API
@@ -15,10 +15,11 @@
15
15
  */
16
16
 
17
17
  #include "internal.h"
18
+ #include "simplestring.h"
18
19
  #include <http/http.h>
19
20
 
20
21
  static void
21
- flush_cb(lcb_t instance, int, const lcb_RESPBASE *rb)
22
+ flush_cb(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
22
23
  {
23
24
  const lcb_RESPHTTP *resp = (const lcb_RESPHTTP *)rb;
24
25
  lcb_RESPCBFLUSH fresp = { 0 };
@@ -34,30 +35,37 @@ flush_cb(lcb_t instance, int, const lcb_RESPBASE *rb)
34
35
  if (callback) {
35
36
  callback(instance, LCB_CALLBACK_CBFLUSH, (lcb_RESPBASE*)&fresp);
36
37
  }
38
+ (void)cbtype;
37
39
  }
38
40
 
39
41
  LIBCOUCHBASE_API
40
42
  lcb_error_t
41
- lcb_cbflush3(lcb_t instance, const void *cookie, const lcb_CMDBASE *)
43
+ lcb_cbflush3(lcb_t instance, const void *cookie, const lcb_CMDBASE *cmd)
42
44
  {
43
45
  lcb_http_request_t htr;
44
46
  lcb_CMDHTTP htcmd = { 0 };
47
+ lcb_string urlpath;
45
48
  lcb_error_t rc;
46
49
 
47
- std::string urlpath("/pools/default/buckets/");
48
- urlpath.append(LCBT_SETTING(instance, bucket));
49
- urlpath.append("/controller/doFlush");
50
+ (void)cmd;
51
+
52
+ lcb_string_init(&urlpath);
53
+ lcb_string_appendz(&urlpath, "/pools/default/buckets/");
54
+ lcb_string_appendz(&urlpath, LCBT_SETTING(instance, bucket));
55
+ lcb_string_appendz(&urlpath, "/controller/doFlush");
56
+
50
57
 
51
58
  htcmd.type = LCB_HTTP_TYPE_MANAGEMENT;
52
59
  htcmd.method = LCB_HTTP_METHOD_POST;
53
60
  htcmd.reqhandle = &htr;
54
- LCB_CMD_SET_KEY(&htcmd, urlpath.c_str(), urlpath.size());
61
+ LCB_CMD_SET_KEY(&htcmd, urlpath.base, urlpath.nused);
55
62
 
56
63
  rc = lcb_http3(instance, cookie, &htcmd);
64
+ lcb_string_release(&urlpath);
57
65
 
58
66
  if (rc != LCB_SUCCESS) {
59
67
  return rc;
60
68
  }
61
- htr->set_callback(flush_cb);
69
+ lcb_htreq_setcb(htr, flush_cb);
62
70
  return LCB_SUCCESS;
63
71
  }
@@ -323,7 +323,16 @@ lcb_durability_validate(lcb_t instance,
323
323
 
324
324
  }
325
325
 
326
- lcb_error_t Durset::MCTX_addcmd(const lcb_CMDBASE *cmd) {
326
+ static lcb_error_t
327
+ dset_ctx_add(lcb_MULTICMD_CTX *mctx, const lcb_CMDBASE *cmd)
328
+ {
329
+ return static_cast<Durset*>(mctx)->mctx_add(cmd);
330
+ }
331
+
332
+ lcb_error_t
333
+ Durset::mctx_add(const lcb_CMDBASE *cmd)
334
+ {
335
+
327
336
  if (LCB_KEYBUF_IS_EMPTY(&cmd->key)) {
328
337
  return LCB_EMPTY_KEY;
329
338
  }
@@ -348,8 +357,14 @@ lcb_error_t Durset::MCTX_addcmd(const lcb_CMDBASE *cmd) {
348
357
  return after_add(ent, reinterpret_cast<const lcb_CMDENDURE*>(cmd));
349
358
  }
350
359
 
360
+ static lcb_error_t
361
+ dset_ctx_schedule(lcb_MULTICMD_CTX *mctx, const void *cookie)
362
+ {
363
+ return static_cast<Durset*>(mctx)->mctx_schedule(cookie);
364
+ }
365
+
351
366
  lcb_error_t
352
- Durset::MCTX_done(const void *cookie_) {
367
+ Durset::mctx_schedule(const void *cookie_) {
353
368
  lcb_error_t err;
354
369
  const char *kptr = kvbufs.c_str();
355
370
 
@@ -380,8 +395,10 @@ Durset::MCTX_done(const void *cookie_) {
380
395
  return LCB_SUCCESS;
381
396
  }
382
397
 
383
- void Durset::MCTX_fail() {
384
- delete this;
398
+ static void
399
+ dset_ctx_fail(lcb_MULTICMD_CTX *mctx)
400
+ {
401
+ delete static_cast<Durset*>(mctx);
385
402
  }
386
403
 
387
404
  void lcbdurctx_set_durstore(lcb_MULTICMD_CTX *mctx, int enabled)
@@ -419,11 +436,14 @@ get_poll_meth(lcb_t instance, const lcb_durability_opts_t *options)
419
436
  }
420
437
 
421
438
  Durset::Durset(lcb_t instance_, const lcb_durability_opts_t *options)
422
- : MultiCmdContext(),
423
- nremaining(0), waiting(0), refcnt(0), next_state(STATE_OBSPOLL),
439
+ : nremaining(0), waiting(0), refcnt(0), next_state(STATE_OBSPOLL),
424
440
  lasterr(LCB_SUCCESS), is_durstore(false), cookie(NULL),
425
441
  ns_timeout(0), timer(NULL), instance(instance_)
426
442
  {
443
+ lcb_MULTICMD_CTX::addcmd = dset_ctx_add;
444
+ lcb_MULTICMD_CTX::done = dset_ctx_schedule;
445
+ lcb_MULTICMD_CTX::fail = dset_ctx_fail;
446
+
427
447
  const lcb_DURABILITYOPTSv0 *opts_in = &options->v.v0;
428
448
 
429
449
  std::memset(&opts, 0, sizeof opts);
@@ -19,8 +19,6 @@
19
19
  #define LCB_DURABILITY_INTERNAL_H
20
20
 
21
21
  #ifdef __cplusplus
22
- #include "mctx-helper.h"
23
-
24
22
  extern "C" {
25
23
  #endif
26
24
 
@@ -193,7 +191,7 @@ struct Item : public CallbackCookie {
193
191
  * A collection encompassing one or more entries which are to be checked for
194
192
  * persistence
195
193
  */
196
- struct Durset : public MultiCmdContext {
194
+ struct Durset : public lcb_MULTICMD_CTX {
197
195
  /**
198
196
  * Call this when the polling method (poll_impl()) has completed. This will
199
197
  * trigger a new poll after the interval.
@@ -250,9 +248,8 @@ struct Durset : public MultiCmdContext {
250
248
  Durset(lcb_t instance, const lcb_durability_opts_t* options);
251
249
 
252
250
  // Implementation for MULTICMD_CTX
253
- lcb_error_t MCTX_done(const void *cookie);
254
- lcb_error_t MCTX_addcmd(const lcb_CMDBASE *cmd);
255
- void MCTX_fail();
251
+ inline lcb_error_t mctx_schedule(const void *cookie);
252
+ inline lcb_error_t mctx_add(const lcb_CMDBASE *cmd);
256
253
 
257
254
  /**
258
255
  * This function calls poll_impl(). The implementation should then call
@@ -181,31 +181,28 @@ lcb_unlock(lcb_t instance, const void *cookie, lcb_size_t num,
181
181
  }
182
182
  }
183
183
 
184
- struct RGetCookie : mc_REQDATAEX {
185
- RGetCookie(const void *cookie, lcb_t instance, lcb_replica_t, int vb);
186
- void decref() {
187
- if (!--remaining) {
188
- delete this;
189
- }
190
- }
191
-
184
+ typedef struct {
185
+ mc_REQDATAEX base;
192
186
  unsigned r_cur;
193
187
  unsigned r_max;
194
188
  int remaining;
195
189
  int vbucket;
196
190
  lcb_replica_t strategy;
197
191
  lcb_t instance;
198
- };
192
+ } rget_cookie;
199
193
 
200
194
  static void rget_dtor(mc_PACKET *pkt) {
201
- static_cast<RGetCookie*>(pkt->u_rdata.exdata)->decref();
195
+ rget_cookie *rck = (rget_cookie *)pkt->u_rdata.exdata;
196
+ if (! --rck->remaining) {
197
+ free(rck);
198
+ }
202
199
  }
203
200
 
204
201
  static void
205
- rget_callback(mc_PIPELINE *, mc_PACKET *pkt, lcb_error_t err, const void *arg)
202
+ rget_callback(mc_PIPELINE *pl, mc_PACKET *pkt, lcb_error_t err, const void *arg)
206
203
  {
207
- RGetCookie *rck = static_cast<RGetCookie*>(pkt->u_rdata.exdata);
208
- lcb_RESPGET *resp = reinterpret_cast<lcb_RESPGET*>(const_cast<void*>(arg));
204
+ rget_cookie *rck = (rget_cookie *)pkt->u_rdata.exdata;
205
+ lcb_RESPGET *resp = (void *)arg;
209
206
  lcb_RESPCALLBACK callback;
210
207
  lcb_t instance = rck->instance;
211
208
 
@@ -250,7 +247,11 @@ rget_callback(mc_PIPELINE *, mc_PACKET *pkt, lcb_error_t err, const void *arg)
250
247
  rck->remaining = 2;
251
248
  }
252
249
  }
253
- rck->decref();
250
+
251
+ if (!--rck->remaining) {
252
+ free(rck);
253
+ }
254
+ (void)pl;
254
255
  }
255
256
 
256
257
  static mc_REQDATAPROCS rget_procs = {
@@ -258,13 +259,6 @@ static mc_REQDATAPROCS rget_procs = {
258
259
  rget_dtor
259
260
  };
260
261
 
261
- RGetCookie::RGetCookie(const void *cookie_, lcb_t instance_,
262
- lcb_replica_t strategy_, int vbucket_)
263
- : mc_REQDATAEX(cookie_, rget_procs, gethrtime()),
264
- r_cur(0), r_max(LCBT_NREPLICAS(instance_)), remaining(0),
265
- vbucket(vbucket_), strategy(strategy_), instance(instance_) {
266
- }
267
-
268
262
  LIBCOUCHBASE_API
269
263
  lcb_error_t
270
264
  lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
@@ -277,6 +271,7 @@ lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
277
271
  int vbid, ixtmp;
278
272
  protocol_binary_request_header req;
279
273
  unsigned r0, r1 = 0;
274
+ rget_cookie *rck = NULL;
280
275
 
281
276
  if (LCB_KEYBUF_IS_EMPTY(&cmd->key)) {
282
277
  return LCB_EMPTY_KEY;
@@ -328,7 +323,15 @@ lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
328
323
  }
329
324
 
330
325
  /* Initialize the cookie */
331
- RGetCookie *rck = new RGetCookie(cookie, instance, cmd->strategy, vbid);
326
+ rck = calloc(1, sizeof(*rck));
327
+ rck->base.cookie = cookie;
328
+ rck->base.start = gethrtime();
329
+ rck->base.procs = &rget_procs;
330
+ rck->strategy = cmd->strategy;
331
+ rck->r_cur = r0;
332
+ rck->r_max = LCBT_NREPLICAS(instance);
333
+ rck->instance = instance;
334
+ rck->vbucket = vbid;
332
335
 
333
336
  /* Initialize the packet */
334
337
  req.request.magic = PROTOCOL_BINARY_REQ;
@@ -340,7 +343,6 @@ lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
340
343
  req.request.keylen = htons((lcb_uint16_t)cmd->key.contig.nbytes);
341
344
  req.request.bodylen = htonl((lcb_uint32_t)cmd->key.contig.nbytes);
342
345
 
343
- rck->r_cur = r0;
344
346
  do {
345
347
  int curix;
346
348
  mc_PIPELINE *pl;
@@ -357,7 +359,7 @@ lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
357
359
  return LCB_CLIENT_ENOMEM;
358
360
  }
359
361
 
360
- pkt->u_rdata.exdata = rck;
362
+ pkt->u_rdata.exdata = &rck->base;
361
363
  pkt->flags |= MCREQ_F_REQEXT;
362
364
 
363
365
  mcreq_reserve_key(pl, pkt, sizeof(req.bytes), &cmd->key);
@@ -16,28 +16,23 @@
16
16
  */
17
17
 
18
18
  #include "internal.h"
19
+ #include "simplestring.h"
19
20
  #include "durability_internal.h"
20
21
  #include "trace.h"
21
- #include "mctx-helper.h"
22
-
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();
31
22
 
23
+ typedef struct {
24
+ mc_REQDATAEX base;
25
+ lcb_MULTICMD_CTX mctx;
32
26
  lcb_t instance;
27
+
33
28
  size_t remaining;
34
29
  unsigned oflags;
35
30
 
36
- typedef std::vector<uint8_t> ServerBuf;
37
31
  /* requests array contains one buffer per server. nrequest essentially
38
32
  * says how many elements (and thus how many servers) */
39
- std::vector<ServerBuf> requests;
40
- };
33
+ size_t nrequests;
34
+ lcb_string requests[1];
35
+ } OBSERVECTX;
41
36
 
42
37
  typedef enum {
43
38
  F_DURABILITY = 0x01,
@@ -45,20 +40,12 @@ typedef enum {
45
40
  F_SCHEDFAILED = 0x04
46
41
  } obs_flags;
47
42
 
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
-
56
43
  static void
57
44
  handle_observe_callback(mc_PIPELINE *pl,
58
45
  mc_PACKET *pkt, lcb_error_t err, const void *arg)
59
46
  {
60
- ObserveCtx *oc = static_cast<ObserveCtx*>(pkt->u_rdata.exdata);
61
- lcb_RESPOBSERVE *resp = reinterpret_cast<lcb_RESPOBSERVE*>(const_cast<void*>(arg));
47
+ OBSERVECTX *oc = (void *)pkt->u_rdata.exdata;
48
+ lcb_RESPOBSERVE *resp = (void *)arg;
62
49
  lcb_t instance = oc->instance;
63
50
 
64
51
  (void)pl;
@@ -81,7 +68,7 @@ handle_observe_callback(mc_PIPELINE *pl,
81
68
  memset(&cur, 0, sizeof(cur));
82
69
  cur.key = ptr;
83
70
  cur.nkey = nkey;
84
- cur.cookie = (void *)oc->cookie;
71
+ cur.cookie = (void *)oc->base.cookie;
85
72
  cur.rc = err;
86
73
  handle_observe_callback(NULL, pkt, err, &cur);
87
74
  ptr += nkey;
@@ -91,7 +78,7 @@ handle_observe_callback(mc_PIPELINE *pl,
91
78
  return;
92
79
  }
93
80
 
94
- resp->cookie = (void *)oc->cookie;
81
+ resp->cookie = (void *)oc->base.cookie;
95
82
  resp->rc = err;
96
83
  if (oc->oflags & F_DURABILITY) {
97
84
  resp->ttp = pl ? pl->index : -1;
@@ -114,23 +101,36 @@ handle_observe_callback(mc_PIPELINE *pl,
114
101
  resp2.rflags = LCB_RESP_F_CLIENTGEN|LCB_RESP_F_FINAL;
115
102
  oc->oflags |= F_DESTROY;
116
103
  handle_observe_callback(NULL, pkt, err, &resp2);
117
- delete oc;
104
+ free(oc);
118
105
  }
119
106
  }
120
107
 
121
108
  static void
122
109
  handle_schedfail(mc_PACKET *pkt)
123
110
  {
124
- ObserveCtx *oc = static_cast<ObserveCtx*>(pkt->u_rdata.exdata);
111
+ OBSERVECTX *oc = (void *)pkt->u_rdata.exdata;
125
112
  oc->oflags |= F_SCHEDFAILED;
126
113
  handle_observe_callback(NULL, pkt, LCB_SCHEDFAIL_INTERNAL, NULL);
127
114
  }
128
115
 
129
- lcb_error_t ObserveCtx::MCTX_addcmd(const lcb_CMDBASE *cmdbase)
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)
130
128
  {
131
129
  int vbid, srvix_dummy;
132
130
  unsigned ii;
133
131
  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,18 +178,23 @@ lcb_error_t ObserveCtx::MCTX_addcmd(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;
181
183
  lcb_U16 ix = servers[ii];
182
184
 
183
- lcb_assert(ix < requests.size());
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);
184
196
 
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++;
197
+ ctx->remaining++;
193
198
  }
194
199
  return LCB_SUCCESS;
195
200
  }
@@ -199,19 +204,21 @@ static mc_REQDATAPROCS obs_procs = {
199
204
  handle_schedfail
200
205
  };
201
206
 
202
- lcb_error_t ObserveCtx::MCTX_done(const void *cookie_)
207
+ static lcb_error_t
208
+ obs_ctxdone(lcb_MULTICMD_CTX *mctx, const void *cookie)
203
209
  {
204
210
  unsigned ii;
205
- mc_CMDQUEUE *cq = &instance->cmdq;
211
+ OBSERVECTX *ctx = CTX_FROM_MULTI(mctx);
212
+ mc_CMDQUEUE *cq = &ctx->instance->cmdq;
206
213
 
207
- for (ii = 0; ii < requests.size(); ii++) {
214
+ for (ii = 0; ii < ctx->nrequests; ii++) {
208
215
  protocol_binary_request_header hdr;
209
216
  mc_PACKET *pkt;
210
217
  mc_PIPELINE *pipeline;
211
- ServerBuf& rr = requests[ii];
218
+ lcb_string *rr = ctx->requests + ii;
212
219
  pipeline = cq->pipelines[ii];
213
220
 
214
- if (rr.empty()) {
221
+ if (!rr->nused) {
215
222
  continue;
216
223
  }
217
224
 
@@ -219,7 +226,7 @@ lcb_error_t ObserveCtx::MCTX_done(const void *cookie_)
219
226
  lcb_assert(pkt);
220
227
 
221
228
  mcreq_reserve_header(pipeline, pkt, MCREQ_PKT_BASESIZE);
222
- mcreq_reserve_value2(pipeline, pkt, rr.size());
229
+ mcreq_reserve_value2(pipeline, pkt, rr->nused);
223
230
 
224
231
  hdr.request.magic = PROTOCOL_BINARY_REQ;
225
232
  hdr.request.opcode = PROTOCOL_BINARY_CMD_OBSERVE;
@@ -229,52 +236,70 @@ lcb_error_t ObserveCtx::MCTX_done(const void *cookie_)
229
236
  hdr.request.vbucket = 0;
230
237
  hdr.request.extlen = 0;
231
238
  hdr.request.opaque = pkt->opaque;
232
- hdr.request.bodylen = htonl((lcb_uint32_t)rr.size());
239
+ hdr.request.bodylen = htonl((lcb_uint32_t)rr->nused);
233
240
 
234
241
  memcpy(SPAN_BUFFER(&pkt->kh_span), hdr.bytes, sizeof(hdr.bytes));
235
- memcpy(SPAN_BUFFER(&pkt->u_value.single), &rr[0], rr.size());
242
+ memcpy(SPAN_BUFFER(&pkt->u_value.single), rr->base, rr->nused);
236
243
 
237
244
  pkt->flags |= MCREQ_F_REQEXT;
238
- pkt->u_rdata.exdata = this;
245
+ pkt->u_rdata.exdata = (mc_REQDATAEX *)ctx;
239
246
  mcreq_sched_add(pipeline, pkt);
240
247
  TRACE_OBSERVE_BEGIN(&hdr, SPAN_BUFFER(&pkt->u_value.single));
241
248
  }
242
249
 
243
- start = gethrtime();
244
- cookie = cookie_;
250
+ destroy_requests(ctx);
251
+ ctx->base.start = gethrtime();
252
+ ctx->base.cookie = cookie;
253
+ ctx->base.procs = &obs_procs;
245
254
 
246
- if (requests.size() == 0 || remaining == 0) {
247
- delete this;
255
+ if (ctx->nrequests == 0 || ctx->remaining == 0) {
256
+ free(ctx);
248
257
  return LCB_EINVAL;
249
258
  } else {
250
- MAYBE_SCHEDLEAVE(instance);
259
+ MAYBE_SCHEDLEAVE(ctx->instance);
251
260
  return LCB_SUCCESS;
252
261
  }
253
262
  }
254
263
 
255
- void ObserveCtx::MCTX_fail() {
256
- delete this;
257
- }
258
-
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));
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);
266
270
  }
267
271
 
268
272
  LIBCOUCHBASE_API
269
- lcb_MULTICMD_CTX * lcb_observe3_ctxnew(lcb_t instance) {
270
- return new ObserveCtx(instance);
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
+ }
290
+
291
+ return &ctx->mctx;
271
292
  }
272
293
 
273
294
  lcb_MULTICMD_CTX *
274
- lcb_observe_ctx_dur_new(lcb_t instance) {
275
- ObserveCtx *ctx = new ObserveCtx(instance);
276
- ctx->oflags |= F_DURABILITY;
277
- return 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;
278
303
  }
279
304
 
280
305
  LIBCOUCHBASE_API