couchbase 3.2.0 → 3.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. package/README.md +24 -18
  2. package/binding.gyp +88 -85
  3. package/deps/lcb/CMakeLists.txt +1 -1
  4. package/deps/lcb/CONTRIBUTING.md +1 -1
  5. package/deps/lcb/README.markdown +2 -2
  6. package/deps/lcb/RELEASE_NOTES.markdown +99 -14
  7. package/deps/lcb/cmake/Modules/GetVersionInfo.cmake +1 -1
  8. package/deps/lcb/contrib/cbsasl/src/scram-sha/scram_utils.cc +22 -26
  9. package/deps/lcb/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +20 -7
  10. package/deps/lcb/doc/Doxyfile +1 -1
  11. package/deps/lcb/example/CMakeLists.txt +4 -4
  12. package/deps/lcb/example/libuvdirect/main.c +39 -12
  13. package/deps/lcb/example/minimal/durability.cc +149 -0
  14. package/deps/lcb/example/minimal/query.c +11 -9
  15. package/deps/lcb/gyp_config/common/libcouchbase/configuration.h +3 -3
  16. package/deps/lcb/gyp_config/linux/arm64/config.h +243 -0
  17. package/deps/lcb/include/libcouchbase/couchbase.h +80 -5
  18. package/deps/lcb/include/libcouchbase/error.h +2 -0
  19. package/deps/lcb/include/libcouchbase/ixmgmt.h +15 -10
  20. package/deps/lcb/include/libcouchbase/tracing.h +2 -2
  21. package/deps/lcb/include/memcached/protocol_binary.h +21 -0
  22. package/deps/lcb/libcouchbase.gyp +347 -349
  23. package/deps/lcb/packaging/deb/control +1 -1
  24. package/deps/lcb/src/analytics/analytics_handle.cc +13 -5
  25. package/deps/lcb/src/analytics/analytics_handle.hh +29 -0
  26. package/deps/lcb/src/bootstrap.cc +6 -3
  27. package/deps/lcb/src/capi/cmd_analytics.cc +12 -1
  28. package/deps/lcb/src/capi/cmd_analytics.hh +30 -0
  29. package/deps/lcb/src/capi/cmd_counter.hh +23 -0
  30. package/deps/lcb/src/capi/cmd_exists.hh +24 -1
  31. package/deps/lcb/src/capi/cmd_get.hh +22 -0
  32. package/deps/lcb/src/capi/cmd_get_replica.hh +23 -0
  33. package/deps/lcb/src/capi/cmd_http.hh +7 -0
  34. package/deps/lcb/src/capi/cmd_query.cc +11 -1
  35. package/deps/lcb/src/capi/cmd_query.hh +31 -0
  36. package/deps/lcb/src/capi/cmd_remove.hh +23 -0
  37. package/deps/lcb/src/capi/cmd_search.cc +6 -0
  38. package/deps/lcb/src/capi/cmd_search.hh +23 -0
  39. package/deps/lcb/src/capi/cmd_store.hh +33 -21
  40. package/deps/lcb/src/capi/cmd_subdoc.hh +35 -0
  41. package/deps/lcb/src/capi/cmd_touch.hh +23 -0
  42. package/deps/lcb/src/capi/cmd_unlock.hh +23 -0
  43. package/deps/lcb/src/capi/cmd_view.hh +6 -0
  44. package/deps/lcb/src/capi/collection_qualifier.hh +2 -2
  45. package/deps/lcb/src/cntl.cc +45 -11
  46. package/deps/lcb/src/crypto.cc +2 -2
  47. package/deps/lcb/src/dns-srv.cc +5 -3
  48. package/deps/lcb/src/errmap.cc +5 -9
  49. package/deps/lcb/src/errmap.h +7 -3
  50. package/deps/lcb/src/handler.cc +24 -18
  51. package/deps/lcb/src/hostlist.h +2 -2
  52. package/deps/lcb/src/http/http-priv.h +2 -2
  53. package/deps/lcb/src/http/http.cc +5 -2
  54. package/deps/lcb/src/instance.cc +20 -11
  55. package/deps/lcb/src/internal.h +9 -0
  56. package/deps/lcb/src/lcbio/connect.cc +14 -2
  57. package/deps/lcb/src/lcbio/connect.h +2 -2
  58. package/deps/lcb/src/lcbio/ctx.cc +4 -2
  59. package/deps/lcb/src/lcbio/ioutils.cc +9 -10
  60. package/deps/lcb/src/lcbio/manager.cc +1 -1
  61. package/deps/lcb/src/mcserver/mcserver.cc +9 -6
  62. package/deps/lcb/src/mcserver/negotiate.cc +39 -17
  63. package/deps/lcb/src/n1ql/ixmgmt.cc +1 -2
  64. package/deps/lcb/src/n1ql/query_handle.cc +41 -19
  65. package/deps/lcb/src/n1ql/query_handle.hh +28 -1
  66. package/deps/lcb/src/operations/counter.cc +18 -5
  67. package/deps/lcb/src/operations/exists.cc +25 -4
  68. package/deps/lcb/src/operations/get.cc +39 -19
  69. package/deps/lcb/src/operations/get_replica.cc +28 -8
  70. package/deps/lcb/src/operations/observe.cc +1 -1
  71. package/deps/lcb/src/operations/ping.cc +8 -8
  72. package/deps/lcb/src/operations/pktfwd.cc +2 -1
  73. package/deps/lcb/src/operations/remove.cc +39 -22
  74. package/deps/lcb/src/operations/store.cc +18 -5
  75. package/deps/lcb/src/operations/subdoc.cc +18 -6
  76. package/deps/lcb/src/operations/touch.cc +34 -16
  77. package/deps/lcb/src/operations/unlock.cc +24 -5
  78. package/deps/lcb/src/packetutils.h +3 -2
  79. package/deps/lcb/src/retryq.cc +24 -5
  80. package/deps/lcb/src/search/search.cc +1 -0
  81. package/deps/lcb/src/search/search_handle.cc +30 -8
  82. package/deps/lcb/src/search/search_handle.hh +29 -0
  83. package/deps/lcb/src/settings.cc +1 -1
  84. package/deps/lcb/src/ssl/ssl_common.c +6 -7
  85. package/deps/lcb/src/tracing/span.cc +47 -14
  86. package/deps/lcb/src/tracing/tracer.cc +11 -2
  87. package/deps/lcb/src/tracing/tracing-internal.h +105 -93
  88. package/deps/lcb/src/utilities.cc +43 -0
  89. package/deps/lcb/src/utilities.h +53 -0
  90. package/deps/lcb/src/vbucket/vbucket.c +34 -33
  91. package/deps/lcb/src/views/view_handle.cc +13 -5
  92. package/deps/lcb/src/views/view_handle.hh +29 -0
  93. package/deps/lcb/tests/CMakeLists.txt +21 -0
  94. package/deps/lcb/tests/basic/t_ctlcodes.cc +24 -3
  95. package/deps/lcb/tests/basic/t_jsparse.cc +8 -0
  96. package/deps/lcb/tests/basic/t_n1qlstrings.cc +73 -0
  97. package/deps/lcb/tests/iotests/mock-environment.cc +30 -1
  98. package/deps/lcb/tests/iotests/mock-environment.h +49 -0
  99. package/deps/lcb/tests/iotests/mock-unit-test.cc +104 -6
  100. package/deps/lcb/tests/iotests/mock-unit-test.h +34 -0
  101. package/deps/lcb/tests/iotests/t_collections.cc +1 -1
  102. package/deps/lcb/tests/iotests/t_confmon.cc +4 -2
  103. package/deps/lcb/tests/iotests/t_get.cc +109 -7
  104. package/deps/lcb/tests/iotests/t_http.cc +9 -4
  105. package/deps/lcb/tests/iotests/t_lock.cc +18 -0
  106. package/deps/lcb/tests/iotests/t_mutate.cc +157 -63
  107. package/deps/lcb/tests/iotests/t_n1ql.cc +330 -33
  108. package/deps/lcb/tests/iotests/t_views.cc +1 -0
  109. package/deps/lcb/tests/iotests/testutil.cc +168 -0
  110. package/deps/lcb/tests/iotests/testutil.h +116 -0
  111. package/deps/lcb/tests/mocksupport/procutil.c +32 -28
  112. package/deps/lcb/tests/mocksupport/server.c +0 -1
  113. package/deps/lcb/tests/mocksupport/timeout.c +2 -2
  114. package/deps/lcb/tools/cbc.cc +7 -0
  115. package/dist/analyticsindexmanager.js +512 -524
  116. package/dist/binding.d.ts +3 -0
  117. package/dist/bindingutilities.js +4 -0
  118. package/dist/bucket.js +1 -1
  119. package/dist/bucketmanager.d.ts +31 -1
  120. package/dist/bucketmanager.js +194 -186
  121. package/dist/cluster.d.ts +7 -0
  122. package/dist/cluster.js +48 -38
  123. package/dist/collection.js +11 -17
  124. package/dist/collectionmanager.js +181 -197
  125. package/dist/connection.d.ts +3 -1
  126. package/dist/connection.js +27 -16
  127. package/dist/couchbase.d.ts +1 -0
  128. package/dist/couchbase.js +3 -13
  129. package/dist/datastructures.js +239 -310
  130. package/dist/diagnosticsexecutor.js +70 -85
  131. package/dist/errors.d.ts +70 -0
  132. package/dist/errors.js +96 -2
  133. package/dist/eventingfunctionmanager.d.ts +804 -0
  134. package/dist/eventingfunctionmanager.js +993 -0
  135. package/dist/httpexecutor.d.ts +2 -1
  136. package/dist/httpexecutor.js +30 -37
  137. package/dist/queryindexmanager.js +240 -266
  138. package/dist/scope.js +10 -4
  139. package/dist/sdspecs.d.ts +1 -1
  140. package/dist/searchexecutor.js +3 -0
  141. package/dist/searchindexmanager.js +240 -271
  142. package/dist/searchquery.d.ts +17 -0
  143. package/dist/searchquery.js +22 -1
  144. package/dist/searchtypes.d.ts +7 -2
  145. package/dist/searchtypes.js +2 -2
  146. package/dist/usermanager.js +251 -264
  147. package/dist/utilities.d.ts +2 -0
  148. package/dist/utilities.js +7 -2
  149. package/dist/viewexecutor.js +1 -1
  150. package/dist/viewindexmanager.js +131 -150
  151. package/package.json +1 -1
  152. package/src/addondata.cpp +58 -0
  153. package/src/addondata.h +40 -0
  154. package/src/binding.cpp +3 -1
  155. package/src/cas.h +2 -2
  156. package/src/connection.cpp +25 -178
  157. package/src/connection.h +8 -65
  158. package/src/connection_ops.cpp +57 -34
  159. package/src/constants.cpp +3 -0
  160. package/src/instance.cpp +235 -0
  161. package/src/instance.h +102 -0
  162. package/src/{connection_callbacks.cpp → instance_callbacks.cpp} +34 -34
  163. package/src/logger.cpp +11 -1
  164. package/src/logger.h +3 -0
  165. package/src/metrics.cpp +10 -0
  166. package/src/metrics.h +3 -0
  167. package/src/mutationtoken.h +2 -2
  168. package/src/opbuilder.h +13 -15
  169. package/src/respreader.cpp +1 -0
  170. package/src/respreader.h +6 -4
  171. package/src/tracespan.h +11 -11
  172. package/src/tracing.cpp +11 -0
  173. package/src/tracing.h +3 -0
  174. package/src/valueparser.h +5 -0
  175. package/deps/lcb/example/observe/durability.c +0 -110
