couchbase 3.2.0 → 3.2.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +24 -18
- package/binding.gyp +88 -85
- package/deps/lcb/CMakeLists.txt +1 -1
- package/deps/lcb/CONTRIBUTING.md +1 -1
- package/deps/lcb/README.markdown +2 -2
- package/deps/lcb/RELEASE_NOTES.markdown +99 -14
- package/deps/lcb/cmake/Modules/GetVersionInfo.cmake +1 -1
- package/deps/lcb/contrib/cbsasl/src/scram-sha/scram_utils.cc +22 -26
- package/deps/lcb/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +20 -7
- package/deps/lcb/doc/Doxyfile +1 -1
- package/deps/lcb/example/CMakeLists.txt +4 -4
- package/deps/lcb/example/libuvdirect/main.c +39 -12
- package/deps/lcb/example/minimal/durability.cc +149 -0
- package/deps/lcb/example/minimal/query.c +11 -9
- package/deps/lcb/gyp_config/common/libcouchbase/configuration.h +3 -3
- package/deps/lcb/gyp_config/linux/arm64/config.h +243 -0
- package/deps/lcb/include/libcouchbase/couchbase.h +80 -5
- package/deps/lcb/include/libcouchbase/error.h +2 -0
- package/deps/lcb/include/libcouchbase/ixmgmt.h +15 -10
- package/deps/lcb/include/libcouchbase/tracing.h +2 -2
- package/deps/lcb/include/memcached/protocol_binary.h +21 -0
- package/deps/lcb/libcouchbase.gyp +347 -349
- package/deps/lcb/packaging/deb/control +1 -1
- package/deps/lcb/src/analytics/analytics_handle.cc +13 -5
- package/deps/lcb/src/analytics/analytics_handle.hh +29 -0
- package/deps/lcb/src/bootstrap.cc +6 -3
- package/deps/lcb/src/capi/cmd_analytics.cc +12 -1
- package/deps/lcb/src/capi/cmd_analytics.hh +30 -0
- package/deps/lcb/src/capi/cmd_counter.hh +23 -0
- package/deps/lcb/src/capi/cmd_exists.hh +24 -1
- package/deps/lcb/src/capi/cmd_get.hh +22 -0
- package/deps/lcb/src/capi/cmd_get_replica.hh +23 -0
- package/deps/lcb/src/capi/cmd_http.hh +7 -0
- package/deps/lcb/src/capi/cmd_query.cc +11 -1
- package/deps/lcb/src/capi/cmd_query.hh +31 -0
- package/deps/lcb/src/capi/cmd_remove.hh +23 -0
- package/deps/lcb/src/capi/cmd_search.cc +6 -0
- package/deps/lcb/src/capi/cmd_search.hh +23 -0
- package/deps/lcb/src/capi/cmd_store.hh +33 -21
- package/deps/lcb/src/capi/cmd_subdoc.hh +35 -0
- package/deps/lcb/src/capi/cmd_touch.hh +23 -0
- package/deps/lcb/src/capi/cmd_unlock.hh +23 -0
- package/deps/lcb/src/capi/cmd_view.hh +6 -0
- package/deps/lcb/src/capi/collection_qualifier.hh +2 -2
- package/deps/lcb/src/cntl.cc +45 -11
- package/deps/lcb/src/crypto.cc +2 -2
- package/deps/lcb/src/dns-srv.cc +5 -3
- package/deps/lcb/src/errmap.cc +5 -9
- package/deps/lcb/src/errmap.h +7 -3
- package/deps/lcb/src/handler.cc +24 -18
- package/deps/lcb/src/hostlist.h +2 -2
- package/deps/lcb/src/http/http-priv.h +2 -2
- package/deps/lcb/src/http/http.cc +5 -2
- package/deps/lcb/src/instance.cc +20 -11
- package/deps/lcb/src/internal.h +9 -0
- package/deps/lcb/src/lcbio/connect.cc +14 -2
- package/deps/lcb/src/lcbio/connect.h +2 -2
- package/deps/lcb/src/lcbio/ctx.cc +4 -2
- package/deps/lcb/src/lcbio/ioutils.cc +9 -10
- package/deps/lcb/src/lcbio/manager.cc +1 -1
- package/deps/lcb/src/mcserver/mcserver.cc +9 -6
- package/deps/lcb/src/mcserver/negotiate.cc +39 -17
- package/deps/lcb/src/n1ql/ixmgmt.cc +1 -2
- package/deps/lcb/src/n1ql/query_handle.cc +41 -19
- package/deps/lcb/src/n1ql/query_handle.hh +28 -1
- package/deps/lcb/src/operations/counter.cc +18 -5
- package/deps/lcb/src/operations/exists.cc +25 -4
- package/deps/lcb/src/operations/get.cc +39 -19
- package/deps/lcb/src/operations/get_replica.cc +28 -8
- package/deps/lcb/src/operations/observe.cc +1 -1
- package/deps/lcb/src/operations/ping.cc +8 -8
- package/deps/lcb/src/operations/pktfwd.cc +2 -1
- package/deps/lcb/src/operations/remove.cc +39 -22
- package/deps/lcb/src/operations/store.cc +18 -5
- package/deps/lcb/src/operations/subdoc.cc +18 -6
- package/deps/lcb/src/operations/touch.cc +34 -16
- package/deps/lcb/src/operations/unlock.cc +24 -5
- package/deps/lcb/src/packetutils.h +3 -2
- package/deps/lcb/src/retryq.cc +24 -5
- package/deps/lcb/src/search/search.cc +1 -0
- package/deps/lcb/src/search/search_handle.cc +30 -8
- package/deps/lcb/src/search/search_handle.hh +29 -0
- package/deps/lcb/src/settings.cc +1 -1
- package/deps/lcb/src/ssl/ssl_common.c +6 -7
- package/deps/lcb/src/tracing/span.cc +47 -14
- package/deps/lcb/src/tracing/tracer.cc +11 -2
- package/deps/lcb/src/tracing/tracing-internal.h +105 -93
- package/deps/lcb/src/utilities.cc +43 -0
- package/deps/lcb/src/utilities.h +53 -0
- package/deps/lcb/src/vbucket/vbucket.c +34 -33
- package/deps/lcb/src/views/view_handle.cc +13 -5
- package/deps/lcb/src/views/view_handle.hh +29 -0
- package/deps/lcb/tests/CMakeLists.txt +21 -0
- package/deps/lcb/tests/basic/t_ctlcodes.cc +24 -3
- package/deps/lcb/tests/basic/t_jsparse.cc +8 -0
- package/deps/lcb/tests/basic/t_n1qlstrings.cc +73 -0
- package/deps/lcb/tests/iotests/mock-environment.cc +30 -1
- package/deps/lcb/tests/iotests/mock-environment.h +49 -0
- package/deps/lcb/tests/iotests/mock-unit-test.cc +104 -6
- package/deps/lcb/tests/iotests/mock-unit-test.h +34 -0
- package/deps/lcb/tests/iotests/t_collections.cc +1 -1
- package/deps/lcb/tests/iotests/t_confmon.cc +4 -2
- package/deps/lcb/tests/iotests/t_get.cc +109 -7
- package/deps/lcb/tests/iotests/t_http.cc +9 -4
- package/deps/lcb/tests/iotests/t_lock.cc +18 -0
- package/deps/lcb/tests/iotests/t_mutate.cc +157 -63
- package/deps/lcb/tests/iotests/t_n1ql.cc +330 -33
- package/deps/lcb/tests/iotests/t_views.cc +1 -0
- package/deps/lcb/tests/iotests/testutil.cc +168 -0
- package/deps/lcb/tests/iotests/testutil.h +116 -0
- package/deps/lcb/tests/mocksupport/procutil.c +32 -28
- package/deps/lcb/tests/mocksupport/server.c +0 -1
- package/deps/lcb/tests/mocksupport/timeout.c +2 -2
- package/deps/lcb/tools/cbc.cc +7 -0
- package/dist/analyticsindexmanager.js +512 -524
- package/dist/binding.d.ts +3 -0
- package/dist/bindingutilities.js +4 -0
- package/dist/bucket.js +1 -1
- package/dist/bucketmanager.d.ts +31 -1
- package/dist/bucketmanager.js +194 -186
- package/dist/cluster.d.ts +7 -0
- package/dist/cluster.js +48 -38
- package/dist/collection.js +11 -17
- package/dist/collectionmanager.js +181 -197
- package/dist/connection.d.ts +3 -1
- package/dist/connection.js +27 -16
- package/dist/couchbase.d.ts +1 -0
- package/dist/couchbase.js +3 -13
- package/dist/datastructures.js +239 -310
- package/dist/diagnosticsexecutor.js +70 -85
- package/dist/errors.d.ts +70 -0
- package/dist/errors.js +96 -2
- package/dist/eventingfunctionmanager.d.ts +804 -0
- package/dist/eventingfunctionmanager.js +993 -0
- package/dist/httpexecutor.d.ts +2 -1
- package/dist/httpexecutor.js +30 -37
- package/dist/queryindexmanager.js +240 -266
- package/dist/scope.js +10 -4
- package/dist/sdspecs.d.ts +1 -1
- package/dist/searchexecutor.js +3 -0
- package/dist/searchindexmanager.js +240 -271
- package/dist/searchquery.d.ts +17 -0
- package/dist/searchquery.js +22 -1
- package/dist/searchtypes.d.ts +7 -2
- package/dist/searchtypes.js +2 -2
- package/dist/usermanager.js +251 -264
- package/dist/utilities.d.ts +2 -0
- package/dist/utilities.js +7 -2
- package/dist/viewexecutor.js +1 -1
- package/dist/viewindexmanager.js +131 -150
- package/package.json +1 -1
- package/src/addondata.cpp +58 -0
- package/src/addondata.h +40 -0
- package/src/binding.cpp +3 -1
- package/src/cas.h +2 -2
- package/src/connection.cpp +25 -178
- package/src/connection.h +8 -65
- package/src/connection_ops.cpp +57 -34
- package/src/constants.cpp +3 -0
- package/src/instance.cpp +235 -0
- package/src/instance.h +102 -0
- package/src/{connection_callbacks.cpp → instance_callbacks.cpp} +34 -34
- package/src/logger.cpp +11 -1
- package/src/logger.h +3 -0
- package/src/metrics.cpp +10 -0
- package/src/metrics.h +3 -0
- package/src/mutationtoken.h +2 -2
- package/src/opbuilder.h +13 -15
- package/src/respreader.cpp +1 -0
- package/src/respreader.h +6 -4
- package/src/tracespan.h +11 -11
- package/src/tracing.cpp +11 -0
- package/src/tracing.h +3 -0
- package/src/valueparser.h +5 -0
- 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(
|
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
|
-
,
|
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(
|
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
|
-
|
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(
|
315
|
+
OpBuilder(Instance *inst, Ts... args)
|
318
316
|
: CmdBuilder<CmdType>(_valueParser, args...)
|
319
|
-
,
|
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(
|
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(
|
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(
|
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->
|
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->
|
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
|
-
|
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 "
|
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
|
-
|
107
|
+
Instance *instance() const
|
106
108
|
{
|
107
|
-
return
|
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,
|
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(
|
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(
|
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
|
-
|
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(
|
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(
|
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
|
-
|
90
|
+
inst->clientString());
|
91
91
|
|
92
92
|
return TraceSpan(span);
|
93
93
|
}
|
94
94
|
|
95
|
-
static TraceSpan beginDecodeTrace(
|
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(
|
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
|
-
|
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(
|
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(
|
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
@@ -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
|
-
}
|