libcouchbase 1.2.8 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -4
  3. data/README.md +16 -8
  4. data/ext/libcouchbase/CMakeLists.txt +34 -32
  5. data/ext/libcouchbase/RELEASE_NOTES.markdown +277 -6
  6. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +14 -0
  7. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibevent.cmake +2 -0
  8. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibuv.cmake +2 -1
  9. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +2 -0
  10. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +8 -1
  11. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  12. data/ext/libcouchbase/cmake/config-cmake.h.in +14 -0
  13. data/ext/libcouchbase/cmake/configure +8 -26
  14. data/ext/libcouchbase/cmake/defs.mk.in +2 -2
  15. data/ext/libcouchbase/cmake/libcouchbase.stp.in +829 -0
  16. data/ext/libcouchbase/cmake/source_files.cmake +11 -2
  17. data/ext/libcouchbase/contrib/cbsasl/CMakeLists.txt +18 -2
  18. data/ext/libcouchbase/contrib/cbsasl/include/cbsasl/cbsasl.h +44 -2
  19. data/ext/libcouchbase/contrib/cbsasl/src/client.c +285 -73
  20. data/ext/libcouchbase/contrib/cbsasl/src/common.c +4 -0
  21. data/ext/libcouchbase/contrib/cbsasl/src/scram-sha/scram_utils.c +500 -0
  22. data/ext/libcouchbase/contrib/cbsasl/src/scram-sha/scram_utils.h +99 -0
  23. data/ext/libcouchbase/contrib/cliopts/CMakeLists.txt +1 -1
  24. data/ext/libcouchbase/contrib/cliopts/cliopts.h +14 -1
  25. data/ext/libcouchbase/contrib/snappy/CMakeLists.txt +2 -3
  26. data/ext/libcouchbase/contrib/snappy/snappy-sinksource.cc +4 -0
  27. data/ext/libcouchbase/contrib/snappy/snappy-stubs-public.h +7 -5
  28. data/ext/libcouchbase/contrib/snappy/snappy.cc +7 -2
  29. data/ext/libcouchbase/example/crypto/.gitignore +2 -0
  30. data/ext/libcouchbase/example/crypto/Makefile +13 -0
  31. data/ext/libcouchbase/example/crypto/common_provider.c +24 -0
  32. data/ext/libcouchbase/example/crypto/common_provider.h +31 -0
  33. data/ext/libcouchbase/example/crypto/openssl_symmetric_decrypt.c +139 -0
  34. data/ext/libcouchbase/example/crypto/openssl_symmetric_encrypt.c +147 -0
  35. data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.c +281 -0
  36. data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.h +29 -0
  37. data/ext/libcouchbase/example/tracing/.gitignore +2 -0
  38. data/ext/libcouchbase/example/tracing/Makefile +8 -0
  39. data/ext/libcouchbase/example/tracing/cJSON.c +1 -0
  40. data/ext/libcouchbase/example/tracing/cJSON.h +1 -0
  41. data/ext/libcouchbase/example/tracing/tracing.c +439 -0
  42. data/ext/libcouchbase/example/tracing/views.c +444 -0
  43. data/ext/libcouchbase/include/libcouchbase/auth.h +56 -4
  44. data/ext/libcouchbase/include/libcouchbase/cbft.h +8 -0
  45. data/ext/libcouchbase/include/libcouchbase/cntl-private.h +55 -1
  46. data/ext/libcouchbase/include/libcouchbase/cntl.h +101 -1
  47. data/ext/libcouchbase/include/libcouchbase/configuration.h.in +6 -0
  48. data/ext/libcouchbase/include/libcouchbase/couchbase.h +109 -6
  49. data/ext/libcouchbase/include/libcouchbase/crypto.h +140 -0
  50. data/ext/libcouchbase/include/libcouchbase/error.h +38 -2
  51. data/ext/libcouchbase/include/libcouchbase/kvbuf.h +6 -1
  52. data/ext/libcouchbase/include/libcouchbase/metrics.h +79 -0
  53. data/ext/libcouchbase/include/libcouchbase/n1ql.h +9 -0
  54. data/ext/libcouchbase/include/libcouchbase/tracing.h +319 -0
  55. data/ext/libcouchbase/include/libcouchbase/vbucket.h +1 -1
  56. data/ext/libcouchbase/include/libcouchbase/views.h +8 -0
  57. data/ext/libcouchbase/include/memcached/protocol_binary.h +40 -10
  58. data/ext/libcouchbase/packaging/rpm/libcouchbase.spec.in +6 -14
  59. data/ext/libcouchbase/plugins/io/libuv/plugin-internal.h +3 -0
  60. data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +1 -0
  61. data/ext/libcouchbase/plugins/io/select/plugin-select.c +4 -1
  62. data/ext/libcouchbase/src/auth-priv.h +36 -4
  63. data/ext/libcouchbase/src/auth.cc +66 -27
  64. data/ext/libcouchbase/src/bootstrap.cc +1 -1
  65. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +12 -7
  66. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +26 -17
  67. data/ext/libcouchbase/src/bucketconfig/bc_http.h +1 -1
  68. data/ext/libcouchbase/src/bucketconfig/clconfig.h +4 -2
  69. data/ext/libcouchbase/src/bucketconfig/confmon.cc +6 -3
  70. data/ext/libcouchbase/src/cbft.cc +48 -0
  71. data/ext/libcouchbase/src/cntl.cc +138 -2
  72. data/ext/libcouchbase/src/config_static.h +17 -0
  73. data/ext/libcouchbase/src/connspec.cc +54 -6
  74. data/ext/libcouchbase/src/connspec.h +9 -1
  75. data/ext/libcouchbase/src/crypto.cc +386 -0
  76. data/ext/libcouchbase/src/ctx-log-inl.h +23 -6
  77. data/ext/libcouchbase/src/dump.cc +4 -0
  78. data/ext/libcouchbase/src/getconfig.cc +1 -2
  79. data/ext/libcouchbase/src/handler.cc +65 -27
  80. data/ext/libcouchbase/src/hostlist.cc +35 -7
  81. data/ext/libcouchbase/src/hostlist.h +7 -0
  82. data/ext/libcouchbase/src/http/http-priv.h +2 -0
  83. data/ext/libcouchbase/src/http/http.cc +77 -37
  84. data/ext/libcouchbase/src/http/http_io.cc +19 -2
  85. data/ext/libcouchbase/src/instance.cc +90 -17
  86. data/ext/libcouchbase/src/internal.h +5 -0
  87. data/ext/libcouchbase/src/lcbio/connect.cc +39 -4
  88. data/ext/libcouchbase/src/lcbio/connect.h +27 -0
  89. data/ext/libcouchbase/src/lcbio/ctx.c +49 -23
  90. data/ext/libcouchbase/src/lcbio/ioutils.cc +30 -3
  91. data/ext/libcouchbase/src/lcbio/ioutils.h +2 -0
  92. data/ext/libcouchbase/src/lcbio/manager.cc +44 -8
  93. data/ext/libcouchbase/src/lcbio/manager.h +2 -0
  94. data/ext/libcouchbase/src/lcbio/rw-inl.h +1 -0
  95. data/ext/libcouchbase/src/lcbio/ssl.h +3 -5
  96. data/ext/libcouchbase/src/logging.c +1 -1
  97. data/ext/libcouchbase/src/logging.h +2 -0
  98. data/ext/libcouchbase/src/mc/compress.cc +164 -0
  99. data/ext/libcouchbase/src/mc/compress.h +7 -12
  100. data/ext/libcouchbase/src/mc/mcreq-flush-inl.h +5 -1
  101. data/ext/libcouchbase/src/mc/mcreq.c +11 -1
  102. data/ext/libcouchbase/src/mc/mcreq.h +35 -4
  103. data/ext/libcouchbase/src/mcserver/mcserver.cc +30 -7
  104. data/ext/libcouchbase/src/mcserver/mcserver.h +7 -0
  105. data/ext/libcouchbase/src/mcserver/negotiate.cc +103 -57
  106. data/ext/libcouchbase/src/mcserver/negotiate.h +2 -2
  107. data/ext/libcouchbase/src/mctx-helper.h +11 -0
  108. data/ext/libcouchbase/src/metrics.cc +132 -0
  109. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
  110. data/ext/libcouchbase/src/n1ql/n1ql.cc +66 -0
  111. data/ext/libcouchbase/src/newconfig.cc +9 -2
  112. data/ext/libcouchbase/src/operations/counter.cc +2 -1
  113. data/ext/libcouchbase/src/operations/durability-cas.cc +11 -0
  114. data/ext/libcouchbase/src/operations/durability-seqno.cc +3 -0
  115. data/ext/libcouchbase/src/operations/durability.cc +24 -2
  116. data/ext/libcouchbase/src/operations/durability_internal.h +19 -0
  117. data/ext/libcouchbase/src/operations/get.cc +4 -2
  118. data/ext/libcouchbase/src/operations/observe-seqno.cc +1 -0
  119. data/ext/libcouchbase/src/operations/observe.cc +113 -62
  120. data/ext/libcouchbase/src/operations/ping.cc +246 -67
  121. data/ext/libcouchbase/src/operations/remove.cc +2 -1
  122. data/ext/libcouchbase/src/operations/store.cc +17 -14
  123. data/ext/libcouchbase/src/operations/touch.cc +3 -0
  124. data/ext/libcouchbase/src/packetutils.h +68 -4
  125. data/ext/libcouchbase/src/probes.d +132 -161
  126. data/ext/libcouchbase/src/rdb/bigalloc.c +1 -1
  127. data/ext/libcouchbase/src/retryq.cc +6 -2
  128. data/ext/libcouchbase/src/rnd.cc +68 -0
  129. data/ext/libcouchbase/src/rnd.h +39 -0
  130. data/ext/libcouchbase/src/settings.c +27 -0
  131. data/ext/libcouchbase/src/settings.h +67 -3
  132. data/ext/libcouchbase/src/ssl/CMakeLists.txt +0 -12
  133. data/ext/libcouchbase/src/ssl/ssl_common.c +23 -4
  134. data/ext/libcouchbase/src/strcodecs/base64.c +141 -16
  135. data/ext/libcouchbase/src/strcodecs/strcodecs.h +16 -1
  136. data/ext/libcouchbase/src/trace.h +68 -61
  137. data/ext/libcouchbase/src/tracing/span.cc +289 -0
  138. data/ext/libcouchbase/src/tracing/threshold_logging_tracer.cc +171 -0
  139. data/ext/libcouchbase/src/tracing/tracer.cc +53 -0
  140. data/ext/libcouchbase/src/tracing/tracing-internal.h +213 -0
  141. data/ext/libcouchbase/src/utilities.c +5 -0
  142. data/ext/libcouchbase/src/vbucket/CMakeLists.txt +2 -2
  143. data/ext/libcouchbase/src/vbucket/vbucket.c +50 -18
  144. data/ext/libcouchbase/src/views/docreq.cc +26 -1
  145. data/ext/libcouchbase/src/views/docreq.h +17 -0
  146. data/ext/libcouchbase/src/views/viewreq.cc +64 -1
  147. data/ext/libcouchbase/src/views/viewreq.h +21 -0
  148. data/ext/libcouchbase/tests/CMakeLists.txt +6 -6
  149. data/ext/libcouchbase/tests/basic/t_base64.cc +34 -6
  150. data/ext/libcouchbase/tests/basic/t_connstr.cc +14 -0
  151. data/ext/libcouchbase/tests/basic/t_creds.cc +10 -10
  152. data/ext/libcouchbase/tests/basic/t_host.cc +22 -2
  153. data/ext/libcouchbase/tests/basic/t_scram.cc +514 -0
  154. data/ext/libcouchbase/tests/check-all.cc +6 -2
  155. data/ext/libcouchbase/tests/iotests/mock-environment.cc +64 -0
  156. data/ext/libcouchbase/tests/iotests/mock-environment.h +27 -1
  157. data/ext/libcouchbase/tests/iotests/t_confmon.cc +2 -2
  158. data/ext/libcouchbase/tests/iotests/t_forward.cc +8 -0
  159. data/ext/libcouchbase/tests/iotests/t_netfail.cc +124 -0
  160. data/ext/libcouchbase/tests/iotests/t_smoke.cc +1 -1
  161. data/ext/libcouchbase/tests/iotests/t_snappy.cc +316 -0
  162. data/ext/libcouchbase/tests/socktests/socktest.cc +2 -2
  163. data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
  164. data/ext/libcouchbase/tests/socktests/t_manager.cc +1 -1
  165. data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
  166. data/ext/libcouchbase/tools/CMakeLists.txt +1 -1
  167. data/ext/libcouchbase/tools/cbc-handlers.h +17 -0
  168. data/ext/libcouchbase/tools/cbc-n1qlback.cc +7 -4
  169. data/ext/libcouchbase/tools/cbc-pillowfight.cc +408 -100
  170. data/ext/libcouchbase/tools/cbc-proxy.cc +134 -3
  171. data/ext/libcouchbase/tools/cbc-subdoc.cc +1 -2
  172. data/ext/libcouchbase/tools/cbc.cc +113 -8
  173. data/ext/libcouchbase/tools/common/histogram.cc +1 -0
  174. data/ext/libcouchbase/tools/common/options.cc +28 -1
  175. data/ext/libcouchbase/tools/common/options.h +5 -0
  176. data/ext/libcouchbase/tools/docgen/docgen.h +36 -10
  177. data/ext/libcouchbase/tools/docgen/loc.h +5 -4
  178. data/ext/libcouchbase/tools/docgen/seqgen.h +28 -0
  179. data/lib/libcouchbase/ext/libcouchbase/enums.rb +10 -0
  180. data/lib/libcouchbase/n1ql.rb +6 -1
  181. data/lib/libcouchbase/version.rb +1 -1
  182. data/spec/connection_spec.rb +6 -6
  183. metadata +38 -5
  184. data/ext/libcouchbase/cmake/Modules/FindCouchbaseSnappy.cmake +0 -11
  185. data/ext/libcouchbase/src/mc/compress.c +0 -90
  186. 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, lcb_size_t sz);
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, ntohs((req)->request.vbucket), (req)->request.opcode, \
43
- (const char *)((cmd)->key.contig.bytes), (cmd)->key.contig.nbytes, ## __VA_ARGS__)
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, ntohs((req)->request.vbucket), (req)->request.opcode, \
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(), 0, mcresp->opcode(), (resp)->rc, (const char *)(resp)->key, (resp)->nkey, \
51
- ## __VA_ARGS__)
52
-
53
- #define TRACE_END_SIMPLE(TGT, mcresp, resp) \
54
- TGT(mcresp->opaque(), 0, mcresp->opcode(), (resp)->rc, (const char *)(resp)->key, (resp)->nkey)
55
-
56
- #define TRACE_GET_BEGIN(req, cmd) \
57
- TRACE(TRACE_BEGIN_COMMON(LIBCOUCHBASE_GET_BEGIN, req, cmd, (cmd)->exptime))
58
-
59
- #define TRACE_GET_END(mcresp, resp) \
60
- TRACE(TRACE_END_COMMON(LIBCOUCHBASE_GET_END, mcresp, resp, \
61
- (const char*)(resp)->value, (resp)->nvalue, (resp)->itmflags, (resp)->cas, \
62
- mcresp->datatype()))
63
-
64
- #define TRACE_UNLOCK_BEGIN(req, cmd) TRACE(TRACE_BEGIN_SIMPLE(LIBCOUCHBASE_UNLOCK_BEGIN, req, cmd))
65
- #define TRACE_UNLOCK_END(mcresp, resp) TRACE(TRACE_END_SIMPLE(LIBCOUCHBASE_UNLOCK_END, mcresp, resp))
66
-
67
- #define TRACE_STORE_BEGIN(req, cmd) \
68
- TRACE(TRACE_BEGIN_COMMON(LIBCOUCHBASE_STORE_BEGIN, req, cmd, \
69
- (const char *)( (cmd)->value.vtype == LCB_KV_IOV ? NULL : (cmd)->value.u_buf.contig.bytes ),\
70
- ( (cmd)->value.vtype == LCB_KV_IOV ? 0 : (cmd)->value.u_buf.contig.nbytes ),\
71
- (cmd)->flags, (cmd)->cas, (req)->request.datatype, (cmd)->exptime))
72
-
73
- #define TRACE_STORE_END(mcresp, resp) TRACE(TRACE_END_COMMON(LIBCOUCHBASE_STORE_END, mcresp, resp, (resp)->cas))
74
-
75
- #define TRACE_ARITHMETIC_BEGIN(req, cmd) \
76
- TRACE(TRACE_BEGIN_COMMON(LIBCOUCHBASE_ARITHMETIC_BEGIN, req, cmd, \
77
- (cmd)->delta, (cmd)->initial, (cmd)->exptime))
78
-
79
- #define TRACE_ARITHMETIC_END(mcresp, resp) \
80
- TRACE(TRACE_END_COMMON(LIBCOUCHBASE_ARITHMETIC_END, mcresp, resp, (resp)->value, (resp)->cas))
81
-
82
- #define TRACE_TOUCH_BEGIN(req, cmd) \
83
- TRACE(TRACE_BEGIN_COMMON(LIBCOUCHBASE_TOUCH_BEGIN, req, cmd, (cmd)->exptime))
84
- #define TRACE_TOUCH_END(mcresp, resp) \
85
- TRACE(TRACE_END_COMMON(LIBCOUCHBASE_TOUCH_END, mcresp, resp, (resp)->cas))
86
-
87
- #define TRACE_REMOVE_BEGIN(req, cmd) TRACE(TRACE_BEGIN_SIMPLE(LIBCOUCHBASE_REMOVE_BEGIN, req, cmd))
88
- #define TRACE_REMOVE_END(mcresp, resp) \
89
- TRACE(TRACE_END_COMMON(LIBCOUCHBASE_REMOVE_END, mcresp, resp, (resp)->cas))
90
-
91
- #define TRACE_OBSERVE_BEGIN(req, body) \
92
- TRACE(LIBCOUCHBASE_OBSERVE_BEGIN(\
93
- (req)->request.opaque, 0, (req)->request.opcode, body, \
94
- ntohl( (req)->request.bodylen) ))
95
-
96
- #define TRACE_OBSERVE_PROGRESS(mcresp, resp) \
97
- TRACE(TRACE_END_COMMON(LIBCOUCHBASE_OBSERVE_PROGRESS,mcresp,resp, \
98
- (resp)->cas, (resp)->status, (resp)->ismaster, (resp)->ttp, (resp)->ttr))
99
-
100
- #define TRACE_OBSERVE_END(mcresp) \
101
- TRACE(LIBCOUCHBASE_OBSERVE_END(mcresp->opaque(), 0, mcresp->opcode(), LCB_SUCCESS))
102
-
103
- #define TRACE_HTTP_BEGIN(req) TRACE(LIBCOUCHBASE_HTTP_BEGIN((req)->url, (req)->nurl, (req)->method))
104
- #define TRACE_HTTP_END(req, rc, resp) TRACE(LIBCOUCHBASE_HTTP_END((req)->url, (req)->nurl, (req)->method, (resp)->rc, (resp)->htstatus
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
+ }