package/src/opbuilder.h CHANGED
@@ -3,6 +3,7 @@
3
3
  #define OPBUILDER_H
4
4
 
5
5
  #include "connection.h"
6
+ #include "instance.h"
6
7
  #include "lcbx.h"
7
8
  #include "tracespan.h"
8
9
  #include "tracing.h"
@@ -17,15 +18,14 @@ using namespace v8;
17
18
  class OpCookie : public Nan::AsyncResource
18
19
  {
19
20
  public:
20
- OpCookie(Connection *impl, const Nan::Callback &callback,
21
+ OpCookie(Instance *inst, const Nan::Callback &callback,
21
22
  const Nan::Persistent<Object> &transcoder, TraceSpan span,
22
23
  WrappedRequestSpan *parentSpan)
23
24
  : Nan::AsyncResource("couchbase::op")
24
- , _impl(impl)
25
+ , _inst(inst)
25
26
  , _parentSpan(parentSpan)
26
27
  , _traceSpan(span)
27
28
  {
28
- _implRef.Reset(_impl->persistent());
29
29
  _callback.Reset(callback.GetFunction());
30
30
  _transcoder.Reset(transcoder);
31
31
  }
@@ -35,7 +35,6 @@ public:
35
35
  // We do not end the trace here, as the callback is responsible for
36
36
  // ending the trace at the appropriate point in time.
37
37
 
38
- _implRef.Reset();
39
38
  _callback.Reset();
40
39
  _transcoder.Reset();
41
40
 
@@ -47,7 +46,7 @@ public:
47
46
 
48
47
  TraceSpan startDecodeTrace()
49
48
  {
50
- return TraceSpan::beginDecodeTrace(_impl, _traceSpan);
49
+ return TraceSpan::beginDecodeTrace(_inst, _traceSpan);
51
50
  }
52
51
 
53
52
  void endTrace()
@@ -65,10 +64,9 @@ public:
65
64
  return _callback.Call(argc, argv, asyncContext()).ToLocalChecked();
66
65
  }
67
66
 
68
- Connection *_impl;
67
+ Instance *_inst;
69
68
  Nan::Callback _callback;
70
69
  Nan::Persistent<Object> _transcoder;
71
- Nan::Persistent<Object> _implRef;
72
70
  WrappedRequestSpan *_parentSpan;
73
71
  TraceSpan _traceSpan;
74
72
  };
