libcouchbase 1.2.8 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/README.md +16 -8
- data/ext/libcouchbase/CMakeLists.txt +34 -32
- data/ext/libcouchbase/RELEASE_NOTES.markdown +277 -6
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +14 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibevent.cmake +2 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibuv.cmake +2 -1
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +2 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +8 -1
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
- data/ext/libcouchbase/cmake/config-cmake.h.in +14 -0
- data/ext/libcouchbase/cmake/configure +8 -26
- data/ext/libcouchbase/cmake/defs.mk.in +2 -2
- data/ext/libcouchbase/cmake/libcouchbase.stp.in +829 -0
- data/ext/libcouchbase/cmake/source_files.cmake +11 -2
- data/ext/libcouchbase/contrib/cbsasl/CMakeLists.txt +18 -2
- data/ext/libcouchbase/contrib/cbsasl/include/cbsasl/cbsasl.h +44 -2
- data/ext/libcouchbase/contrib/cbsasl/src/client.c +285 -73
- data/ext/libcouchbase/contrib/cbsasl/src/common.c +4 -0
- data/ext/libcouchbase/contrib/cbsasl/src/scram-sha/scram_utils.c +500 -0
- data/ext/libcouchbase/contrib/cbsasl/src/scram-sha/scram_utils.h +99 -0
- data/ext/libcouchbase/contrib/cliopts/CMakeLists.txt +1 -1
- data/ext/libcouchbase/contrib/cliopts/cliopts.h +14 -1
- data/ext/libcouchbase/contrib/snappy/CMakeLists.txt +2 -3
- data/ext/libcouchbase/contrib/snappy/snappy-sinksource.cc +4 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-public.h +7 -5
- data/ext/libcouchbase/contrib/snappy/snappy.cc +7 -2
- data/ext/libcouchbase/example/crypto/.gitignore +2 -0
- data/ext/libcouchbase/example/crypto/Makefile +13 -0
- data/ext/libcouchbase/example/crypto/common_provider.c +24 -0
- data/ext/libcouchbase/example/crypto/common_provider.h +31 -0
- data/ext/libcouchbase/example/crypto/openssl_symmetric_decrypt.c +139 -0
- data/ext/libcouchbase/example/crypto/openssl_symmetric_encrypt.c +147 -0
- data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.c +281 -0
- data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.h +29 -0
- data/ext/libcouchbase/example/tracing/.gitignore +2 -0
- data/ext/libcouchbase/example/tracing/Makefile +8 -0
- data/ext/libcouchbase/example/tracing/cJSON.c +1 -0
- data/ext/libcouchbase/example/tracing/cJSON.h +1 -0
- data/ext/libcouchbase/example/tracing/tracing.c +439 -0
- data/ext/libcouchbase/example/tracing/views.c +444 -0
- data/ext/libcouchbase/include/libcouchbase/auth.h +56 -4
- data/ext/libcouchbase/include/libcouchbase/cbft.h +8 -0
- data/ext/libcouchbase/include/libcouchbase/cntl-private.h +55 -1
- data/ext/libcouchbase/include/libcouchbase/cntl.h +101 -1
- data/ext/libcouchbase/include/libcouchbase/configuration.h.in +6 -0
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +109 -6
- data/ext/libcouchbase/include/libcouchbase/crypto.h +140 -0
- data/ext/libcouchbase/include/libcouchbase/error.h +38 -2
- data/ext/libcouchbase/include/libcouchbase/kvbuf.h +6 -1
- data/ext/libcouchbase/include/libcouchbase/metrics.h +79 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +9 -0
- data/ext/libcouchbase/include/libcouchbase/tracing.h +319 -0
- data/ext/libcouchbase/include/libcouchbase/vbucket.h +1 -1
- data/ext/libcouchbase/include/libcouchbase/views.h +8 -0
- data/ext/libcouchbase/include/memcached/protocol_binary.h +40 -10
- data/ext/libcouchbase/packaging/rpm/libcouchbase.spec.in +6 -14
- data/ext/libcouchbase/plugins/io/libuv/plugin-internal.h +3 -0
- data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +1 -0
- data/ext/libcouchbase/plugins/io/select/plugin-select.c +4 -1
- data/ext/libcouchbase/src/auth-priv.h +36 -4
- data/ext/libcouchbase/src/auth.cc +66 -27
- data/ext/libcouchbase/src/bootstrap.cc +1 -1
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +12 -7
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +26 -17
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +1 -1
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +4 -2
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +6 -3
- data/ext/libcouchbase/src/cbft.cc +48 -0
- data/ext/libcouchbase/src/cntl.cc +138 -2
- data/ext/libcouchbase/src/config_static.h +17 -0
- data/ext/libcouchbase/src/connspec.cc +54 -6
- data/ext/libcouchbase/src/connspec.h +9 -1
- data/ext/libcouchbase/src/crypto.cc +386 -0
- data/ext/libcouchbase/src/ctx-log-inl.h +23 -6
- data/ext/libcouchbase/src/dump.cc +4 -0
- data/ext/libcouchbase/src/getconfig.cc +1 -2
- data/ext/libcouchbase/src/handler.cc +65 -27
- data/ext/libcouchbase/src/hostlist.cc +35 -7
- data/ext/libcouchbase/src/hostlist.h +7 -0
- data/ext/libcouchbase/src/http/http-priv.h +2 -0
- data/ext/libcouchbase/src/http/http.cc +77 -37
- data/ext/libcouchbase/src/http/http_io.cc +19 -2
- data/ext/libcouchbase/src/instance.cc +90 -17
- data/ext/libcouchbase/src/internal.h +5 -0
- data/ext/libcouchbase/src/lcbio/connect.cc +39 -4
- data/ext/libcouchbase/src/lcbio/connect.h +27 -0
- data/ext/libcouchbase/src/lcbio/ctx.c +49 -23
- data/ext/libcouchbase/src/lcbio/ioutils.cc +30 -3
- data/ext/libcouchbase/src/lcbio/ioutils.h +2 -0
- data/ext/libcouchbase/src/lcbio/manager.cc +44 -8
- data/ext/libcouchbase/src/lcbio/manager.h +2 -0
- data/ext/libcouchbase/src/lcbio/rw-inl.h +1 -0
- data/ext/libcouchbase/src/lcbio/ssl.h +3 -5
- data/ext/libcouchbase/src/logging.c +1 -1
- data/ext/libcouchbase/src/logging.h +2 -0
- data/ext/libcouchbase/src/mc/compress.cc +164 -0
- data/ext/libcouchbase/src/mc/compress.h +7 -12
- data/ext/libcouchbase/src/mc/mcreq-flush-inl.h +5 -1
- data/ext/libcouchbase/src/mc/mcreq.c +11 -1
- data/ext/libcouchbase/src/mc/mcreq.h +35 -4
- data/ext/libcouchbase/src/mcserver/mcserver.cc +30 -7
- data/ext/libcouchbase/src/mcserver/mcserver.h +7 -0
- data/ext/libcouchbase/src/mcserver/negotiate.cc +103 -57
- data/ext/libcouchbase/src/mcserver/negotiate.h +2 -2
- data/ext/libcouchbase/src/mctx-helper.h +11 -0
- data/ext/libcouchbase/src/metrics.cc +132 -0
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
- data/ext/libcouchbase/src/n1ql/n1ql.cc +66 -0
- data/ext/libcouchbase/src/newconfig.cc +9 -2
- data/ext/libcouchbase/src/operations/counter.cc +2 -1
- data/ext/libcouchbase/src/operations/durability-cas.cc +11 -0
- data/ext/libcouchbase/src/operations/durability-seqno.cc +3 -0
- data/ext/libcouchbase/src/operations/durability.cc +24 -2
- data/ext/libcouchbase/src/operations/durability_internal.h +19 -0
- data/ext/libcouchbase/src/operations/get.cc +4 -2
- data/ext/libcouchbase/src/operations/observe-seqno.cc +1 -0
- data/ext/libcouchbase/src/operations/observe.cc +113 -62
- data/ext/libcouchbase/src/operations/ping.cc +246 -67
- data/ext/libcouchbase/src/operations/remove.cc +2 -1
- data/ext/libcouchbase/src/operations/store.cc +17 -14
- data/ext/libcouchbase/src/operations/touch.cc +3 -0
- data/ext/libcouchbase/src/packetutils.h +68 -4
- data/ext/libcouchbase/src/probes.d +132 -161
- data/ext/libcouchbase/src/rdb/bigalloc.c +1 -1
- data/ext/libcouchbase/src/retryq.cc +6 -2
- data/ext/libcouchbase/src/rnd.cc +68 -0
- data/ext/libcouchbase/src/rnd.h +39 -0
- data/ext/libcouchbase/src/settings.c +27 -0
- data/ext/libcouchbase/src/settings.h +67 -3
- data/ext/libcouchbase/src/ssl/CMakeLists.txt +0 -12
- data/ext/libcouchbase/src/ssl/ssl_common.c +23 -4
- data/ext/libcouchbase/src/strcodecs/base64.c +141 -16
- data/ext/libcouchbase/src/strcodecs/strcodecs.h +16 -1
- data/ext/libcouchbase/src/trace.h +68 -61
- data/ext/libcouchbase/src/tracing/span.cc +289 -0
- data/ext/libcouchbase/src/tracing/threshold_logging_tracer.cc +171 -0
- data/ext/libcouchbase/src/tracing/tracer.cc +53 -0
- data/ext/libcouchbase/src/tracing/tracing-internal.h +213 -0
- data/ext/libcouchbase/src/utilities.c +5 -0
- data/ext/libcouchbase/src/vbucket/CMakeLists.txt +2 -2
- data/ext/libcouchbase/src/vbucket/vbucket.c +50 -18
- data/ext/libcouchbase/src/views/docreq.cc +26 -1
- data/ext/libcouchbase/src/views/docreq.h +17 -0
- data/ext/libcouchbase/src/views/viewreq.cc +64 -1
- data/ext/libcouchbase/src/views/viewreq.h +21 -0
- data/ext/libcouchbase/tests/CMakeLists.txt +6 -6
- data/ext/libcouchbase/tests/basic/t_base64.cc +34 -6
- data/ext/libcouchbase/tests/basic/t_connstr.cc +14 -0
- data/ext/libcouchbase/tests/basic/t_creds.cc +10 -10
- data/ext/libcouchbase/tests/basic/t_host.cc +22 -2
- data/ext/libcouchbase/tests/basic/t_scram.cc +514 -0
- data/ext/libcouchbase/tests/check-all.cc +6 -2
- data/ext/libcouchbase/tests/iotests/mock-environment.cc +64 -0
- data/ext/libcouchbase/tests/iotests/mock-environment.h +27 -1
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +2 -2
- data/ext/libcouchbase/tests/iotests/t_forward.cc +8 -0
- data/ext/libcouchbase/tests/iotests/t_netfail.cc +124 -0
- data/ext/libcouchbase/tests/iotests/t_smoke.cc +1 -1
- data/ext/libcouchbase/tests/iotests/t_snappy.cc +316 -0
- data/ext/libcouchbase/tests/socktests/socktest.cc +2 -2
- data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
- data/ext/libcouchbase/tests/socktests/t_manager.cc +1 -1
- data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
- data/ext/libcouchbase/tools/CMakeLists.txt +1 -1
- data/ext/libcouchbase/tools/cbc-handlers.h +17 -0
- data/ext/libcouchbase/tools/cbc-n1qlback.cc +7 -4
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +408 -100
- data/ext/libcouchbase/tools/cbc-proxy.cc +134 -3
- data/ext/libcouchbase/tools/cbc-subdoc.cc +1 -2
- data/ext/libcouchbase/tools/cbc.cc +113 -8
- data/ext/libcouchbase/tools/common/histogram.cc +1 -0
- data/ext/libcouchbase/tools/common/options.cc +28 -1
- data/ext/libcouchbase/tools/common/options.h +5 -0
- data/ext/libcouchbase/tools/docgen/docgen.h +36 -10
- data/ext/libcouchbase/tools/docgen/loc.h +5 -4
- data/ext/libcouchbase/tools/docgen/seqgen.h +28 -0
- data/lib/libcouchbase/ext/libcouchbase/enums.rb +10 -0
- data/lib/libcouchbase/n1ql.rb +6 -1
- data/lib/libcouchbase/version.rb +1 -1
- data/spec/connection_spec.rb +6 -6
- metadata +38 -5
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseSnappy.cmake +0 -11
- data/ext/libcouchbase/src/mc/compress.c +0 -90
- data/ext/libcouchbase/tools/common/my_inttypes.h +0 -22
@@ -46,11 +46,26 @@ lcb_urldecode(const char *in, char *out, lcb_SSIZE n);
|
|
46
46
|
/**
|
47
47
|
* Base64 encode a string into an output buffer.
|
48
48
|
* @param src string to encode
|
49
|
+
* @param len size of source buffer
|
49
50
|
* @param dst destination buffer
|
50
51
|
* @param sz size of destination buffer
|
51
52
|
* @return 0 if success, -1 if the destination buffer isn't big enough
|
52
53
|
*/
|
53
|
-
int lcb_base64_encode(const char *src, char *dst,
|
54
|
+
int lcb_base64_encode(const char *src, lcb_SIZE len, char *dst, lcb_SIZE sz);
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Base64 encode a string into an output buffer.
|
58
|
+
* @param src string to encode
|
59
|
+
* @param len size of source buffer
|
60
|
+
* @param dst destination buffer
|
61
|
+
* @param sz size of destination buffer
|
62
|
+
* @return 0 if success, -1 if function wasn't able to allocate enough memory
|
63
|
+
*/
|
64
|
+
int lcb_base64_encode2(const char *src, lcb_SIZE len, char **dst, lcb_SIZE *sz);
|
65
|
+
|
66
|
+
|
67
|
+
lcb_SSIZE lcb_base64_decode(const char *src, lcb_SIZE nsrc, char *dst, lcb_SIZE ndst);
|
68
|
+
lcb_SSIZE lcb_base64_decode2(const char *src, lcb_SIZE nsrc, char **dst, lcb_SIZE *ndst);
|
54
69
|
|
55
70
|
/**
|
56
71
|
* Encodes a string suitable for being passed as either a key or value in an
|
@@ -38,70 +38,77 @@
|
|
38
38
|
#define TRACE(probe)
|
39
39
|
#endif
|
40
40
|
|
41
|
-
#define TRACE_BEGIN_COMMON(TGT, req, cmd,
|
42
|
-
TGT((req)->request.opaque,
|
43
|
-
|
41
|
+
#define TRACE_BEGIN_COMMON(TGT, instance, req, cmd, ...) \
|
42
|
+
TGT(instance, (req)->request.opaque, lcb_ntohs((req)->request.vbucket), (req)->request.opcode, \
|
43
|
+
(const char *)((cmd)->key.contig.bytes), (cmd)->key.contig.nbytes, ##__VA_ARGS__)
|
44
44
|
|
45
|
-
#define TRACE_BEGIN_SIMPLE(TGT, req, cmd)
|
46
|
-
TGT((req)->request.opaque,
|
45
|
+
#define TRACE_BEGIN_SIMPLE(TGT, instance, req, cmd) \
|
46
|
+
TGT(instance, (req)->request.opaque, lcb_ntohs((req)->request.vbucket), (req)->request.opcode, \
|
47
47
|
(const char *)(cmd)->key.contig.bytes, (cmd)->key.contig.nbytes)
|
48
48
|
|
49
|
-
#define TRACE_END_COMMON(TGT, mcresp, resp, ...)
|
50
|
-
TGT(mcresp->opaque(),
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
#define TRACE_UNLOCK_BEGIN(req, cmd) TRACE(TRACE_BEGIN_SIMPLE(LIBCOUCHBASE_UNLOCK_BEGIN, req, cmd))
|
65
|
-
#define TRACE_UNLOCK_END(
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
(
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#define
|
76
|
-
TRACE(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
#define
|
85
|
-
TRACE(
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
#define TRACE_OBSERVE_PROGRESS(mcresp, resp)
|
97
|
-
TRACE(TRACE_END_COMMON(LIBCOUCHBASE_OBSERVE_PROGRESS,mcresp,resp, \
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
#define TRACE_HTTP_BEGIN(req)
|
104
|
-
|
49
|
+
#define TRACE_END_COMMON(TGT, instance, pkt, mcresp, resp, ...) \
|
50
|
+
TGT(instance, mcresp->opaque(), mcresp->opcode(), \
|
51
|
+
(MCREQ_PKT_RDATA(pkt)->dispatch) - (MCREQ_PKT_RDATA(pkt)->start), (resp)->rc, (const char *)(resp)->key, \
|
52
|
+
(resp)->nkey, ##__VA_ARGS__)
|
53
|
+
|
54
|
+
#define TRACE_END_SIMPLE(TGT, instance, pkt, mcresp, resp) \
|
55
|
+
TGT(instance, mcresp->opaque(), mcresp->opcode(), MCREQ_PKT_RDATA(pkt)->dispatch - MCREQ_PKT_RDATA(pkt)->start, \
|
56
|
+
(resp)->rc, (const char *)(resp)->key, (resp)->nkey)
|
57
|
+
|
58
|
+
#define TRACE_GET_BEGIN(instance, req, cmd) \
|
59
|
+
TRACE(TRACE_BEGIN_COMMON(LIBCOUCHBASE_GET_BEGIN, instance, req, cmd, (cmd)->exptime))
|
60
|
+
#define TRACE_GET_END(instance, pkt, mcresp, resp) \
|
61
|
+
TRACE(TRACE_END_COMMON(LIBCOUCHBASE_GET_END, instance, pkt, mcresp, resp, (const char *)(resp)->value, \
|
62
|
+
(resp)->nvalue, (resp)->itmflags, (resp)->cas, mcresp->datatype()))
|
63
|
+
|
64
|
+
#define TRACE_UNLOCK_BEGIN(instance, req, cmd) TRACE(TRACE_BEGIN_SIMPLE(LIBCOUCHBASE_UNLOCK_BEGIN, instance, req, cmd))
|
65
|
+
#define TRACE_UNLOCK_END(instance, pkt, mcresp, resp) \
|
66
|
+
TRACE(TRACE_END_SIMPLE(LIBCOUCHBASE_UNLOCK_END, instance, pkt, mcresp, resp))
|
67
|
+
|
68
|
+
#define TRACE_STORE_BEGIN(instance, req, cmd) \
|
69
|
+
TRACE( \
|
70
|
+
TRACE_BEGIN_COMMON(LIBCOUCHBASE_STORE_BEGIN, instance, req, cmd, \
|
71
|
+
(const char *)((cmd)->value.vtype == LCB_KV_IOV ? NULL : (cmd)->value.u_buf.contig.bytes), \
|
72
|
+
((cmd)->value.vtype == LCB_KV_IOV ? 0 : (cmd)->value.u_buf.contig.nbytes), (cmd)->flags, \
|
73
|
+
(cmd)->cas, (req)->request.datatype, (cmd)->exptime))
|
74
|
+
|
75
|
+
#define TRACE_STORE_END(instance, pkt, mcresp, resp) \
|
76
|
+
TRACE(TRACE_END_COMMON(LIBCOUCHBASE_STORE_END, instance, pkt, mcresp, resp, (resp)->cas))
|
77
|
+
|
78
|
+
#define TRACE_ARITHMETIC_BEGIN(instance, req, cmd) \
|
79
|
+
TRACE(TRACE_BEGIN_COMMON(LIBCOUCHBASE_ARITHMETIC_BEGIN, instance, req, cmd, (cmd)->delta, (cmd)->initial, \
|
80
|
+
(cmd)->exptime))
|
81
|
+
#define TRACE_ARITHMETIC_END(instance, pkt, mcresp, resp) \
|
82
|
+
TRACE(TRACE_END_COMMON(LIBCOUCHBASE_ARITHMETIC_END, instance, pkt, mcresp, resp, (resp)->value, (resp)->cas))
|
83
|
+
|
84
|
+
#define TRACE_TOUCH_BEGIN(instance, req, cmd) \
|
85
|
+
TRACE(TRACE_BEGIN_COMMON(LIBCOUCHBASE_TOUCH_BEGIN, instance, req, cmd, (cmd)->exptime))
|
86
|
+
#define TRACE_TOUCH_END(instance, pkt, mcresp, resp) \
|
87
|
+
TRACE(TRACE_END_COMMON(LIBCOUCHBASE_TOUCH_END, instance, pkt, mcresp, resp, (resp)->cas))
|
88
|
+
|
89
|
+
#define TRACE_REMOVE_BEGIN(instance, req, cmd) TRACE(TRACE_BEGIN_SIMPLE(LIBCOUCHBASE_REMOVE_BEGIN, instance, req, cmd))
|
90
|
+
#define TRACE_REMOVE_END(instance, pkt, mcresp, resp) \
|
91
|
+
TRACE(TRACE_END_COMMON(LIBCOUCHBASE_REMOVE_END, instance, pkt, mcresp, resp, (resp)->cas))
|
92
|
+
|
93
|
+
#define TRACE_OBSERVE_BEGIN(instance, req, body) \
|
94
|
+
TRACE(LIBCOUCHBASE_OBSERVE_BEGIN(instance, (req)->request.opaque, (req)->request.opcode, body, \
|
95
|
+
ntohl((req)->request.bodylen)))
|
96
|
+
#define TRACE_OBSERVE_PROGRESS(instance, pkt, mcresp, resp) \
|
97
|
+
TRACE(TRACE_END_COMMON(LIBCOUCHBASE_OBSERVE_PROGRESS, instance, pkt, mcresp, resp, (resp)->cas, (resp)->status, \
|
98
|
+
(resp)->ismaster, (resp)->ttp, (resp)->ttr))
|
99
|
+
#define TRACE_OBSERVE_END(instance, pkt, mcresp) \
|
100
|
+
TRACE(LIBCOUCHBASE_OBSERVE_END(instance, mcresp->opaque(), mcresp->opcode(), \
|
101
|
+
MCREQ_PKT_RDATA(pkt)->dispatch - MCREQ_PKT_RDATA(pkt)->start, LCB_SUCCESS))
|
102
|
+
|
103
|
+
#define TRACE_HTTP_BEGIN(req) \
|
104
|
+
TRACE(LIBCOUCHBASE_HTTP_BEGIN((req)->instance, (req), (req)->reqtype, (req)->method, (req)->url.c_str(), \
|
105
|
+
(req)->host.c_str(), (req)->port.c_str()))
|
106
|
+
#define TRACE_HTTP_END(req, rc, htstatus) \
|
107
|
+
TRACE(LIBCOUCHBASE_HTTP_END((req)->instance, (req), (req)->reqtype, (req)->method, (req)->url.c_str(), \
|
108
|
+
(req)->host.c_str(), (req)->port.c_str(), rc, htstatus, (gethrtime() - (req)->start)))
|
109
|
+
|
110
|
+
#define TRACE_NEW_CONFIG(instance, config) \
|
111
|
+
TRACE(LIBCOUCHBASE_NEW_CONFIG(instance, (config)->vbc->revid, (config)->vbc->bname, (config)->vbc->buuid, (config)))
|
105
112
|
|
106
113
|
#ifdef __clang__
|
107
114
|
#pragma GCC diagnostic pop
|
@@ -0,0 +1,289 @@
|
|
1
|
+
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2017 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
|
+
#include "internal.h"
|
19
|
+
#ifdef HAVE__FTIME64_S
|
20
|
+
#include <sys/timeb.h>
|
21
|
+
#endif
|
22
|
+
|
23
|
+
LIBCOUCHBASE_API
|
24
|
+
uint64_t lcbtrace_now()
|
25
|
+
{
|
26
|
+
uint64_t ret;
|
27
|
+
#ifdef HAVE__FTIME64_S
|
28
|
+
struct __timeb64 tb;
|
29
|
+
_ftime64_s(&tb);
|
30
|
+
ret = (uint64_t)tb.time * 1000000; /* sec */
|
31
|
+
ret += (uint64_t)tb.millitm * 1000;
|
32
|
+
#else
|
33
|
+
struct timeval tv;
|
34
|
+
if (gettimeofday(&tv, NULL) == -1) {
|
35
|
+
return -1;
|
36
|
+
}
|
37
|
+
ret = (uint64_t)tv.tv_sec * 1000000;
|
38
|
+
ret += (uint64_t)tv.tv_usec;
|
39
|
+
#endif
|
40
|
+
return ret;
|
41
|
+
}
|
42
|
+
|
43
|
+
LIBCOUCHBASE_API
|
44
|
+
void lcbtrace_span_finish(lcbtrace_SPAN *span, uint64_t now)
|
45
|
+
{
|
46
|
+
if (!span) {
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
|
50
|
+
span->finish(now);
|
51
|
+
delete span;
|
52
|
+
}
|
53
|
+
|
54
|
+
LIBCOUCHBASE_API
|
55
|
+
void lcbtrace_span_add_tag_str(lcbtrace_SPAN *span, const char *name, const char *value)
|
56
|
+
{
|
57
|
+
if (!span) {
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
span->add_tag(name, value);
|
61
|
+
}
|
62
|
+
|
63
|
+
LIBCOUCHBASE_API
|
64
|
+
void lcbtrace_span_add_tag_uint64(lcbtrace_SPAN *span, const char *name, uint64_t value)
|
65
|
+
{
|
66
|
+
if (!span) {
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
span->add_tag(name, (Json::Value::UInt64)value);
|
70
|
+
}
|
71
|
+
|
72
|
+
LIBCOUCHBASE_API
|
73
|
+
void lcbtrace_span_add_tag_double(lcbtrace_SPAN *span, const char *name, double value)
|
74
|
+
{
|
75
|
+
if (!span) {
|
76
|
+
return;
|
77
|
+
}
|
78
|
+
span->add_tag(name, value);
|
79
|
+
}
|
80
|
+
|
81
|
+
LIBCOUCHBASE_API
|
82
|
+
void lcbtrace_span_add_tag_bool(lcbtrace_SPAN *span, const char *name, int value)
|
83
|
+
{
|
84
|
+
if (!span) {
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
span->add_tag(name, value);
|
88
|
+
}
|
89
|
+
|
90
|
+
LCB_INTERNAL_API
|
91
|
+
void lcbtrace_span_add_system_tags(lcbtrace_SPAN *span, lcb_settings *settings, const char *service)
|
92
|
+
{
|
93
|
+
if (!span) {
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
lcbtrace_span_add_tag_str(span, LCBTRACE_TAG_SERVICE, service);
|
97
|
+
std::string client_string(LCB_CLIENT_ID);
|
98
|
+
if (settings->client_string) {
|
99
|
+
client_string += " ";
|
100
|
+
client_string += settings->client_string;
|
101
|
+
}
|
102
|
+
lcbtrace_span_add_tag_str(span, LCBTRACE_TAG_COMPONENT, client_string.c_str());
|
103
|
+
if (settings->bucket) {
|
104
|
+
lcbtrace_span_add_tag_str(span, LCBTRACE_TAG_DB_INSTANCE, settings->bucket);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
LIBCOUCHBASE_API
|
109
|
+
lcbtrace_SPAN *lcbtrace_span_get_parent(lcbtrace_SPAN *span)
|
110
|
+
{
|
111
|
+
if (!span) {
|
112
|
+
return NULL;
|
113
|
+
}
|
114
|
+
return span->m_parent;
|
115
|
+
}
|
116
|
+
|
117
|
+
LCB_INTERNAL_API
|
118
|
+
void lcbtrace_span_set_parent(lcbtrace_SPAN *span, lcbtrace_SPAN *parent)
|
119
|
+
{
|
120
|
+
if (!span) {
|
121
|
+
return;
|
122
|
+
}
|
123
|
+
span->m_parent = parent;
|
124
|
+
}
|
125
|
+
|
126
|
+
LIBCOUCHBASE_API
|
127
|
+
uint64_t lcbtrace_span_get_start_ts(lcbtrace_SPAN *span)
|
128
|
+
{
|
129
|
+
if (!span) {
|
130
|
+
return 0;
|
131
|
+
}
|
132
|
+
return span->m_start;
|
133
|
+
}
|
134
|
+
|
135
|
+
LIBCOUCHBASE_API
|
136
|
+
uint64_t lcbtrace_span_get_finish_ts(lcbtrace_SPAN *span)
|
137
|
+
{
|
138
|
+
if (!span) {
|
139
|
+
return 0;
|
140
|
+
}
|
141
|
+
return span->m_finish;
|
142
|
+
}
|
143
|
+
|
144
|
+
LIBCOUCHBASE_API
|
145
|
+
int lcbtrace_span_is_orphaned(lcbtrace_SPAN *span)
|
146
|
+
{
|
147
|
+
return span && span->m_orphaned;
|
148
|
+
}
|
149
|
+
|
150
|
+
LCB_INTERNAL_API
|
151
|
+
void lcbtrace_span_set_orphaned(lcbtrace_SPAN *span, int val)
|
152
|
+
{
|
153
|
+
if (!span) {
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
span->m_orphaned = (val != 0);
|
157
|
+
}
|
158
|
+
|
159
|
+
LIBCOUCHBASE_API
|
160
|
+
uint64_t lcbtrace_span_get_span_id(lcbtrace_SPAN *span)
|
161
|
+
{
|
162
|
+
if (!span) {
|
163
|
+
return 0;
|
164
|
+
}
|
165
|
+
return span->m_span_id;
|
166
|
+
}
|
167
|
+
|
168
|
+
LIBCOUCHBASE_API
|
169
|
+
const char *lcbtrace_span_get_operation(lcbtrace_SPAN *span)
|
170
|
+
{
|
171
|
+
if (!span) {
|
172
|
+
return NULL;
|
173
|
+
}
|
174
|
+
return span->m_opname.c_str();
|
175
|
+
}
|
176
|
+
|
177
|
+
LIBCOUCHBASE_API
|
178
|
+
uint64_t lcbtrace_span_get_trace_id(lcbtrace_SPAN *span)
|
179
|
+
{
|
180
|
+
if (!span) {
|
181
|
+
return 0;
|
182
|
+
}
|
183
|
+
if (span->m_parent) {
|
184
|
+
return span->m_parent->m_span_id;
|
185
|
+
}
|
186
|
+
return span->m_span_id;
|
187
|
+
}
|
188
|
+
|
189
|
+
LIBCOUCHBASE_API
|
190
|
+
lcb_error_t lcbtrace_span_get_tag_str(lcbtrace_SPAN *span, const char *name, char **value, size_t *nvalue)
|
191
|
+
{
|
192
|
+
if (!span) {
|
193
|
+
return LCB_EINVAL;
|
194
|
+
}
|
195
|
+
Json::Value &val = span->tags[name];
|
196
|
+
if (val.isString()) {
|
197
|
+
std::string str = val.asString();
|
198
|
+
if (*nvalue) {
|
199
|
+
/* string has been pre-allocated */
|
200
|
+
if (str.size() < *nvalue) {
|
201
|
+
*nvalue = str.size();
|
202
|
+
}
|
203
|
+
} else {
|
204
|
+
*nvalue = str.size();
|
205
|
+
*value = (char *)calloc(*nvalue, sizeof(char));
|
206
|
+
}
|
207
|
+
str.copy(*value, *nvalue, 0);
|
208
|
+
return LCB_SUCCESS;
|
209
|
+
}
|
210
|
+
return LCB_KEY_ENOENT;
|
211
|
+
}
|
212
|
+
|
213
|
+
LIBCOUCHBASE_API lcb_error_t lcbtrace_span_get_tag_uint64(lcbtrace_SPAN *span, const char *name, uint64_t *value)
|
214
|
+
{
|
215
|
+
if (!span) {
|
216
|
+
return LCB_EINVAL;
|
217
|
+
}
|
218
|
+
Json::Value &val = span->tags[name];
|
219
|
+
if (val.isNumeric()) {
|
220
|
+
*value = val.asUInt64();
|
221
|
+
return LCB_SUCCESS;
|
222
|
+
}
|
223
|
+
return LCB_KEY_ENOENT;
|
224
|
+
}
|
225
|
+
|
226
|
+
LIBCOUCHBASE_API lcb_error_t lcbtrace_span_get_tag_double(lcbtrace_SPAN *span, const char *name, double *value)
|
227
|
+
{
|
228
|
+
if (!span) {
|
229
|
+
return LCB_EINVAL;
|
230
|
+
}
|
231
|
+
Json::Value &val = span->tags[name];
|
232
|
+
if (val.isNumeric()) {
|
233
|
+
*value = val.asDouble();
|
234
|
+
return LCB_SUCCESS;
|
235
|
+
}
|
236
|
+
return LCB_KEY_ENOENT;
|
237
|
+
}
|
238
|
+
|
239
|
+
LIBCOUCHBASE_API lcb_error_t lcbtrace_span_get_tag_bool(lcbtrace_SPAN *span, const char *name, int *value)
|
240
|
+
{
|
241
|
+
if (!span) {
|
242
|
+
return LCB_EINVAL;
|
243
|
+
}
|
244
|
+
Json::Value &val = span->tags[name];
|
245
|
+
if (val.isBool()) {
|
246
|
+
*value = val.asBool();
|
247
|
+
return LCB_SUCCESS;
|
248
|
+
}
|
249
|
+
return LCB_KEY_ENOENT;
|
250
|
+
}
|
251
|
+
|
252
|
+
LIBCOUCHBASE_API int lcbtrace_span_has_tag(lcbtrace_SPAN *span, const char *name)
|
253
|
+
{
|
254
|
+
if (!span) {
|
255
|
+
return 0;
|
256
|
+
}
|
257
|
+
return span->tags.isMember(name);
|
258
|
+
}
|
259
|
+
|
260
|
+
using namespace lcb::trace;
|
261
|
+
|
262
|
+
Span::Span(lcbtrace_TRACER *tracer, const char *opname, uint64_t start, lcbtrace_REF_TYPE ref, lcbtrace_SPAN *other)
|
263
|
+
: m_tracer(tracer), m_opname(opname)
|
264
|
+
{
|
265
|
+
m_start = start ? start : lcbtrace_now();
|
266
|
+
m_span_id = lcb_next_rand64();
|
267
|
+
m_orphaned = false;
|
268
|
+
add_tag(LCBTRACE_TAG_DB_TYPE, "couchbase");
|
269
|
+
add_tag(LCBTRACE_TAG_SPAN_KIND, "client");
|
270
|
+
|
271
|
+
if (other != NULL && ref == LCBTRACE_REF_CHILD_OF) {
|
272
|
+
m_parent = other;
|
273
|
+
} else {
|
274
|
+
m_parent = NULL;
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
void Span::finish(uint64_t now)
|
279
|
+
{
|
280
|
+
m_finish = now ? now : lcbtrace_now();
|
281
|
+
if (m_tracer && m_tracer->version == 0 && m_tracer->v.v0.report) {
|
282
|
+
m_tracer->v.v0.report(m_tracer, this);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
template < typename T > void Span::add_tag(const char *name, T value)
|
287
|
+
{
|
288
|
+
tags[name] = value;
|
289
|
+
}
|