@@ -314,9 +312,9 @@ class OpBuilder : public CmdBuilder<CmdType>
314
312
  {
315
313
  public:
316
314
  template <typename... Ts>
317
- OpBuilder(Connection *impl, Ts... args)
315
+ OpBuilder(Instance *inst, Ts... args)
318
316
  : CmdBuilder<CmdType>(_valueParser, args...)
319
- , _impl(impl)
317
+ , _inst(inst)
320
318
  , _parentSpan(nullptr)
321
319
  {
322
320
  }
@@ -334,7 +332,7 @@ public:
334
332
 
335
333
  TraceSpan startEncodeTrace()
336
334
  {
337
- return TraceSpan::beginEncodeTrace(_impl, _traceSpan);
335
+ return TraceSpan::beginEncodeTrace(_inst, _traceSpan);
338
336
  }
339
337
 
340
338
  bool parseParentSpan(Local<Value> parentSpan)
@@ -346,7 +344,7 @@ public:
346
344
 
347
345
  if (!parentSpan.IsEmpty() && parentSpan->IsObject()) {
348
346
  _parentSpan =
349
- new WrappedRequestSpan(_impl, parentSpan.As<Object>());
347
+ new WrappedRequestSpan(_inst, parentSpan.As<Object>());
350
348
  }
351
349
 
352
350
  return true;
@@ -451,7 +449,7 @@ public:
451
449
  }
452
450
 
453
451
  TraceSpan span =
454
- TraceSpan::beginOpTrace(_impl, service, opName, parentSpan);
452
+ TraceSpan::beginOpTrace(_inst, service, opName, parentSpan);
455
453
  _traceSpan = span;
456
454
  }
457
455
 
@@ -472,13 +470,13 @@ public:
472
470
  }
473
471
 
474
472
  OpCookie *cookie =
475
- new OpCookie(this->_impl, this->_callback, this->_transcoder,
473
+ new OpCookie(this->_inst, this->_callback, this->_transcoder,
476
474
  this->_traceSpan, this->_parentSpan);
477
475
 
478
476
  // ownership of the parent span wrapper transfers to the opcookie
479
477
  _parentSpan = nullptr;
480
478
 
481
- lcb_STATUS err = ExecFn(this->_impl->lcbHandle(), cookie, this->cmd());
479
+ lcb_STATUS err = ExecFn(this->_inst->lcbHandle(), cookie, this->cmd());
482
480
  if (err != LCB_SUCCESS) {
483
481
  // If the result was unsuccessful, we need to destroy the cookie
484
482
  // since we won't see it in any callbacks.
@@ -489,7 +487,7 @@ public:
489
487
  }
490
488
 
491
489
  protected:
492
- Connection *_impl;
490
+ Instance *_inst;
493
491
  ValueParser _valueParser;
494
492
  std::vector<Nan::Utf8String *> _strings;
495
493
  Nan::Callback _callback;
@@ -0,0 +1 @@
1
+ #include "respreader.h"
package/src/respreader.h CHANGED
@@ -2,7 +2,9 @@
2
2
  #ifndef RESPREADER_H
3
3
  #define RESPREADER_H
4
4
 
5
- #include "connection.h"
5
+ #include "error.h"
6
+ #include "instance.h"
7
+ #include "mutationtoken.h"
6
8
  #include "opbuilder.h"
7
9
 
8
10
  namespace couchnode
@@ -102,9 +104,9 @@ public:
102
104
  }
103
105
  }
104
106
 
105
- Connection *connection() const
107
+ Instance *instance() const
106
108
  {
107
- return Connection::fromInstance(_instance);
109
+ return Instance::fromLcbInst(_instance);
108
110
  }
109
111
 
110
112
  OpCookie *cookie() const
@@ -384,7 +386,7 @@ public:
384
386
  return Nan::Null();
385
387
  }
386
388
 
387
- return MutationToken::create(value, connection()->bucketName());
389
+ return MutationToken::create(value, instance()->bucketName());
388
390
  }
389
391
 
390
392
  template <lcb_STATUS (*ValFn)(const RespType *, const char **, size_t *)>
package/src/tracespan.h CHANGED
@@ -45,10 +45,10 @@ public:
45
45
  return TraceSpan(span);
46
46
  }
47
47
 
48
- static TraceSpan beginOpTrace(Connection *impl, lcbtrace_SERVICE service,
48
+ static TraceSpan beginOpTrace(Instance *inst, lcbtrace_SERVICE service,
49
49
  const char *opName, TraceSpan parent)
50
50
  {
51
- lcbtrace_TRACER *tracer = lcb_get_tracer(impl->lcbHandle());
51
+ lcbtrace_TRACER *tracer = lcb_get_tracer(inst->lcbHandle());
52
52
  if (!tracer) {
53
53
  return TraceSpan();
54
54
  }
@@ -64,19 +64,19 @@ public:
64
64
  lcbtrace_SPAN *span = lcbtrace_span_start(tracer, opName, 0, refPtr);
65
65
  lcbtrace_span_set_is_outer(span, 1);
66
66
  lcbtrace_span_add_tag_str(span, LCBTRACE_TAG_COMPONENT,
67
- impl->clientString());
67
+ inst->clientString());
68
68
  lcbtrace_span_set_service(span, service);
69
69
 
70
70
  return TraceSpan(span);
71
71
  }
72
72
 
73
- static TraceSpan beginEncodeTrace(Connection *impl, TraceSpan opSpan)
73
+ static TraceSpan beginEncodeTrace(Instance *inst, TraceSpan opSpan)
74
74
  {
75
75
  if (!opSpan) {
76
76
  return TraceSpan();
77
77
  }
78
78
 
79
- lcbtrace_TRACER *tracer = lcb_get_tracer(impl->lcbHandle());
79
+ lcbtrace_TRACER *tracer = lcb_get_tracer(inst->lcbHandle());
80
80
  if (!tracer) {
81
81
  return TraceSpan();
82
82
  }
@@ -87,18 +87,18 @@ public:
87
87
  lcbtrace_SPAN *span = lcbtrace_span_start(
88
88
  tracer, LCBTRACE_OP_REQUEST_ENCODING, LCBTRACE_NOW, &ref);
89
89
  lcbtrace_span_add_tag_str(span, LCBTRACE_TAG_COMPONENT,
90
- impl->clientString());
90
+ inst->clientString());
91
91
 
92
92
  return TraceSpan(span);
93
93
  }
94
94
 
95
- static TraceSpan beginDecodeTrace(Connection *impl, TraceSpan opSpan)
95
+ static TraceSpan beginDecodeTrace(Instance *inst, TraceSpan opSpan)
96
96
  {
97
97
  if (!opSpan) {
98
98
  return NULL;
99
99
  }
100
100
 
101
- lcbtrace_TRACER *tracer = lcb_get_tracer(impl->lcbHandle());
101
+ lcbtrace_TRACER *tracer = lcb_get_tracer(inst->lcbHandle());
102
102
  if (!tracer) {
103
103
  return NULL;
104
104
  }
@@ -109,7 +109,7 @@ public:
109
109
  lcbtrace_SPAN *span = lcbtrace_span_start(
110
110
  tracer, LCBTRACE_OP_RESPONSE_DECODING, LCBTRACE_NOW, &ref);
111
111
  lcbtrace_span_add_tag_str(span, LCBTRACE_TAG_COMPONENT,
112
- impl->clientString());
112
+ inst->clientString());
113
113
 
114
114
  return TraceSpan(span);
115
115
  }
@@ -126,11 +126,11 @@ private:
126
126
  class WrappedRequestSpan
127
127
  {
128
128
  public:
129
- WrappedRequestSpan(Connection *conn, Local<Object> val)
129
+ WrappedRequestSpan(Instance *inst, Local<Object> val)
130
130
  : _reqSpan(val, true)
131
131
  , _span(nullptr)
132
132
  {
133
- lcbtrace_TRACER *tracer = lcb_get_tracer(conn->lcbHandle());
133
+ lcbtrace_TRACER *tracer = lcb_get_tracer(inst->lcbHandle());
134
134
  if (!tracer) {
135
135
  _span = nullptr;
136
136
  return;
package/src/tracing.cpp CHANGED
@@ -59,9 +59,11 @@ static void lcbSpanAddTagUint64(lcbxtrace_SPAN *procs, const char *name,
59
59
  }
60
60
 
61
61
  RequestTracer::RequestTracer(Local<Object> impl)
62
+ : _enabled(true)
62
63
  {
63
64
  _lcbTracer = lcbtrace_new(nullptr, LCBTRACE_F_EXTERNAL);
64
65
  _lcbTracer->version = 1;
66
+ _lcbTracer->destructor = nullptr;
65
67
  _lcbTracer->v.v1.start_span = lcbTracerStartSpan;
66
68
  _lcbTracer->v.v1.end_span = lcbSpanEnd;
67
69
  _lcbTracer->v.v1.destroy_span = lcbSpanDestroy;
@@ -89,9 +91,18 @@ lcbtrace_TRACER *RequestTracer::lcbProcs() const
89
91
  return _lcbTracer;
90
92
  }
91
93
 
94
+ void RequestTracer::disconnect()
95
+ {
96
+ _enabled = false;
97
+ }
98
+
92
99
  lcbxtrace_SPAN *RequestTracer::requestSpan(const char *name,
93
100
  const lcbxtrace_SPAN *parent)
94
101
  {
102
+ if (!_enabled) {
103
+ return nullptr;
104
+ }
105
+
95
106
  Nan::HandleScope scope;
96
107
  Local<Object> impl = Nan::New(_impl);
97
108
  Local<Function> requestSpanImpl = Nan::New(_requestSpanImpl);
package/src/tracing.h CHANGED
@@ -23,7 +23,10 @@ public:
23
23
 
24
24
  lcbxtrace_SPAN *requestSpan(const char *name, const lcbxtrace_SPAN *parent);
25
25
 
26
+ void disconnect();
27
+
26
28
  protected:
29
+ bool _enabled;
27
30
  lcbtrace_TRACER *_lcbTracer;
28
31
  Nan::Persistent<Object> _impl;
29
32
  Nan::Persistent<Function> _requestSpanImpl;
package/src/valueparser.h CHANGED
@@ -88,6 +88,11 @@ public:
88
88
  return true;
89
89
  }
90
90
 
91
+ static bool isSet(Local<Value> val)
92
+ {
93
+ return !val.IsEmpty() && !val->IsUndefined() && !val->IsNull();
94
+ }
95
+
91
96
  template <typename T>
92
97
  static bool parseUint(T *out, Local<Value> value)
93
98
  {
@@ -1,110 +0,0 @@
1
- /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright 2017-2020 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
- /*
19
- * BUILD:
20
- * cc -o durability durability.c -lcouchbase
21
- *
22
- * RUN:
23
- * ./durability [ CONNSTRING [ PASSWORD [ USERNAME ] ] ]
24
- *
25
- * # use default durability check method
26
- * ./durability couchbase://localhost
27
- *
28
- * # force durability check method based on sequence numbers
29
- * ./durability couchbase://localhost?fetch_mutation_tokens=true&dur_mutation_tokens=true
30
- */
31
- #include <stdlib.h>
32
- #include <stdio.h>
33
- #include <string.h>
34
- #include <assert.h>
35
- #include <libcouchbase/couchbase.h>
36
-
37
- #define fail(msg) \
38
- fprintf(stderr, "%s\n", msg); \
39
- exit(EXIT_FAILURE)
40
-
41
- #define fail2(msg, err) \
42
- fprintf(stderr, "%s\n", msg); \
43
- fprintf(stderr, "Error was 0x%x (%s)\n", err, lcb_strerror_short(err)); \
44
- exit(EXIT_FAILURE)
45
-
46
- static void store_callback(lcb_INSTANCE *instance, int cbtype, const lcb_RESPSTORE *resp)
47
- {
48
- lcb_STATUS rc = lcb_respstore_status(resp);
49
- int store_ok, exists_master, persisted_master;
50
- uint16_t num_responses, num_replicated, num_persisted;
51
-
52
- lcb_respstore_observe_stored(resp, &store_ok);
53
- lcb_respstore_observe_master_exists(resp, &exists_master);
54
- lcb_respstore_observe_master_persisted(resp, &persisted_master);
55
- lcb_respstore_observe_num_responses(resp, &num_responses);
56
- lcb_respstore_observe_num_replicated(resp, &num_replicated);
57
- lcb_respstore_observe_num_persisted(resp, &num_persisted);
58
-
59
- fprintf(stderr, "Got status of operation: 0x%02x, %s\n", rc, lcb_strerror_short(rc));
60
- fprintf(stderr, "Stored: %s\n", store_ok ? "true" : "false");
61
- fprintf(stderr, "Number of roundtrips: %d\n", (int)num_responses);
62
- fprintf(stderr, "In memory on master: %s\n", exists_master ? "true" : "false");
63
- fprintf(stderr, "Persisted on master: %s\n", persisted_master ? "true" : "false");
64
- fprintf(stderr, "Nodes have value replicated: %d\n", (int)num_replicated);
65
- fprintf(stderr, "Nodes have value persisted (including master): %d\n", (int)num_persisted);
66
- }
67
-
68
- int main(int argc, char *argv[])
69
- {
70
- lcb_INSTANCE *instance;
71
- lcb_STATUS err;
72
- lcb_CMDSTORE *cmd;
73
- lcb_CREATEOPTS *options = NULL;
74
- const char *key = "foo";
75
- const char *value = "{\"val\":42}";
76
-
77
- lcb_createopts_create(&options, LCB_TYPE_BUCKET);
78
- if (argc > 1) {
79
- lcb_createopts_connstr(options, argv[1], strlen(argv[1]));
80
- }
81
- if (argc > 3) {
82
- lcb_createopts_credentials(options, argv[3], strlen(argv[3]), argv[2], strlen(argv[2]));
83
- }
84
-
85
- if ((err = lcb_create(&instance, options)) != LCB_SUCCESS) {
86
- fail2("cannot create connection instance", err);
87
- }
88
- lcb_createopts_destroy(options);
89
- if ((err = lcb_connect(instance)) != LCB_SUCCESS) {
90
- fail2("Couldn't schedule connection", err);
91
- }
92
- lcb_wait(instance, LCB_WAIT_DEFAULT);
93
- if ((err = lcb_get_bootstrap_status(instance)) != LCB_SUCCESS) {
94
- fail2("Couldn't get initial cluster configuration", err);
95
- }
96
- lcb_install_callback(instance, LCB_CALLBACK_STORE, (lcb_RESPCALLBACK)store_callback);
97
-
98
- lcb_cmdstore_create(&cmd, LCB_STORE_UPSERT);
99
- lcb_cmdstore_key(cmd, key, strlen(key));
100
- lcb_cmdstore_value(cmd, value, strlen(value));
101
- /* replicate and persist on all nodes */
102
- lcb_cmdstore_durability_observe(cmd, -1, -1);
103
- lcb_store(instance, NULL, cmd);
104
- lcb_cmdstore_destroy(cmd);
105
-
106
- lcb_wait(instance, LCB_WAIT_DEFAULT);
107
-
108
- lcb_destroy(instance);
109
- return EXIT_SUCCESS;
110
- }