libcouchbase 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (561) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +35 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +24 -0
  8. data/README.md +389 -0
  9. data/Rakefile +75 -0
  10. data/ext/README.md +6 -0
  11. data/ext/Rakefile +20 -0
  12. data/ext/libcouchbase/.gitignore +130 -0
  13. data/ext/libcouchbase/.travis.yml +19 -0
  14. data/ext/libcouchbase/CMakeLists.txt +429 -0
  15. data/ext/libcouchbase/CONTRIBUTING.md +124 -0
  16. data/ext/libcouchbase/LICENSE +202 -0
  17. data/ext/libcouchbase/README.markdown +163 -0
  18. data/ext/libcouchbase/RELEASE_NOTES.markdown +2691 -0
  19. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +27 -0
  20. data/ext/libcouchbase/cmake/Modules/CopyPDB.cmake +42 -0
  21. data/ext/libcouchbase/cmake/Modules/DistScript.cmake +17 -0
  22. data/ext/libcouchbase/cmake/Modules/DownloadLcbDep.cmake +20 -0
  23. data/ext/libcouchbase/cmake/Modules/FindCouchbaseHdrHistogram.cmake +15 -0
  24. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibev.cmake +73 -0
  25. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibevent.cmake +52 -0
  26. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibuv.cmake +56 -0
  27. data/ext/libcouchbase/cmake/Modules/FindCouchbaseSnappy.cmake +11 -0
  28. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +29 -0
  29. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +133 -0
  30. data/ext/libcouchbase/cmake/Modules/GetPlatformCCInfo.cmake +45 -0
  31. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +70 -0
  32. data/ext/libcouchbase/cmake/config-cmake.h.in +60 -0
  33. data/ext/libcouchbase/cmake/configure +357 -0
  34. data/ext/libcouchbase/cmake/defs.mk.in +8 -0
  35. data/ext/libcouchbase/cmake/dtrace-instr-link.pl +38 -0
  36. data/ext/libcouchbase/cmake/source_files.cmake +73 -0
  37. data/ext/libcouchbase/configure.pl +1 -0
  38. data/ext/libcouchbase/contrib/cJSON/cJSON.c +624 -0
  39. data/ext/libcouchbase/contrib/cJSON/cJSON.h +158 -0
  40. data/ext/libcouchbase/contrib/cbsasl/CMakeLists.txt +9 -0
  41. data/ext/libcouchbase/contrib/cbsasl/COPYING +202 -0
  42. data/ext/libcouchbase/contrib/cbsasl/include/cbsasl/cbsasl.h +217 -0
  43. data/ext/libcouchbase/contrib/cbsasl/src/client.c +205 -0
  44. data/ext/libcouchbase/contrib/cbsasl/src/common.c +46 -0
  45. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.c +67 -0
  46. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.h +33 -0
  47. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.c +296 -0
  48. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.h +45 -0
  49. data/ext/libcouchbase/contrib/cbsasl/src/hash.c +573 -0
  50. data/ext/libcouchbase/contrib/cbsasl/src/hash.h +15 -0
  51. data/ext/libcouchbase/contrib/cbsasl/src/util.h +31 -0
  52. data/ext/libcouchbase/contrib/cliopts/CMakeLists.txt +2 -0
  53. data/ext/libcouchbase/contrib/cliopts/cliopts.c +747 -0
  54. data/ext/libcouchbase/contrib/cliopts/cliopts.h +493 -0
  55. data/ext/libcouchbase/contrib/genhash/genhash.c +372 -0
  56. data/ext/libcouchbase/contrib/genhash/genhash.h +235 -0
  57. data/ext/libcouchbase/contrib/gtest-1.7.0/CHANGES +157 -0
  58. data/ext/libcouchbase/contrib/gtest-1.7.0/CMakeLists.txt +252 -0
  59. data/ext/libcouchbase/contrib/gtest-1.7.0/CONTRIBUTORS +37 -0
  60. data/ext/libcouchbase/contrib/gtest-1.7.0/LICENSE +28 -0
  61. data/ext/libcouchbase/contrib/gtest-1.7.0/MINIFY.sh +15 -0
  62. data/ext/libcouchbase/contrib/gtest-1.7.0/README +435 -0
  63. data/ext/libcouchbase/contrib/gtest-1.7.0/cmake/internal_utils.cmake +227 -0
  64. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-death-test.h +294 -0
  65. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-message.h +250 -0
  66. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h +1421 -0
  67. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h.pump +487 -0
  68. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-printers.h +855 -0
  69. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-spi.h +232 -0
  70. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-test-part.h +179 -0
  71. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-typed-test.h +259 -0
  72. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest.h +2291 -0
  73. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_pred_impl.h +358 -0
  74. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_prod.h +58 -0
  75. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-death-test-internal.h +319 -0
  76. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-filepath.h +206 -0
  77. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-internal.h +1158 -0
  78. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-linked_ptr.h +233 -0
  79. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h +5143 -0
  80. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h.pump +301 -0
  81. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util.h +619 -0
  82. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-port.h +1947 -0
  83. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-string.h +167 -0
  84. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h +1012 -0
  85. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h.pump +339 -0
  86. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h +3331 -0
  87. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h.pump +297 -0
  88. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-all.cc +48 -0
  89. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-death-test.cc +1344 -0
  90. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-filepath.cc +382 -0
  91. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-internal-inl.h +1218 -0
  92. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-port.cc +805 -0
  93. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-printers.cc +363 -0
  94. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-test-part.cc +110 -0
  95. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-typed-test.cc +110 -0
  96. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest.cc +5015 -0
  97. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest_main.cc +38 -0
  98. data/ext/libcouchbase/contrib/http_parser/LICENSE-MIT +23 -0
  99. data/ext/libcouchbase/contrib/http_parser/README.md +178 -0
  100. data/ext/libcouchbase/contrib/http_parser/http_parser.c +2060 -0
  101. data/ext/libcouchbase/contrib/http_parser/http_parser.h +321 -0
  102. data/ext/libcouchbase/contrib/jsonsl/LICENSE +20 -0
  103. data/ext/libcouchbase/contrib/jsonsl/jsonsl.c +1452 -0
  104. data/ext/libcouchbase/contrib/jsonsl/jsonsl.h +971 -0
  105. data/ext/libcouchbase/contrib/lcb-jsoncpp/CMakeLists.txt +6 -0
  106. data/ext/libcouchbase/contrib/lcb-jsoncpp/LICENSE +55 -0
  107. data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp-forwards.h +255 -0
  108. data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +4892 -0
  109. data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.h +1961 -0
  110. data/ext/libcouchbase/contrib/snappy/CMakeLists.txt +8 -0
  111. data/ext/libcouchbase/contrib/snappy/COPYING +28 -0
  112. data/ext/libcouchbase/contrib/snappy/snappy-c.cc +90 -0
  113. data/ext/libcouchbase/contrib/snappy/snappy-c.h +138 -0
  114. data/ext/libcouchbase/contrib/snappy/snappy-internal.h +150 -0
  115. data/ext/libcouchbase/contrib/snappy/snappy-lcb-msvc.h +5 -0
  116. data/ext/libcouchbase/contrib/snappy/snappy-sinksource.cc +71 -0
  117. data/ext/libcouchbase/contrib/snappy/snappy-sinksource.h +137 -0
  118. data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.cc +42 -0
  119. data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.h +491 -0
  120. data/ext/libcouchbase/contrib/snappy/snappy-stubs-public.h +98 -0
  121. data/ext/libcouchbase/contrib/snappy/snappy.cc +1307 -0
  122. data/ext/libcouchbase/contrib/snappy/snappy.h +184 -0
  123. data/ext/libcouchbase/contrib/win32-defs/iocpdefs.h +133 -0
  124. data/ext/libcouchbase/contrib/win32-defs/mingwdefs.h +4396 -0
  125. data/ext/libcouchbase/contrib/win32-defs/win_stdint.h +258 -0
  126. data/ext/libcouchbase/example/CMakeLists.txt +37 -0
  127. data/ext/libcouchbase/example/README.markdown +47 -0
  128. data/ext/libcouchbase/example/db/db.c +167 -0
  129. data/ext/libcouchbase/example/db/vb.c +227 -0
  130. data/ext/libcouchbase/example/instancepool/main.cc +102 -0
  131. data/ext/libcouchbase/example/instancepool/pool.cc +102 -0
  132. data/ext/libcouchbase/example/instancepool/pool.h +69 -0
  133. data/ext/libcouchbase/example/libeventdirect/main.c +148 -0
  134. data/ext/libcouchbase/example/mcc/mcc.cc +246 -0
  135. data/ext/libcouchbase/example/minimal/minimal.c +130 -0
  136. data/ext/libcouchbase/example/observe/observe.c +146 -0
  137. data/ext/libcouchbase/example/subdoc/subdoc-multi.cc +132 -0
  138. data/ext/libcouchbase/example/subdoc/subdoc-simple.cc +191 -0
  139. data/ext/libcouchbase/example/tick/tick.c +119 -0
  140. data/ext/libcouchbase/example/views/views-example.cc +83 -0
  141. data/ext/libcouchbase/include/libcouchbase/_cxxwrap.h +150 -0
  142. data/ext/libcouchbase/include/libcouchbase/api-legacy.h +1689 -0
  143. data/ext/libcouchbase/include/libcouchbase/api3.h +2 -0
  144. data/ext/libcouchbase/include/libcouchbase/assert.h +44 -0
  145. data/ext/libcouchbase/include/libcouchbase/cbft.h +109 -0
  146. data/ext/libcouchbase/include/libcouchbase/cntl-private.h +356 -0
  147. data/ext/libcouchbase/include/libcouchbase/cntl.h +937 -0
  148. data/ext/libcouchbase/include/libcouchbase/configuration.h.in +23 -0
  149. data/ext/libcouchbase/include/libcouchbase/couchbase.h +3677 -0
  150. data/ext/libcouchbase/include/libcouchbase/deprecated.h +300 -0
  151. data/ext/libcouchbase/include/libcouchbase/error.h +595 -0
  152. data/ext/libcouchbase/include/libcouchbase/http.h +1 -0
  153. data/ext/libcouchbase/include/libcouchbase/iops.h +1050 -0
  154. data/ext/libcouchbase/include/libcouchbase/ixmgmt.h +263 -0
  155. data/ext/libcouchbase/include/libcouchbase/kvbuf.h +132 -0
  156. data/ext/libcouchbase/include/libcouchbase/n1ql.h +364 -0
  157. data/ext/libcouchbase/include/libcouchbase/pktfwd.h +270 -0
  158. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +367 -0
  159. data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr-inl.c +76 -0
  160. data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr.h +199 -0
  161. data/ext/libcouchbase/include/libcouchbase/subdoc.h +312 -0
  162. data/ext/libcouchbase/include/libcouchbase/sysdefs.h +98 -0
  163. data/ext/libcouchbase/include/libcouchbase/vbucket.h +643 -0
  164. data/ext/libcouchbase/include/libcouchbase/views.h +298 -0
  165. data/ext/libcouchbase/include/libcouchbase/visibility.h +65 -0
  166. data/ext/libcouchbase/include/memcached/COPYING +30 -0
  167. data/ext/libcouchbase/include/memcached/README +10 -0
  168. data/ext/libcouchbase/include/memcached/protocol_binary.h +1916 -0
  169. data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
  170. data/ext/libcouchbase/packaging/README +7 -0
  171. data/ext/libcouchbase/packaging/abicheck/.gitignore +4 -0
  172. data/ext/libcouchbase/packaging/abicheck/Makefile +17 -0
  173. data/ext/libcouchbase/packaging/abicheck/README.md +27 -0
  174. data/ext/libcouchbase/packaging/abicheck/template.xml +3 -0
  175. data/ext/libcouchbase/packaging/deb/compat +1 -0
  176. data/ext/libcouchbase/packaging/deb/control +73 -0
  177. data/ext/libcouchbase/packaging/deb/copyright +10 -0
  178. data/ext/libcouchbase/packaging/deb/libcouchbase-dev.docs +3 -0
  179. data/ext/libcouchbase/packaging/deb/package.mk +31 -0
  180. data/ext/libcouchbase/packaging/deb/rules +46 -0
  181. data/ext/libcouchbase/packaging/deb/source/format +1 -0
  182. data/ext/libcouchbase/packaging/distinfo/README +1 -0
  183. data/ext/libcouchbase/packaging/distinfo/distinfo.cmake.in +4 -0
  184. data/ext/libcouchbase/packaging/dllversion.rc.in +39 -0
  185. data/ext/libcouchbase/packaging/libcouchbase.pc.in +10 -0
  186. data/ext/libcouchbase/packaging/nuget/libcouchbase.autopkg +76 -0
  187. data/ext/libcouchbase/packaging/parse-git-describe.pl +166 -0
  188. data/ext/libcouchbase/packaging/rpm/libcouchbase.spec.in +108 -0
  189. data/ext/libcouchbase/packaging/rpm/package.mk +40 -0
  190. data/ext/libcouchbase/plugins/io/iocp/CMakeLists.txt +9 -0
  191. data/ext/libcouchbase/plugins/io/iocp/iocp_iops.c +466 -0
  192. data/ext/libcouchbase/plugins/io/iocp/iocp_iops.h +217 -0
  193. data/ext/libcouchbase/plugins/io/iocp/iocp_loop.c +295 -0
  194. data/ext/libcouchbase/plugins/io/iocp/iocp_timer.c +79 -0
  195. data/ext/libcouchbase/plugins/io/iocp/iocp_util.c +229 -0
  196. data/ext/libcouchbase/plugins/io/libev/CMakeLists.txt +29 -0
  197. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +65 -0
  198. data/ext/libcouchbase/plugins/io/libev/plugin-libev.c +289 -0
  199. data/ext/libcouchbase/plugins/io/libevent/CMakeLists.txt +29 -0
  200. data/ext/libcouchbase/plugins/io/libevent/libevent_io_opts.h +67 -0
  201. data/ext/libcouchbase/plugins/io/libevent/plugin-libevent.c +292 -0
  202. data/ext/libcouchbase/plugins/io/libuv/CMakeLists.txt +42 -0
  203. data/ext/libcouchbase/plugins/io/libuv/libuv_compat.h +212 -0
  204. data/ext/libcouchbase/plugins/io/libuv/libuv_io_opts.h +118 -0
  205. data/ext/libcouchbase/plugins/io/libuv/plugin-internal.h +148 -0
  206. data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +648 -0
  207. data/ext/libcouchbase/plugins/io/select/CMakeLists.txt +11 -0
  208. data/ext/libcouchbase/plugins/io/select/plugin-select.c +448 -0
  209. data/ext/libcouchbase/plugins/io/select/select_io_opts.h +39 -0
  210. data/ext/libcouchbase/src/README.md +103 -0
  211. data/ext/libcouchbase/src/aspend.h +106 -0
  212. data/ext/libcouchbase/src/auth.cc +74 -0
  213. data/ext/libcouchbase/src/auth.h +54 -0
  214. data/ext/libcouchbase/src/bootstrap.c +269 -0
  215. data/ext/libcouchbase/src/bootstrap.h +129 -0
  216. data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +495 -0
  217. data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
  218. data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
  219. data/ext/libcouchbase/src/bucketconfig/bc_http.h +82 -0
  220. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
  221. data/ext/libcouchbase/src/bucketconfig/clconfig.h +681 -0
  222. data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
  223. data/ext/libcouchbase/src/callbacks.c +378 -0
  224. data/ext/libcouchbase/src/cbft.cc +210 -0
  225. data/ext/libcouchbase/src/cntl.cc +847 -0
  226. data/ext/libcouchbase/src/config_static.h +159 -0
  227. data/ext/libcouchbase/src/connspec.cc +462 -0
  228. data/ext/libcouchbase/src/connspec.h +105 -0
  229. data/ext/libcouchbase/src/ctx-log-inl.h +27 -0
  230. data/ext/libcouchbase/src/dump.c +98 -0
  231. data/ext/libcouchbase/src/getconfig.c +100 -0
  232. data/ext/libcouchbase/src/gethrtime.c +109 -0
  233. data/ext/libcouchbase/src/handler.c +922 -0
  234. data/ext/libcouchbase/src/hashset.c +164 -0
  235. data/ext/libcouchbase/src/hashset.h +86 -0
  236. data/ext/libcouchbase/src/hashtable.c +75 -0
  237. data/ext/libcouchbase/src/hdr_timings.c +92 -0
  238. data/ext/libcouchbase/src/hostlist.cc +301 -0
  239. data/ext/libcouchbase/src/hostlist.h +171 -0
  240. data/ext/libcouchbase/src/http/http-priv.h +307 -0
  241. data/ext/libcouchbase/src/http/http.cc +633 -0
  242. data/ext/libcouchbase/src/http/http.h +34 -0
  243. data/ext/libcouchbase/src/http/http_io.cc +307 -0
  244. data/ext/libcouchbase/src/instance.cc +722 -0
  245. data/ext/libcouchbase/src/internal.h +244 -0
  246. data/ext/libcouchbase/src/iofactory.c +575 -0
  247. data/ext/libcouchbase/src/jsparse/parser.cc +519 -0
  248. data/ext/libcouchbase/src/jsparse/parser.h +173 -0
  249. data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
  250. data/ext/libcouchbase/src/lcbht/lcbht.h +199 -0
  251. data/ext/libcouchbase/src/lcbio/connect.c +557 -0
  252. data/ext/libcouchbase/src/lcbio/connect.h +364 -0
  253. data/ext/libcouchbase/src/lcbio/ctx.c +611 -0
  254. data/ext/libcouchbase/src/lcbio/ctx.h +405 -0
  255. data/ext/libcouchbase/src/lcbio/iotable.c +290 -0
  256. data/ext/libcouchbase/src/lcbio/iotable.h +84 -0
  257. data/ext/libcouchbase/src/lcbio/ioutils.c +350 -0
  258. data/ext/libcouchbase/src/lcbio/ioutils.h +203 -0
  259. data/ext/libcouchbase/src/lcbio/lcbio.h +51 -0
  260. data/ext/libcouchbase/src/lcbio/manager.c +584 -0
  261. data/ext/libcouchbase/src/lcbio/manager.h +156 -0
  262. data/ext/libcouchbase/src/lcbio/protoctx.c +84 -0
  263. data/ext/libcouchbase/src/lcbio/rw-inl.h +115 -0
  264. data/ext/libcouchbase/src/lcbio/ssl.h +149 -0
  265. data/ext/libcouchbase/src/lcbio/timer-ng.h +179 -0
  266. data/ext/libcouchbase/src/lcbio/timer.c +132 -0
  267. data/ext/libcouchbase/src/legacy.c +430 -0
  268. data/ext/libcouchbase/src/list.c +144 -0
  269. data/ext/libcouchbase/src/list.h +127 -0
  270. data/ext/libcouchbase/src/logging.c +244 -0
  271. data/ext/libcouchbase/src/logging.h +86 -0
  272. data/ext/libcouchbase/src/mc/compress.c +90 -0
  273. data/ext/libcouchbase/src/mc/compress.h +61 -0
  274. data/ext/libcouchbase/src/mc/forward.c +186 -0
  275. data/ext/libcouchbase/src/mc/forward.h +90 -0
  276. data/ext/libcouchbase/src/mc/iovcursor-inl.h +279 -0
  277. data/ext/libcouchbase/src/mc/iovcursor.h +66 -0
  278. data/ext/libcouchbase/src/mc/mcreq-flush-inl.h +111 -0
  279. data/ext/libcouchbase/src/mc/mcreq.c +954 -0
  280. data/ext/libcouchbase/src/mc/mcreq.h +977 -0
  281. data/ext/libcouchbase/src/mcserver/mcserver.c +784 -0
  282. data/ext/libcouchbase/src/mcserver/mcserver.h +121 -0
  283. data/ext/libcouchbase/src/mcserver/negotiate.c +656 -0
  284. data/ext/libcouchbase/src/mcserver/negotiate.h +119 -0
  285. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +860 -0
  286. data/ext/libcouchbase/src/n1ql/n1ql-internal.h +22 -0
  287. data/ext/libcouchbase/src/n1ql/n1ql.cc +729 -0
  288. data/ext/libcouchbase/src/n1ql/params.cc +215 -0
  289. data/ext/libcouchbase/src/netbuf/netbuf-defs.h +89 -0
  290. data/ext/libcouchbase/src/netbuf/netbuf-mblock.h +235 -0
  291. data/ext/libcouchbase/src/netbuf/netbuf.c +929 -0
  292. data/ext/libcouchbase/src/netbuf/netbuf.h +452 -0
  293. data/ext/libcouchbase/src/newconfig.c +385 -0
  294. data/ext/libcouchbase/src/nodeinfo.cc +194 -0
  295. data/ext/libcouchbase/src/operations/cbflush.c +71 -0
  296. data/ext/libcouchbase/src/operations/counter.c +116 -0
  297. data/ext/libcouchbase/src/operations/durability-cas.c +224 -0
  298. data/ext/libcouchbase/src/operations/durability-seqno.c +157 -0
  299. data/ext/libcouchbase/src/operations/durability.c +668 -0
  300. data/ext/libcouchbase/src/operations/durability_internal.h +199 -0
  301. data/ext/libcouchbase/src/operations/get.c +409 -0
  302. data/ext/libcouchbase/src/operations/observe-seqno.c +96 -0
  303. data/ext/libcouchbase/src/operations/observe.c +340 -0
  304. data/ext/libcouchbase/src/operations/pktfwd.c +86 -0
  305. data/ext/libcouchbase/src/operations/remove.c +83 -0
  306. data/ext/libcouchbase/src/operations/stats.c +461 -0
  307. data/ext/libcouchbase/src/operations/store.c +360 -0
  308. data/ext/libcouchbase/src/operations/subdoc.cc +510 -0
  309. data/ext/libcouchbase/src/operations/touch.c +81 -0
  310. data/ext/libcouchbase/src/packetutils.c +60 -0
  311. data/ext/libcouchbase/src/packetutils.h +147 -0
  312. data/ext/libcouchbase/src/probes.d +211 -0
  313. data/ext/libcouchbase/src/rdb/bigalloc.c +225 -0
  314. data/ext/libcouchbase/src/rdb/bigalloc.h +73 -0
  315. data/ext/libcouchbase/src/rdb/chunkalloc.c +174 -0
  316. data/ext/libcouchbase/src/rdb/libcalloc.c +94 -0
  317. data/ext/libcouchbase/src/rdb/rope.c +419 -0
  318. data/ext/libcouchbase/src/rdb/rope.h +488 -0
  319. data/ext/libcouchbase/src/retrychk.c +113 -0
  320. data/ext/libcouchbase/src/retryq.c +424 -0
  321. data/ext/libcouchbase/src/retryq.h +157 -0
  322. data/ext/libcouchbase/src/ringbuffer.c +442 -0
  323. data/ext/libcouchbase/src/ringbuffer.h +100 -0
  324. data/ext/libcouchbase/src/settings.c +95 -0
  325. data/ext/libcouchbase/src/settings.h +188 -0
  326. data/ext/libcouchbase/src/simplestring.c +211 -0
  327. data/ext/libcouchbase/src/simplestring.h +228 -0
  328. data/ext/libcouchbase/src/sllist-inl.h +197 -0
  329. data/ext/libcouchbase/src/sllist.h +76 -0
  330. data/ext/libcouchbase/src/ssl/CMakeLists.txt +23 -0
  331. data/ext/libcouchbase/src/ssl/ssl_c.c +415 -0
  332. data/ext/libcouchbase/src/ssl/ssl_common.c +454 -0
  333. data/ext/libcouchbase/src/ssl/ssl_e.c +408 -0
  334. data/ext/libcouchbase/src/ssl/ssl_iot_common.h +180 -0
  335. data/ext/libcouchbase/src/ssobuf.h +82 -0
  336. data/ext/libcouchbase/src/strcodecs/base64.c +123 -0
  337. data/ext/libcouchbase/src/strcodecs/strcodecs.h +285 -0
  338. data/ext/libcouchbase/src/timings.c +208 -0
  339. data/ext/libcouchbase/src/trace.h +105 -0
  340. data/ext/libcouchbase/src/utilities.c +171 -0
  341. data/ext/libcouchbase/src/vbucket/CMakeLists.txt +2 -0
  342. data/ext/libcouchbase/src/vbucket/aliases.h +35 -0
  343. data/ext/libcouchbase/src/vbucket/crc32.h +83 -0
  344. data/ext/libcouchbase/src/vbucket/hash.h +30 -0
  345. data/ext/libcouchbase/src/vbucket/json-inl.h +112 -0
  346. data/ext/libcouchbase/src/vbucket/ketama.c +66 -0
  347. data/ext/libcouchbase/src/vbucket/rfc1321/global.h +32 -0
  348. data/ext/libcouchbase/src/vbucket/rfc1321/md5.h +35 -0
  349. data/ext/libcouchbase/src/vbucket/rfc1321/md5c-inl.h +335 -0
  350. data/ext/libcouchbase/src/vbucket/vbucket.c +1543 -0
  351. data/ext/libcouchbase/src/views/docreq.c +194 -0
  352. data/ext/libcouchbase/src/views/docreq.h +83 -0
  353. data/ext/libcouchbase/src/views/viewreq.c +358 -0
  354. data/ext/libcouchbase/src/views/viewreq.h +36 -0
  355. data/ext/libcouchbase/src/wait.c +161 -0
  356. data/ext/libcouchbase/tests/CMakeLists.txt +140 -0
  357. data/ext/libcouchbase/tests/basic/t_base64.cc +81 -0
  358. data/ext/libcouchbase/tests/basic/t_ccbc103.cc +95 -0
  359. data/ext/libcouchbase/tests/basic/t_connstr.cc +404 -0
  360. data/ext/libcouchbase/tests/basic/t_creds.cc +32 -0
  361. data/ext/libcouchbase/tests/basic/t_ctlcodes.cc +92 -0
  362. data/ext/libcouchbase/tests/basic/t_hashset.cc +262 -0
  363. data/ext/libcouchbase/tests/basic/t_host.cc +198 -0
  364. data/ext/libcouchbase/tests/basic/t_jsparse.cc +137 -0
  365. data/ext/libcouchbase/tests/basic/t_jsparse.h +589 -0
  366. data/ext/libcouchbase/tests/basic/t_list.cc +155 -0
  367. data/ext/libcouchbase/tests/basic/t_logger.cc +65 -0
  368. data/ext/libcouchbase/tests/basic/t_misc.cc +24 -0
  369. data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +18 -0
  370. data/ext/libcouchbase/tests/basic/t_netbuf.cc +446 -0
  371. data/ext/libcouchbase/tests/basic/t_packet.cc +222 -0
  372. data/ext/libcouchbase/tests/basic/t_ringbuffer.cc +278 -0
  373. data/ext/libcouchbase/tests/basic/t_slist.cc +429 -0
  374. data/ext/libcouchbase/tests/basic/t_strerror.cc +64 -0
  375. data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
  376. data/ext/libcouchbase/tests/basic/t_urlencode.cc +132 -0
  377. data/ext/libcouchbase/tests/check-all.cc +608 -0
  378. data/ext/libcouchbase/tests/htparse/t_basic.cc +193 -0
  379. data/ext/libcouchbase/tests/ioserver/connection.cc +166 -0
  380. data/ext/libcouchbase/tests/ioserver/future.cc +50 -0
  381. data/ext/libcouchbase/tests/ioserver/ioserver.cc +104 -0
  382. data/ext/libcouchbase/tests/ioserver/ioserver.h +478 -0
  383. data/ext/libcouchbase/tests/ioserver/socket.cc +88 -0
  384. data/ext/libcouchbase/tests/ioserver/ssl_connection.cc +145 -0
  385. data/ext/libcouchbase/tests/ioserver/threads-pthreads.cc +119 -0
  386. data/ext/libcouchbase/tests/ioserver/threads-win32.cc +117 -0
  387. data/ext/libcouchbase/tests/ioserver/threads.h +66 -0
  388. data/ext/libcouchbase/tests/iotests/iotests.h +15 -0
  389. data/ext/libcouchbase/tests/iotests/mock-environment.cc +524 -0
  390. data/ext/libcouchbase/tests/iotests/mock-environment.h +385 -0
  391. data/ext/libcouchbase/tests/iotests/mock-unit-test.cc +67 -0
  392. data/ext/libcouchbase/tests/iotests/mock-unit-test.h +61 -0
  393. data/ext/libcouchbase/tests/iotests/serverparams.h +76 -0
  394. data/ext/libcouchbase/tests/iotests/t_arithmetic.cc +143 -0
  395. data/ext/libcouchbase/tests/iotests/t_behavior.cc +226 -0
  396. data/ext/libcouchbase/tests/iotests/t_configcache.cc +117 -0
  397. data/ext/libcouchbase/tests/iotests/t_confmon.cc +241 -0
  398. data/ext/libcouchbase/tests/iotests/t_durability.cc +1059 -0
  399. data/ext/libcouchbase/tests/iotests/t_forward.cc +110 -0
  400. data/ext/libcouchbase/tests/iotests/t_get.cc +512 -0
  401. data/ext/libcouchbase/tests/iotests/t_http.cc +438 -0
  402. data/ext/libcouchbase/tests/iotests/t_iops.cc +175 -0
  403. data/ext/libcouchbase/tests/iotests/t_lock.cc +275 -0
  404. data/ext/libcouchbase/tests/iotests/t_misc.cc +713 -0
  405. data/ext/libcouchbase/tests/iotests/t_mutate.cc +609 -0
  406. data/ext/libcouchbase/tests/iotests/t_n1ql.cc +270 -0
  407. data/ext/libcouchbase/tests/iotests/t_netfail.cc +654 -0
  408. data/ext/libcouchbase/tests/iotests/t_obseqno.cc +157 -0
  409. data/ext/libcouchbase/tests/iotests/t_regression.cc +321 -0
  410. data/ext/libcouchbase/tests/iotests/t_sched.cc +88 -0
  411. data/ext/libcouchbase/tests/iotests/t_serverops.cc +230 -0
  412. data/ext/libcouchbase/tests/iotests/t_smoke.cc +528 -0
  413. data/ext/libcouchbase/tests/iotests/t_subdoc.cc +822 -0
  414. data/ext/libcouchbase/tests/iotests/t_syncmode.cc +64 -0
  415. data/ext/libcouchbase/tests/iotests/t_views.cc +405 -0
  416. data/ext/libcouchbase/tests/iotests/testutil.cc +250 -0
  417. data/ext/libcouchbase/tests/iotests/testutil.h +163 -0
  418. data/ext/libcouchbase/tests/mc/mctest.h +119 -0
  419. data/ext/libcouchbase/tests/mc/pktmaker.h +101 -0
  420. data/ext/libcouchbase/tests/mc/t_alloc.cc +269 -0
  421. data/ext/libcouchbase/tests/mc/t_context.cc +100 -0
  422. data/ext/libcouchbase/tests/mc/t_flush.cc +185 -0
  423. data/ext/libcouchbase/tests/mc/t_forward.cc +239 -0
  424. data/ext/libcouchbase/tests/mc/t_ioflush.cc +102 -0
  425. data/ext/libcouchbase/tests/mc/t_iovcursor.cc +173 -0
  426. data/ext/libcouchbase/tests/mocksupport/procutil.c +305 -0
  427. data/ext/libcouchbase/tests/mocksupport/procutil.h +89 -0
  428. data/ext/libcouchbase/tests/mocksupport/server.c +391 -0
  429. data/ext/libcouchbase/tests/mocksupport/server.h +72 -0
  430. data/ext/libcouchbase/tests/mocksupport/timeout.c +69 -0
  431. data/ext/libcouchbase/tests/nonio_tests.cc +23 -0
  432. data/ext/libcouchbase/tests/rdb/rdbtest.h +133 -0
  433. data/ext/libcouchbase/tests/rdb/t_basic.cc +128 -0
  434. data/ext/libcouchbase/tests/rdb/t_bigalloc.cc +93 -0
  435. data/ext/libcouchbase/tests/rdb/t_refs.cc +112 -0
  436. data/ext/libcouchbase/tests/socktests/socktest.cc +347 -0
  437. data/ext/libcouchbase/tests/socktests/socktest.h +448 -0
  438. data/ext/libcouchbase/tests/socktests/t_basic.cc +143 -0
  439. data/ext/libcouchbase/tests/socktests/t_ctx.cc +73 -0
  440. data/ext/libcouchbase/tests/socktests/t_manager.cc +179 -0
  441. data/ext/libcouchbase/tests/socktests/t_putex.cc +256 -0
  442. data/ext/libcouchbase/tests/socktests/t_read.cc +187 -0
  443. data/ext/libcouchbase/tests/socktests/t_reentrant.cc +143 -0
  444. data/ext/libcouchbase/tests/socktests/t_ssl.cc +80 -0
  445. data/ext/libcouchbase/tests/socktests/t_write.cc +95 -0
  446. data/ext/libcouchbase/tests/start_mock.bat +15 -0
  447. data/ext/libcouchbase/tests/start_mock.sh +42 -0
  448. data/ext/libcouchbase/tests/unit_tests.cc +43 -0
  449. data/ext/libcouchbase/tests/vbucket/confdata/bad.json +101 -0
  450. data/ext/libcouchbase/tests/vbucket/confdata/full_25.json +363 -0
  451. data/ext/libcouchbase/tests/vbucket/confdata/memd_25.json +90 -0
  452. data/ext/libcouchbase/tests/vbucket/confdata/memd_30.json +1 -0
  453. data/ext/libcouchbase/tests/vbucket/confdata/memd_45.json +1 -0
  454. data/ext/libcouchbase/tests/vbucket/confdata/terse_25.json +291 -0
  455. data/ext/libcouchbase/tests/vbucket/confdata/terse_30.json +1 -0
  456. data/ext/libcouchbase/tests/vbucket/t_config.cc +341 -0
  457. data/ext/libcouchbase/tools/CMakeLists.txt +51 -0
  458. data/ext/libcouchbase/tools/cbc-handlers.h +462 -0
  459. data/ext/libcouchbase/tools/cbc-n1qlback.cc +439 -0
  460. data/ext/libcouchbase/tools/cbc-pillowfight.cc +822 -0
  461. data/ext/libcouchbase/tools/cbc.cc +1541 -0
  462. data/ext/libcouchbase/tools/common/histogram.cc +43 -0
  463. data/ext/libcouchbase/tools/common/histogram.h +23 -0
  464. data/ext/libcouchbase/tools/common/my_inttypes.h +22 -0
  465. data/ext/libcouchbase/tools/common/options.cc +420 -0
  466. data/ext/libcouchbase/tools/common/options.h +81 -0
  467. data/ext/libcouchbase/tools/docgen/docgen.h +469 -0
  468. data/ext/libcouchbase/tools/docgen/loc.h +210 -0
  469. data/ext/libcouchbase/tools/docgen/placeholders.h +211 -0
  470. data/ext/libcouchbase/tools/docgen/seqgen.h +94 -0
  471. data/lib/libcouchbase.rb +36 -0
  472. data/lib/libcouchbase/bucket.rb +819 -0
  473. data/lib/libcouchbase/callbacks.rb +72 -0
  474. data/lib/libcouchbase/connection.rb +790 -0
  475. data/lib/libcouchbase/design_docs.rb +86 -0
  476. data/lib/libcouchbase/error.rb +68 -0
  477. data/lib/libcouchbase/ext/libcouchbase.rb +1135 -0
  478. data/lib/libcouchbase/ext/libcouchbase/cmdbase.rb +23 -0
  479. data/lib/libcouchbase/ext/libcouchbase/cmdcounter.rb +36 -0
  480. data/lib/libcouchbase/ext/libcouchbase/cmdendure.rb +26 -0
  481. data/lib/libcouchbase/ext/libcouchbase/cmdfts.rb +24 -0
  482. data/lib/libcouchbase/ext/libcouchbase/cmdget.rb +30 -0
  483. data/lib/libcouchbase/ext/libcouchbase/cmdgetreplica.rb +49 -0
  484. data/lib/libcouchbase/ext/libcouchbase/cmdhttp.rb +58 -0
  485. data/lib/libcouchbase/ext/libcouchbase/cmdn1ql.rb +40 -0
  486. data/lib/libcouchbase/ext/libcouchbase/cmdobseqno.rb +33 -0
  487. data/lib/libcouchbase/ext/libcouchbase/cmdobserve.rb +30 -0
  488. data/lib/libcouchbase/ext/libcouchbase/cmdstore.rb +40 -0
  489. data/lib/libcouchbase/ext/libcouchbase/cmdstoredur.rb +45 -0
  490. data/lib/libcouchbase/ext/libcouchbase/cmdsubdoc.rb +49 -0
  491. data/lib/libcouchbase/ext/libcouchbase/cmdverbosity.rb +29 -0
  492. data/lib/libcouchbase/ext/libcouchbase/cmdviewquery.rb +61 -0
  493. data/lib/libcouchbase/ext/libcouchbase/contigbuf.rb +14 -0
  494. data/lib/libcouchbase/ext/libcouchbase/create_st.rb +15 -0
  495. data/lib/libcouchbase/ext/libcouchbase/create_st0.rb +23 -0
  496. data/lib/libcouchbase/ext/libcouchbase/create_st1.rb +26 -0
  497. data/lib/libcouchbase/ext/libcouchbase/create_st2.rb +32 -0
  498. data/lib/libcouchbase/ext/libcouchbase/create_st3.rb +26 -0
  499. data/lib/libcouchbase/ext/libcouchbase/crst_u.rb +20 -0
  500. data/lib/libcouchbase/ext/libcouchbase/durability_opts_st_v.rb +11 -0
  501. data/lib/libcouchbase/ext/libcouchbase/durability_opts_t.rb +14 -0
  502. data/lib/libcouchbase/ext/libcouchbase/durabilityopt_sv0.rb +63 -0
  503. data/lib/libcouchbase/ext/libcouchbase/enums.rb +991 -0
  504. data/lib/libcouchbase/ext/libcouchbase/fragbuf.rb +18 -0
  505. data/lib/libcouchbase/ext/libcouchbase/ftshandle.rb +7 -0
  506. data/lib/libcouchbase/ext/libcouchbase/histogram.rb +34 -0
  507. data/lib/libcouchbase/ext/libcouchbase/http_request_t.rb +7 -0
  508. data/lib/libcouchbase/ext/libcouchbase/keybuf.rb +20 -0
  509. data/lib/libcouchbase/ext/libcouchbase/multicmd_ctx.rb +30 -0
  510. data/lib/libcouchbase/ext/libcouchbase/mutation_token.rb +17 -0
  511. data/lib/libcouchbase/ext/libcouchbase/n1qlhandle.rb +7 -0
  512. data/lib/libcouchbase/ext/libcouchbase/n1qlparams.rb +7 -0
  513. data/lib/libcouchbase/ext/libcouchbase/respbase.rb +29 -0
  514. data/lib/libcouchbase/ext/libcouchbase/respcounter.rb +32 -0
  515. data/lib/libcouchbase/ext/libcouchbase/respendure.rb +49 -0
  516. data/lib/libcouchbase/ext/libcouchbase/respfts.rb +40 -0
  517. data/lib/libcouchbase/ext/libcouchbase/respget.rb +44 -0
  518. data/lib/libcouchbase/ext/libcouchbase/resphttp.rb +48 -0
  519. data/lib/libcouchbase/ext/libcouchbase/respmcversion.rb +38 -0
  520. data/lib/libcouchbase/ext/libcouchbase/respn1ql.rb +41 -0
  521. data/lib/libcouchbase/ext/libcouchbase/respobseqno.rb +52 -0
  522. data/lib/libcouchbase/ext/libcouchbase/respobserve.rb +41 -0
  523. data/lib/libcouchbase/ext/libcouchbase/respserverbase.rb +32 -0
  524. data/lib/libcouchbase/ext/libcouchbase/respstats.rb +38 -0
  525. data/lib/libcouchbase/ext/libcouchbase/respstore.rb +32 -0
  526. data/lib/libcouchbase/ext/libcouchbase/respstoredur.rb +38 -0
  527. data/lib/libcouchbase/ext/libcouchbase/respsubdoc.rb +35 -0
  528. data/lib/libcouchbase/ext/libcouchbase/respviewquery.rb +67 -0
  529. data/lib/libcouchbase/ext/libcouchbase/sdentry.rb +22 -0
  530. data/lib/libcouchbase/ext/libcouchbase/sdspec.rb +26 -0
  531. data/lib/libcouchbase/ext/libcouchbase/t.rb +7 -0
  532. data/lib/libcouchbase/ext/libcouchbase/valbuf.rb +22 -0
  533. data/lib/libcouchbase/ext/libcouchbase/valbuf_u_buf.rb +14 -0
  534. data/lib/libcouchbase/ext/libcouchbase/viewhandle.rb +7 -0
  535. data/lib/libcouchbase/ext/libcouchbase_iocp.rb +26 -0
  536. data/lib/libcouchbase/ext/libcouchbase_libuv.rb +18 -0
  537. data/lib/libcouchbase/ext/tasks.rb +87 -0
  538. data/lib/libcouchbase/n1ql.rb +73 -0
  539. data/lib/libcouchbase/query_full_text.rb +147 -0
  540. data/lib/libcouchbase/query_n1ql.rb +121 -0
  541. data/lib/libcouchbase/query_view.rb +129 -0
  542. data/lib/libcouchbase/results_fiber.rb +262 -0
  543. data/lib/libcouchbase/results_native.rb +211 -0
  544. data/lib/libcouchbase/version.rb +5 -0
  545. data/libcouchbase.gemspec +61 -0
  546. data/spec/bucket_spec.rb +270 -0
  547. data/spec/connection_spec.rb +277 -0
  548. data/spec/design_docs_spec.rb +23 -0
  549. data/spec/error_spec.rb +26 -0
  550. data/spec/fts_spec.rb +129 -0
  551. data/spec/n1ql_spec.rb +201 -0
  552. data/spec/results_libuv_spec.rb +229 -0
  553. data/spec/results_native_spec.rb +259 -0
  554. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/design.json +1 -0
  555. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/data-0000.cbb +0 -0
  556. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/failover.json +1 -0
  557. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/meta.json +1 -0
  558. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/seqno.json +1 -0
  559. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/snapshot_markers.json +1 -0
  560. data/spec/view_spec.rb +195 -0
  561. metadata +775 -0
@@ -0,0 +1,23 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2010-2012 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
+ #ifndef LIBCOUCHBASE_CONFIGURATION_H
19
+ #define LIBCOUCHBASE_CONFIGURATION_H 1
20
+ #define LCB_VERSION_STRING "@LCB_VERSION@"
21
+ #define LCB_VERSION @LCB_VERSION_HEX@
22
+ #define LCB_VERSION_CHANGESET "@LCB_VERSION_CHANGESET@"
23
+ #endif
@@ -0,0 +1,3677 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2010-2012 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
+ #ifndef LIBCOUCHBASE_COUCHBASE_H
19
+ #define LIBCOUCHBASE_COUCHBASE_H 1
20
+
21
+ /**
22
+ * @file
23
+ * Main header file for Couchbase
24
+ */
25
+
26
+ #define LCB_CONFIG_MCD_PORT 11210
27
+ #define LCB_CONFIG_MCD_SSL_PORT 11207
28
+ #define LCB_CONFIG_HTTP_PORT 8091
29
+ #define LCB_CONFIG_HTTP_SSL_PORT 18091
30
+ #define LCB_CONFIG_MCCOMPAT_PORT 11211
31
+
32
+ struct lcb_st;
33
+
34
+ /**
35
+ * @ingroup lcb-init
36
+ * Library handle representing a connection to a data bucket. The contents
37
+ * of this structure are opaque.
38
+ * @see lcb_create
39
+ * @see lcb_destroy
40
+ */
41
+ typedef struct lcb_st *lcb_t;
42
+ struct lcb_http_request_st;
43
+ typedef struct lcb_http_request_st *lcb_http_request_t;
44
+
45
+ #include <stddef.h>
46
+ #include <time.h>
47
+ #include <stdarg.h>
48
+ #include <stdio.h>
49
+ #include <libcouchbase/sysdefs.h>
50
+ #include <libcouchbase/assert.h>
51
+ #include <libcouchbase/visibility.h>
52
+ #include <libcouchbase/error.h>
53
+ #include <libcouchbase/iops.h>
54
+ #include <libcouchbase/http.h>
55
+ #include <libcouchbase/configuration.h>
56
+ #include <libcouchbase/kvbuf.h>
57
+ #include <libcouchbase/_cxxwrap.h>
58
+
59
+ #ifdef __cplusplus
60
+ extern "C"{
61
+ #endif
62
+
63
+ typedef lcb_U8 lcb_datatype_t;
64
+ typedef lcb_U32 lcb_USECS;
65
+
66
+
67
+ /******************************************************************************
68
+ ******************************************************************************
69
+ ******************************************************************************
70
+ ** INITIALIZATION **
71
+ ******************************************************************************
72
+ ******************************************************************************
73
+ ******************************************************************************/
74
+
75
+ /**
76
+ * @ingroup lcb-public-api
77
+ * @defgroup lcb-init Initialization
78
+ *
79
+ * @details
80
+ *
81
+ * To communicate with a Couchbase cluster, a new library handle instance is
82
+ * created in the form of an lcb_t. To create such an object, the lcb_create()
83
+ * function is called, passing it a structure of type lcb_create_st. The structure
84
+ * acts as a container for a union of other structures which are extended
85
+ * as more features are added. This container is forwards and backwards
86
+ * compatible, meaning that if the structure is extended, you code and application
87
+ * will still function if using an older version of the structure. The current
88
+ * sub-field of the lcb_create_st structure is the `v3` field.
89
+ *
90
+ * Connecting to the cluster involes the client knowing the necessary
91
+ * information needed to actually locate its services and connect to it.
92
+ *
93
+ * A connection specification consists of:
94
+ *
95
+ * 1. One or more hosts which comprise the cluster
96
+ * 2. The name of the bucket to access and perform operations on
97
+ * 3. The credentials of the bucket
98
+ *
99
+ * All these options are specified within the form of a URI in the form of
100
+ *
101
+ * `couchbase://$HOSTS/$BUCKET?$OPTIONS`
102
+ *
103
+ * @note
104
+ * If any of the fields (hosts, bucket, options) contain the `/` character then
105
+ * it _must_ be url-encoded; thus a bucket named `foo/bar` would be specified
106
+ * as `couchbase:///foo%2Fbar`
107
+ *
108
+ * @par Hosts
109
+ *
110
+ * In the most typical use case, you would specify a list of several hostnames
111
+ * delimited by a comma (`,`); each host specified should be a member of the
112
+ * cluster. The library will use this list to initially connect to the cluster.
113
+ *
114
+ * Note that it is not necessary to specify _all_ the nodes of the cluster as in
115
+ * a normal situation the library will only initially connect to one of the nodes.
116
+ * Passing multiple nodes increases the chance of a connection succeeding even
117
+ * if some of the nodes are currently down. Once connected to the cluster, the
118
+ * client will update itself with the other nodes actually found within the
119
+ * cluster and discard the list passed to it
120
+ *
121
+ * You can specify multiple hosts like so:
122
+ *
123
+ * `couchbase://foo.com,bar.com,baz.com`
124
+ *
125
+ * Or a single host:
126
+ *
127
+ * `couchbase://localhost`
128
+ *
129
+ * #### Specifying Ports and Protocol Options
130
+ *
131
+ * The default `couchbase://` scheme will assume all hosts and/or ports
132
+ * specify the _memcached_ port. If no port is specified, it is assumed
133
+ * that the port is _11210). For more extended options there are additional
134
+ * schemes available:
135
+ *
136
+ * * `couchbases://` - Will assume all ports refer to the SSL-enabled memcached
137
+ * ports. This setting implicitly enables SSL on the instance as well. If no
138
+ * ports are provided for the hosts, the implicit port for each host will be
139
+ * _11207_.
140
+ *
141
+ * * `http://` - Will assume all ports refer to the HTTP REST API ports used
142
+ * by Couchbase 2.2 and lower. These are also used when connecting to a
143
+ * memcached bucket. If no port is specified it will be assumed the port is
144
+ * _8091_.
145
+ *
146
+ * ### Bucket
147
+ *
148
+ * A bucket may be specified by using the optional _path_ component of the URI
149
+ * For protected buckets a password will still need to be supplied out of band.
150
+ *
151
+ * * `couchbase://1.1.1.1,2.2.2.2,3.3.3.3/users` - Connect to the `users`
152
+ * bucket.
153
+ *
154
+ * ### Options
155
+ *
156
+ * @warning The key-value options here are considered to be a volatile interface
157
+ * as their names may change.
158
+ *
159
+ * Options can be specified as the _query_ part of the connection string,
160
+ * for example:
161
+ *
162
+ * `couchbase://cbnode.net/beer?operation_timeout=10000000`.
163
+ *
164
+ * Options may either be appropriate _key_ parameters for lcb_cntl_string()
165
+ * or one of the following:
166
+ *
167
+ * * `boostrap_on` - specify bootstrap protocols. Values can be `http` to force
168
+ * old-style bootstrap mode for legacy clusters, `cccp` to force bootstrap
169
+ * over the memcached port (For clusters 2.5 and above), or `all` to try with
170
+ * _cccp_ and revert to _http_
171
+ *
172
+ * * `certpath` - Specify the path (on the local filesystem) to the server's
173
+ * SSL certificate. Only applicable if SSL is being used (i.e. the scheme is
174
+ * `couchbases`)
175
+ *
176
+ * ### Bucket Identification and Credentials
177
+ *
178
+ * The most common settings you will wish to modify are the bucket name
179
+ * and the credentials field (`user` and `passwd`). If a
180
+ * `bucket` is not specified it will revert to the `default` bucket (i.e. the
181
+ * bucket which is created when Couchbase Server is installed).
182
+ *
183
+ * The `user` and `passwd` fields authenticate for the bucket. This is only
184
+ * needed if you have configured your bucket to employ SASL auth. You can tell
185
+ * if the bucket has been configured with SASL auth by
186
+ *
187
+ * 1. Logging into the Couchbase Administration Console
188
+ * 2. Going to the _Data Buckets_ tab
189
+ * 3. Locate the row for your bucket
190
+ * 4. Expand the row into the detailed view (by clicking on the arrow at the
191
+ * left of the row)
192
+ * 5. Click on _Edit_
193
+ * 6. Inspect the _Access Control_ section in the pop-up
194
+ *
195
+ * The bucket name is specified as the _path_ portion of the URI.
196
+ *
197
+ * For security purposes, the _user_ and _passwd_ cannot be specified within
198
+ * the URI
199
+ *
200
+ *
201
+ * @note
202
+ * You may not change the bucket or credentials after initializing the handle.
203
+ *
204
+ * #### Bootstrap Options
205
+ *
206
+ * The default configuration process will attempt to bootstrap first from
207
+ * the new memcached configuration protocol (CCCP) and if that fails, use
208
+ * the "HTTP" protocol via the REST API.
209
+ *
210
+ * The CCCP configuration will by default attempt to connect to one of
211
+ * the nodes specified on the port 11201. While normally the memcached port
212
+ * is determined by the configuration itself, this is not possible when
213
+ * the configuration has not been attained. You may specify a list of
214
+ * alternate memcached servers by using the 'mchosts' field.
215
+ *
216
+ * If you wish to modify the default bootstrap protocol selection, you
217
+ * can use the `bootstrap_on` option to specify the desired bootstrap
218
+ * specification
219
+ * to use for configuration (note that the ordering of this array is
220
+ * ignored). Using this mechanism, you can disable CCCP or HTTP.
221
+ *
222
+ * To force only "new-style" bootstrap, you may use `bootstrap_on=cccp`.
223
+ * To force only "old-style" bootstrap, use `bootstrap_on=http`. To force the
224
+ * default behavior, use `bootstrap_on=all`
225
+ *
226
+ *
227
+ * @addtogroup lcb-init
228
+ * @{
229
+ */
230
+
231
+ /** @brief Handle types @see lcb_create_st3::type */
232
+ typedef enum {
233
+ LCB_TYPE_BUCKET = 0x00, /**< Handle for data access (default) */
234
+ LCB_TYPE_CLUSTER = 0x01 /**< Handle for administrative access */
235
+ } lcb_type_t;
236
+
237
+ #ifndef __LCB_DOXYGEN__
238
+ /* These are definitions for some of the older fields of the `lcb_create_st`
239
+ * structure. They are here for backwards compatibility and should not be
240
+ * used by new code */
241
+ typedef enum { LCB_CONFIG_TRANSPORT_LIST_END = 0, LCB_CONFIG_TRANSPORT_HTTP = 1, LCB_CONFIG_TRANSPORT_CCCP, LCB_CONFIG_TRANSPORT_MAX } lcb_config_transport_t;
242
+ #define LCB_CREATE_V0_FIELDS const char *host; const char *user; const char *passwd; const char *bucket; struct lcb_io_opt_st *io;
243
+ #define LCB_CREATE_V1_FIELDS LCB_CREATE_V0_FIELDS lcb_type_t type;
244
+ #define LCB_CREATE_V2_FIELDS LCB_CREATE_V1_FIELDS const char *mchosts; const lcb_config_transport_t* transports;
245
+ struct lcb_create_st0 { LCB_CREATE_V0_FIELDS };
246
+ struct lcb_create_st1 { LCB_CREATE_V1_FIELDS };
247
+ struct lcb_create_st2 { LCB_CREATE_V2_FIELDS };
248
+ #endif
249
+
250
+ /**
251
+ * @brief Innser structure for lcb_create().
252
+ */
253
+ struct lcb_create_st3 {
254
+ const char *connstr; /**< Connection string */
255
+ const char *username; /**< Username for bucket. Unused as of Server 2.5 */
256
+ const char *passwd; /**< Password for bucket */
257
+ void *_pad_bucket; /**< @private */
258
+ struct lcb_io_opt_st *io; /**< IO Options */
259
+ lcb_type_t type;
260
+ };
261
+
262
+ /**@brief Wrapper structure for lcb_create()
263
+ * @see lcb_create_st3 */
264
+ struct lcb_create_st {
265
+ /** Indicates which field in the @ref lcb_CRST_u union should be used. Set this to `3` */
266
+ int version;
267
+
268
+ /**This union contains the set of current and historical options. The
269
+ * The #v3 field should be used. */
270
+ union lcb_CRST_u {
271
+ struct lcb_create_st0 v0;
272
+ struct lcb_create_st1 v1;
273
+ struct lcb_create_st2 v2;
274
+ struct lcb_create_st3 v3; /**< Use this field */
275
+ } v;
276
+ LCB_DEPR_CTORS_CRST
277
+ };
278
+
279
+ /**
280
+ * @brief Create an instance of lcb.
281
+ * @param instance Where the instance should be returned
282
+ * @param options How to create the libcouchbase instance
283
+ * @return LCB_SUCCESS on success
284
+ *
285
+ *
286
+ * ### Examples
287
+ * Create an instance using the default values:
288
+ *
289
+ * @code{.c}
290
+ * lcb_t instance;
291
+ * lcb_error_t err = lcb_create(&instance, NULL);
292
+ * if (err != LCB_SUCCESS) {
293
+ * fprintf(stderr, "Failed to create instance: %s\n", lcb_strerror(NULL, err));
294
+ * exit(EXIT_FAILURE);
295
+ * }
296
+ * @endcode
297
+ *
298
+ * Specify server list
299
+ *
300
+ * @code{.c}
301
+ * struct lcb_create_st options;
302
+ * memset(&options, 0, sizeof(options));
303
+ * options.version = 3;
304
+ * options.v.v3.connstr = "couchbase://host1,host2,host3";
305
+ * err = lcb_create(&instance, &options);
306
+ * @endcode
307
+ *
308
+ *
309
+ * Create a handle for data requests to protected bucket
310
+ *
311
+ * @code{.c}
312
+ * struct lcb_create_st options;
313
+ * memset(&options, 0, sizeof(options));
314
+ * options.version = 3;
315
+ * options.v.v3.host = "couchbase://example.com,example.org/protected"
316
+ * options.v.v3.passwd = "secret";
317
+ * err = lcb_create(&instance, &options);
318
+ * @endcode
319
+ * @committed
320
+ * @see lcb_create_st3
321
+ */
322
+ LIBCOUCHBASE_API
323
+ lcb_error_t lcb_create(lcb_t *instance, const struct lcb_create_st *options);
324
+
325
+ /**
326
+ * @brief Schedule the initial connection
327
+ * This function will schedule the initial connection for the handle. This
328
+ * function _must_ be called before any operations can be performed.
329
+ *
330
+ * lcb_set_bootstrap_callback() or lcb_get_bootstrap_status() can be used to
331
+ * determine if the scheduled connection completed successfully.
332
+ *
333
+ * @par Synchronous Usage
334
+ * @code{.c}
335
+ * lcb_error_t rc = lcb_connect(instance);
336
+ * if (rc != LCB_SUCCESS) {
337
+ * your_error_handling(rc);
338
+ * }
339
+ * lcb_wait(instance);
340
+ * rc = lcb_get_bootstrap_status(instance);
341
+ * if (rc != LCB_SUCCESS) {
342
+ * your_error_handler(rc);
343
+ * }
344
+ * @endcode
345
+ * @committed
346
+ */
347
+ LIBCOUCHBASE_API
348
+ lcb_error_t lcb_connect(lcb_t instance);
349
+
350
+ /**
351
+ * Bootstrap callback. Invoked once the instance is ready to perform operations
352
+ * @param instance The instance which was bootstrapped
353
+ * @param err The error code received. If this is not LCB_SUCCESS then the
354
+ * instance is not bootstrapped and must be recreated
355
+ *
356
+ * @attention This callback only receives information during instantiation.
357
+ * @committed
358
+ */
359
+ typedef void (*lcb_bootstrap_callback)(lcb_t instance, lcb_error_t err);
360
+
361
+ /**
362
+ * @brief Set the callback for notification of success or failure of
363
+ * initial connection.
364
+ *
365
+ * @param instance the instance
366
+ * @param callback the callback to set. If `NULL`, return the existing callback
367
+ * @return The existing (and previous) callback.
368
+ * @see lcb_connect()
369
+ * @see lcb_get_bootstrap_status()
370
+ */
371
+ LIBCOUCHBASE_API
372
+ lcb_bootstrap_callback
373
+ lcb_set_bootstrap_callback(lcb_t instance, lcb_bootstrap_callback callback);
374
+
375
+ /**
376
+ * @brief Gets the initial bootstrap status
377
+ *
378
+ * This is an alternative to using the lcb_bootstrap_callback() and may be used
379
+ * after the initial lcb_connect() and lcb_wait() sequence.
380
+ * @param instance
381
+ * @return LCB_SUCCESS if properly bootstrapped or an error code otherwise.
382
+ *
383
+ * @attention
384
+ * Calling this function only makes sense during instantiation.
385
+ * @committed
386
+ */
387
+ LIBCOUCHBASE_API
388
+ lcb_error_t
389
+ lcb_get_bootstrap_status(lcb_t instance);
390
+ /**@}*/
391
+
392
+
393
+
394
+ /**
395
+ * @ingroup lcb-public-api
396
+ * @defgroup lcb-kv-api Key/Value
397
+ *
398
+ * @brief Preview APIs for performing commands
399
+ *
400
+ * @details
401
+ * Basic command and structure definitions for public API. This represents the
402
+ * "V3" API of libcouchbase. This API replaces the legacy API (which now wraps
403
+ * this one). It contains common definitions for scheduling, response structures
404
+ * and callback signatures.
405
+ *
406
+ * @addtogroup lcb-kv-api
407
+ * @{
408
+ */
409
+
410
+ /**
411
+ * @name Creating Commands
412
+ * @details
413
+ *
414
+ * Issuing a command to the Cluster involves selecting the correct command
415
+ * structure, populating it with the data relevant for the command, optionally
416
+ * associating the command with your own application data, issuing the command
417
+ * to a spooling function, and finally receiving the response.
418
+ *
419
+ * Command structures all derive from the common @ref lcb_CMDBASE structure. This
420
+ * structure defines the common fields for all commands.
421
+ *
422
+ * Almost all commands need to contain a key, which should be assigned using
423
+ * the LCB_CMD_SET_KEY() macro.
424
+ *
425
+ * @{*/
426
+
427
+ #define LCB_CMD_BASE \
428
+ /**Common flags for the command. These modify the command itself. Currently
429
+ the lower 16 bits of this field are reserved, and the higher 16 bits are
430
+ used for individual commands.*/ \
431
+ lcb_U32 cmdflags; \
432
+ \
433
+ /**Specify the expiration time. This is either an absolute Unix time stamp
434
+ or a relative offset from now, in seconds. If the value of this number
435
+ is greater than the value of thirty days in seconds, then it is a Unix
436
+ timestamp.
437
+
438
+ This field is used in mutation operations (lcb_store3()) to indicate
439
+ the lifetime of the item. It is used in lcb_get3() with the lcb_CMDGET::lock
440
+ option to indicate the lock expiration itself. */ \
441
+ lcb_U32 exptime; \
442
+ \
443
+ /**The known CAS of the item. This is passed to mutation to commands to
444
+ ensure the item is only changed if the server-side CAS value matches the
445
+ one specified here. For other operations (such as lcb_CMDENDURE) this
446
+ is used to ensure that the item has been persisted/replicated to a number
447
+ of servers with the value specified here. */ \
448
+ lcb_U64 cas; \
449
+ \
450
+ /**The key for the document itself. This should be set via LCB_CMD_SET_KEY() */ \
451
+ lcb_KEYBUF key; \
452
+ \
453
+ /** \volatile */ \
454
+ lcb_KEYBUF _hashkey
455
+
456
+ /**@brief Common ABI header for all commands. _Any_ command may be safely
457
+ * casted to this type.*/
458
+ typedef struct lcb_CMDBASE {
459
+ LCB_CMD_BASE;
460
+ } lcb_CMDBASE;
461
+
462
+ /**
463
+ * @private
464
+ * Flag for lcb_CMDBASE::cmdflags which indicates that the lcb_CMDBASE::cookie
465
+ * is a special callback object. This flag is used internally within the
466
+ * library.
467
+ */
468
+ #define LCB_CMD_F_INTERNAL_CALLBACK (1 << 0)
469
+
470
+ /**
471
+ * If this flag is set, then multiple authentication credentials will be passed
472
+ * to the server. By default only the bucket's credentials (i.e. bucket SASL
473
+ * password) are passed.
474
+ */
475
+ #define LCB_CMD_F_MULTIAUTH (1<<1)
476
+
477
+ /**
478
+ * @committed
479
+ *
480
+ * Set the key for the command.
481
+ * @param cmd A command derived from lcb_CMDBASE
482
+ * @param keybuf the buffer for the key
483
+ * @param keylen the length of the key.
484
+ *
485
+ * @code{.c}
486
+ * lcb_CMDGET cmd = { 0 };
487
+ * LCB_CMD_SET_KEY(&cmd, "key", strlen("key"));
488
+ * @endcode
489
+ *
490
+ * The storage for `keybuf` may be released or modified after the command has
491
+ * been spooled.
492
+ */
493
+ #define LCB_CMD_SET_KEY(cmd, keybuf, keylen) \
494
+ LCB_KREQ_SIMPLE(&(cmd)->key, keybuf, keylen)
495
+
496
+ /**
497
+ * @volatile
498
+ *
499
+ * Sets the vBucket ID for the item. This accomplishes the same effect as
500
+ * _hashkey_ except that this assumes the vBucket has already been obtained.
501
+ *
502
+ * The intent of this API is to override the default vBucket hashing/calculation.
503
+ *
504
+ * @param cmd the command structure
505
+ * @param vbid the vBucket ID for the key.
506
+ */
507
+ #define LCB_CMD__SETVBID(cmd, vbid) do { \
508
+ (cmd)->_hashkey.type = LCB_KV_VBID; \
509
+ (cmd)->_hashkey.contig.nbytes = vbid; \
510
+ } while (0);
511
+ /**@}*/
512
+
513
+ /**
514
+ * @name Receiving Responses
515
+ * @details
516
+ *
517
+ * This section describes the APIs used in receiving responses.
518
+ *
519
+ * Each command will have a callback invoked (typically once, for some commands
520
+ * this may be more than once) with a response structure. The response structure
521
+ * will be of a type that extends lcb_RESPBASE. The response structure should
522
+ * not be modified and any of its fields should be considered to point to memory
523
+ * which will be released after the callback exits.
524
+ *
525
+ * The common response header contains the lcb_RESPBASE::cookie field which
526
+ * is the pointer to your application context (passed as the second argument
527
+ * to the spooling function) and allows you to associate a specific command
528
+ * with a specific response.
529
+ *
530
+ * The header will also contain the key (lcb_RESPBASE::key) field which can
531
+ * also help identify the specific command. This is useful if you maintain a
532
+ * single _cookie_ for multiple commands, and have per-item specific data
533
+ * you wish to associate within the _cookie_ itself.
534
+ *
535
+ * Success or failure of the operation is signalled through the lcb_RESPBASE::rc
536
+ * field. Note that even in the case of failure, the lcb_RESPBASE::cookie and
537
+ * lcb_RESPBASE::key fields will _always_ be populated.
538
+ *
539
+ * Most commands also return the CAS of the item (as it exists on the server)
540
+ * and this is placed inside the lcb_RESPBASE::cas field, however it is
541
+ * only valid in the case where lcb_RESPBASE::rc is LCB_SUCCESS.
542
+ *
543
+ * @{
544
+ */
545
+
546
+ #define LCB_RESP_BASE \
547
+ /**
548
+ Application-defined pointer passed as the `cookie` parameter when
549
+ scheduling the command.
550
+ */ \
551
+ void *cookie; \
552
+ const void *key; /**< Key for request */ \
553
+ lcb_SIZE nkey; /**< Size of key */ \
554
+ lcb_CAS cas; /**< CAS for response (if applicable) */ \
555
+ lcb_error_t rc; /**< Status code */ \
556
+ lcb_U16 version; /**< ABI version for response */ \
557
+ lcb_U16 rflags; /**< Response specific flags. see ::lcb_RESPFLAGS */
558
+
559
+
560
+ /**
561
+ * @brief
562
+ * Base response structure for callbacks.
563
+ * All responses structures derive from this ABI.
564
+ */
565
+ typedef struct {
566
+ LCB_RESP_BASE
567
+ } lcb_RESPBASE;
568
+
569
+
570
+ #define LCB_RESP_SERVER_FIELDS \
571
+ /** String containing the `host:port` of the server which sent this response */ \
572
+ const char *server;
573
+
574
+ /**@brief Base structure for informational commands from servers
575
+ * This contains an additional lcb_RESPSERVERBASE::server field containing the
576
+ * server which emitted this response.
577
+ */
578
+ typedef struct {
579
+ LCB_RESP_BASE
580
+ LCB_RESP_SERVER_FIELDS
581
+ } lcb_RESPSERVERBASE;
582
+
583
+ /** @ingroup lcb-mutation-tokens */
584
+ typedef struct lcb_MUTATION_TOKEN {
585
+ lcb_U64 uuid_; /**< Use LCB_MUTATION_TOKEN_ID() */
586
+ lcb_U64 seqno_; /**< Use LCB_MUTATION_TOKEN_SEQ() */
587
+ lcb_U16 vbid_; /**< Use LCB_MUTATION_TOKEN_VB() */
588
+ } lcb_MUTATION_TOKEN;
589
+
590
+ /**
591
+ * @brief Response flags.
592
+ * These provide additional 'meta' information about the response
593
+ * One of more of these values can be set in @ref lcb_RESPBASE::rflags
594
+ */
595
+ typedef enum {
596
+ /** No more responses are to be received for this request */
597
+ LCB_RESP_F_FINAL = 0x01,
598
+
599
+ /**The response was artificially generated inside the client.
600
+ * This does not contain reply data from the server for the command, but
601
+ * rather contains the basic fields to indicate success or failure and is
602
+ * otherwise empty.
603
+ */
604
+ LCB_RESP_F_CLIENTGEN = 0x02,
605
+
606
+ /**The response was a result of a not-my-vbucket error */
607
+ LCB_RESP_F_NMVGEN = 0x04,
608
+
609
+ /**The response has additional internal data.
610
+ * Used by lcb_resp_get_mutation_token() */
611
+ LCB_RESP_F_EXTDATA = 0x08,
612
+
613
+ /**Flag, only valid for subdoc responses, indicates that the response was
614
+ * processed using the single-operation protocol. */
615
+ LCB_RESP_F_SDSINGLE = 0x010
616
+ } lcb_RESPFLAGS;
617
+
618
+ /**
619
+ * The type of response passed to the callback. This is used to install callbacks
620
+ * for the library and to distinguish between responses if a single callback
621
+ * is used for multiple response types.
622
+ *
623
+ * @note These callbacks may conflict with the older version 2 callbacks. The
624
+ * rules are as follows:
625
+ * * If a callback has been installed using lcb_install_callback3(), then
626
+ * the older version 2 callback will not be invoked for that operation. The order
627
+ * of installation does not matter.
628
+ * * If the LCB_CALLBACK_DEFAULT callback is installed, _none_ of the version 2
629
+ * callbacks are invoked.
630
+ */
631
+ typedef enum {
632
+ LCB_CALLBACK_DEFAULT = 0, /**< Default callback invoked as a fallback */
633
+ LCB_CALLBACK_GET, /**< lcb_get3() */
634
+ LCB_CALLBACK_STORE, /**< lcb_store3() */
635
+ LCB_CALLBACK_COUNTER, /**< lcb_counter3() */
636
+ LCB_CALLBACK_TOUCH, /**< lcb_touch3() */
637
+ LCB_CALLBACK_REMOVE, /**< lcb_remove3() */
638
+ LCB_CALLBACK_UNLOCK, /**< lcb_unlock3() */
639
+ LCB_CALLBACK_STATS, /**< lcb_stats3() */
640
+ LCB_CALLBACK_VERSIONS, /**< lcb_server_versions3() */
641
+ LCB_CALLBACK_VERBOSITY, /**< lcb_server_verbosity3() */
642
+ LCB_CALLBACK_FLUSH, /**< lcb_flush3() */
643
+ LCB_CALLBACK_OBSERVE, /**< lcb_observe3_ctxnew() */
644
+ LCB_CALLBACK_GETREPLICA, /**< lcb_rget3() */
645
+ LCB_CALLBACK_ENDURE, /**< lcb_endure3_ctxnew() */
646
+ LCB_CALLBACK_HTTP, /**< lcb_http3() */
647
+ LCB_CALLBACK_CBFLUSH, /**< lcb_cbflush3() */
648
+ LCB_CALLBACK_OBSEQNO, /**< For lcb_observe_seqno3() */
649
+ LCB_CALLBACK_STOREDUR, /** <for lcb_storedur3() */
650
+ LCB_CALLBACK_SDLOOKUP,
651
+ LCB_CALLBACK_SDMUTATE,
652
+ LCB_CALLBACK__MAX /* Number of callbacks */
653
+ } lcb_CALLBACKTYPE;
654
+
655
+ /* The following callback types cannot be set using lcb_install_callback3(),
656
+ * however, their value is passed along as the second argument of their
657
+ * respective callbacks. This allows you to still use the same callback,
658
+ * differentiating their meaning by the type. */
659
+
660
+ /** Callback type for views (cannot be used for lcb_install_callback3()) */
661
+ #define LCB_CALLBACK_VIEWQUERY -1
662
+
663
+ /** Callback type for N1QL (cannot be used for lcb_install_callback3()) */
664
+ #define LCB_CALLBACK_N1QL -2
665
+
666
+ #define LCB_CALLBACK_IXMGMT -3
667
+
668
+ /**
669
+ * @committed
670
+ *
671
+ * Callback invoked for responses.
672
+ * @param instance The handle
673
+ * @param cbtype The type of callback - or in other words, the type of operation
674
+ * this callback has been invoked for.
675
+ * @param resp The response for the operation. Depending on the operation this
676
+ * response structure should be casted into a more specialized type.
677
+ */
678
+ typedef void (*lcb_RESPCALLBACK)
679
+ (lcb_t instance, int cbtype, const lcb_RESPBASE* resp);
680
+
681
+ /**
682
+ * @committed
683
+ *
684
+ * Install a new-style callback for an operation. The callback will be invoked
685
+ * with the relevant response structure.
686
+ *
687
+ * @param instance the handle
688
+ * @param cbtype the type of operation for which this callback should be installed.
689
+ * The value should be one of the lcb_CALLBACKTYPE constants
690
+ * @param cb the callback to install
691
+ * @return the old callback
692
+ *
693
+ * @note LCB_CALLBACK_DEFAULT is initialized to the default handler which proxies
694
+ * back to the older 2.x callbacks. If you set `cbtype` to LCB_CALLBACK_DEFAULT
695
+ * then your `2.x` callbacks _will not work_.
696
+ *
697
+ * @note The old callback may be `NULL`. It is usually not an error to have a
698
+ * `NULL` callback installed. If the callback is `NULL`, then the default callback
699
+ * invocation pattern will take place (as desribed above). However it is an error
700
+ * to set the default callback to `NULL`.
701
+ */
702
+ LIBCOUCHBASE_API
703
+ lcb_RESPCALLBACK
704
+ lcb_install_callback3(lcb_t instance, int cbtype, lcb_RESPCALLBACK cb);
705
+
706
+ /**
707
+ * @committed
708
+ *
709
+ * Get the current callback installed as `cbtype`. Note that this does not
710
+ * perform any kind of resolution (as described in lcb_install_callback3) and
711
+ * will only return a non-`NULL` value if a callback had specifically been
712
+ * installed via lcb_install_callback3() with the given `cbtype`.
713
+ *
714
+ * @param instance the handle
715
+ * @param cbtype the type of callback to retrieve
716
+ * @return the installed callback for the type.
717
+ */
718
+ LIBCOUCHBASE_API
719
+ lcb_RESPCALLBACK
720
+ lcb_get_callback3(lcb_t instance, int cbtype);
721
+
722
+ /**
723
+ * @committed
724
+ *
725
+ * Returns the type of the callback as a string.
726
+ * This function is helpful for debugging and demonstrative processes.
727
+ * @param cbtype the type of the callback (the second argument to the callback)
728
+ * @return a string describing the callback type
729
+ */
730
+ LIBCOUCHBASE_API
731
+ const char *
732
+ lcb_strcbtype(int cbtype);
733
+
734
+ /**@}*/
735
+
736
+ /**
737
+ * @ingroup lcb-kv-api
738
+ * @defgroup lcb-get Read
739
+ * @brief Retrieve a document from the cluster
740
+ * @addtogroup lcb-get
741
+ * @{
742
+ */
743
+
744
+ /**
745
+ * If this bit is set in lcb_CMDGET::cmdflags then the expiry time is cleared if
746
+ * lcb_CMDGET::exptime is 0. This allows get-and-touch with an expiry of 0.
747
+ */
748
+ #define LCB_CMDGET_F_CLEAREXP (1<<16)
749
+
750
+ /**@brief Command for retrieving a single item
751
+ *
752
+ * @see lcb_get3()
753
+ * @see lcb_RESPGET
754
+ *
755
+ * @note The #cas member should be set to 0 for this operation. If the #cas is
756
+ * not 0, lcb_get3() will fail with ::LCB_OPTIONS_CONFLICT.
757
+ *
758
+ * ### Use of the `exptime` field
759
+ *
760
+ * <ul>
761
+ * <li>Get And Touch:
762
+ *
763
+ * It is possible to retrieve an item and concurrently modify its expiration
764
+ * time (thus keeping it "alive"). The item's expiry time can be set using
765
+ * the #exptime field.
766
+ * </li>
767
+ *
768
+ * <li>Lock
769
+ * If the #lock field is set to non-zero, the #exptime field indicates the amount
770
+ * of time the lock should be held for
771
+ * </li>
772
+ * </ul>
773
+ */
774
+ typedef struct {
775
+ LCB_CMD_BASE;
776
+ /**If set to true, the `exptime` field inside `options` will take to mean
777
+ * the time the lock should be held. While the lock is held, other operations
778
+ * trying to access the key will fail with an `LCB_ETMPFAIL` error. The
779
+ * item may be unlocked either via `lcb_unlock3()` or via a mutation
780
+ * operation with a supplied CAS
781
+ */
782
+ int lock;
783
+ } lcb_CMDGET;
784
+
785
+ /** @brief Response structure when retrieving a single item */
786
+ typedef struct {
787
+ LCB_RESP_BASE
788
+ const void *value; /**< Value buffer for the item */
789
+ lcb_SIZE nvalue; /**< Length of value */
790
+ void* bufh;
791
+ lcb_datatype_t datatype; /**< @private */
792
+ lcb_U32 itmflags; /**< User-defined flags for the item */
793
+ } lcb_RESPGET;
794
+
795
+ /**
796
+ * @committed
797
+ *
798
+ * @brief Spool a single get operation
799
+ * @param instance the handle
800
+ * @param cookie a pointer to be associated with the command
801
+ * @param cmd the command structure
802
+ * @return LCB_SUCCESS if successful, an error code otherwise
803
+ *
804
+ * @par Request
805
+ * @code{.c}
806
+ * lcb_CMDGET cmd = { 0 };
807
+ * LCB_CMD_SET_KEY(&cmd, "Hello", 5);
808
+ * lcb_get3(instance, cookie, &cmd);
809
+ * @endcode
810
+ *
811
+ * @par Response
812
+ * @code{.c}
813
+ * lcb_install_callback3(instance, LCB_CALLBACK_GET, get_callback);
814
+ * static void get_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb) {
815
+ * const lcb_RESPGET *resp = (const lcb_RESPGET*)rb;
816
+ * printf("Got response for key: %.*s\n", (int)resp->key, resp->nkey);
817
+ *
818
+ * if (resp->rc != LCB_SUCCESS) {
819
+ * printf("Couldn't get item: %s\n", lcb_strerror(NULL, resp->rc));
820
+ * } else {
821
+ * printf("Got value: %.*s\n", (int)resp->nvalue, resp->value);
822
+ * printf("Got CAS: 0x%llx\n", resp->cas);
823
+ * printf("Got item/formatting flags: 0x%x\n", resp->itmflags);
824
+ * }
825
+ * }
826
+ *
827
+ * @endcode
828
+ *
829
+ * @par Errors
830
+ * @cb_err ::LCB_KEY_ENOENT if the item does not exist in the cluster
831
+ * @cb_err ::LCB_ETMPFAIL if the lcb_CMDGET::lock option was set but the item
832
+ * was already locked. Note that this error may also be returned (as a generic
833
+ * error) if there is a resource constraint within the server itself.
834
+ */
835
+ LIBCOUCHBASE_API
836
+ lcb_error_t
837
+ lcb_get3(lcb_t instance, const void *cookie, const lcb_CMDGET *cmd);
838
+ /**@}*/
839
+
840
+ /**
841
+ * @ingroup lcb-kv-api
842
+ * @defgroup lcb-get-replica Read (Replica)
843
+ * @brief Retrieve a document from a replica if it cannot be fetched from the
844
+ * primary
845
+ * @addtogroup lcb-get-replica
846
+ * @{
847
+ */
848
+
849
+
850
+ /**@brief Select get-replica mode
851
+ * @see lcb_rget3_cmd_t */
852
+ typedef enum {
853
+ /**Query all the replicas sequentially, retrieving the first successful
854
+ * response */
855
+ LCB_REPLICA_FIRST = 0x00,
856
+
857
+ /**Query all the replicas concurrently, retrieving all the responses*/
858
+ LCB_REPLICA_ALL = 0x01,
859
+
860
+ /**Query the specific replica specified by the
861
+ * lcb_rget3_cmd_t#index field */
862
+ LCB_REPLICA_SELECT = 0x02
863
+ } lcb_replica_t;
864
+
865
+ /**
866
+ * @brief Command for requesting an item from a replica
867
+ * @note The `options.exptime` and `options.cas` fields are ignored for this
868
+ * command.
869
+ *
870
+ * This structure is similar to @ref lcb_RESPGET with the addition of an
871
+ * `index` and `strategy` field which allow you to control and select how
872
+ * many replicas are queried.
873
+ *
874
+ * @see lcb_rget3(), lcb_RESPGET
875
+ */
876
+ typedef struct {
877
+ LCB_CMD_BASE;
878
+ /**
879
+ * Strategy for selecting a replica. The default is ::LCB_REPLICA_FIRST
880
+ * which results in the client trying each replica in sequence until a
881
+ * successful reply is found, and returned in the callback.
882
+ *
883
+ * ::LCB_REPLICA_FIRST evaluates to 0.
884
+ *
885
+ * Other options include:
886
+ * <ul>
887
+ * <li>::LCB_REPLICA_ALL - queries all replicas concurrently and dispatches
888
+ * a callback for each reply</li>
889
+ * <li>::LCB_REPLICA_SELECT - queries a specific replica indicated in the
890
+ * #index field</li>
891
+ * </ul>
892
+ *
893
+ * @note When ::LCB_REPLICA_ALL is selected, the callback will be invoked
894
+ * multiple times, one for each replica. The final callback will have the
895
+ * ::LCB_RESP_F_FINAL bit set in the lcb_RESPBASE::rflags field. The final
896
+ * response will also contain the response from the last replica to
897
+ * respond.
898
+ */
899
+ lcb_replica_t strategy;
900
+
901
+ /**
902
+ * Valid only when #strategy is ::LCB_REPLICA_SELECT, specifies the replica
903
+ * index number to query. This should be no more than `nreplicas-1`
904
+ * where `nreplicas` is the number of replicas the bucket is configured with.
905
+ */
906
+ int index;
907
+ } lcb_CMDGETREPLICA;
908
+
909
+ /**@committed
910
+ *
911
+ * @brief Spool a single get-with-replica request
912
+ * @param instance
913
+ * @param cookie
914
+ * @param cmd
915
+ * @return LCB_SUCCESS on success, error code otherwise.
916
+ *
917
+ * When a response is received, the callback installed for ::LCB_CALLBACK_GETREPLICA
918
+ * will be invoked. The response will be an @ref lcb_RESPGET pointer.
919
+ *
920
+ * ### Request
921
+ * @code{.c}
922
+ * lcb_CMDGETREPLICA cmd = { 0 };
923
+ * LCB_CMD_SET_KEY(&cmd, "key", 3);
924
+ * lcb_rget3(instance, cookie, &cmd);
925
+ * @endcode
926
+ *
927
+ * ### Response
928
+ * @code{.c}
929
+ * lcb_install_callback3(instance, LCB_CALLBACK_GETREPLICA, rget_callback);
930
+ * static void rget_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
931
+ * {
932
+ * const lcb_RESPGET *resp = (const lcb_RESPGET *)rb;
933
+ * printf("Got Get-From-Replica response for %.*s\n", (int)resp->key, resp->nkey);
934
+ * if (resp->rc == LCB_SUCCESS) {
935
+ * printf("Got response: %.*s\n", (int)resp->value, resp->nvalue);
936
+ * else {
937
+ * printf("Couldn't retrieve: %s\n", lcb_strerror(NULL, resp->rc));
938
+ * }
939
+ * }
940
+ * @endcode
941
+ *
942
+ * @warning As this function queries a replica node for data it is possible
943
+ * that the returned document may not reflect the latest document in the server.
944
+ *
945
+ * @warning This function should only be used in cases where a normal lcb_get3()
946
+ * has failed, or where there is reason to believe it will fail. Because this
947
+ * function may query more than a single replica it may cause additional network
948
+ * and server-side CPU load. Use sparingly and only when necessary.
949
+ *
950
+ * @cb_err ::LCB_KEY_ENOENT if the key is not found on the replica(s),
951
+ * ::LCB_NO_MATCHING_SERVER if there are no replicas (either configured or online),
952
+ * or if the given replica
953
+ * (if lcb_CMDGETREPLICA::strategy is ::LCB_REPLICA_SELECT) is not available or
954
+ * is offline.
955
+ */
956
+ LIBCOUCHBASE_API
957
+ lcb_error_t
958
+ lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd);
959
+ /**@}*/
960
+
961
+ /**
962
+ * @ingroup lcb-kv-api
963
+ * @defgroup lcb-store Create/Update
964
+ * @brief Set the value of a document
965
+ * @addtogroup lcb-store
966
+ * @{
967
+ */
968
+
969
+ /**
970
+ * @brief Values for lcb_CMDSTORE::operation
971
+ *
972
+ * Storing an item in couchbase is only one operation with a different
973
+ * set of attributes / constraints.
974
+ */
975
+ typedef enum {
976
+ /**
977
+ * Will cause the operation to fail if the key already exists in the
978
+ * cluster.
979
+ */
980
+ LCB_ADD = 0x01,
981
+
982
+ /**
983
+ * Will cause the operation to fail _unless_ the key already exists in the
984
+ * cluster.
985
+ */
986
+ LCB_REPLACE = 0x02,
987
+
988
+ /** Unconditionally store the item in the cluster */
989
+ LCB_SET = 0x03,
990
+
991
+ /**
992
+ * The default storage mode. This constant was added in version 2.6.2 for
993
+ * the sake of maintaining a default storage mode, eliminating the need
994
+ * for simple storage operations to explicitly define
995
+ * lcb_CMDSTORE::operation. Behaviorally it is identical to @ref LCB_SET
996
+ * in that it will make the server unconditionally store the item, whether
997
+ * it exists or not.
998
+ */
999
+ LCB_UPSERT = 0x00,
1000
+
1001
+ /**
1002
+ * Rather than setting the contents of the entire document, take the value
1003
+ * specified in lcb_CMDSTORE::value and _append_ it to the existing bytes in
1004
+ * the value.
1005
+ */
1006
+ LCB_APPEND = 0x04,
1007
+
1008
+ /**
1009
+ * Like ::LCB_APPEND, but prepends the new value to the existing value.
1010
+ */
1011
+ LCB_PREPEND = 0x05
1012
+ } lcb_storage_t;
1013
+
1014
+ /**@brief
1015
+ *
1016
+ * Command for storing an item to the server. This command must contain the
1017
+ * key to mutate, the value which should be set (or appended/prepended) in the
1018
+ * lcb_CMDSTORE::value field (see LCB_CMD_SET_VALUE()) and the operation indicating
1019
+ * the mutation type (lcb_CMDSTORE::operation).
1020
+ *
1021
+ * @warning #exptime *cannot* be used with #operation set to @ref LCB_APPEND
1022
+ * or @ref LCB_PREPEND.
1023
+ */
1024
+ typedef struct {
1025
+ LCB_CMD_BASE;
1026
+
1027
+ /**
1028
+ * Value to store on the server. The value may be set using the
1029
+ * LCB_CMD_SET_VALUE() or LCB_CMD_SET_VALUEIOV() API
1030
+ */
1031
+ lcb_VALBUF value;
1032
+
1033
+ /**
1034
+ * Format flags used by clients to determine the underlying encoding of
1035
+ * the value. This value is also returned during retrieval operations in the
1036
+ * lcb_RESPGET::itmflags field
1037
+ */
1038
+ lcb_U32 flags;
1039
+
1040
+ /** Do not set this value for now */
1041
+ lcb_datatype_t datatype;
1042
+
1043
+ /** Controls *how* the operation is perfomed. See the documentation for
1044
+ * @ref lcb_storage_t for the options. There is no default value for this
1045
+ * field.
1046
+ */
1047
+ lcb_storage_t operation;
1048
+ } lcb_CMDSTORE;
1049
+
1050
+ /**
1051
+ * @brief Response structure for lcb_store3()
1052
+ */
1053
+ typedef struct {
1054
+ LCB_RESP_BASE
1055
+
1056
+ /** The type of operation which was performed */
1057
+ lcb_storage_t op;
1058
+ } lcb_RESPSTORE;
1059
+
1060
+ /**
1061
+ * @committed
1062
+ *
1063
+ * @brief Set the value buffer for the command. This may be used when the new
1064
+ * value is a single contiguous buffer.
1065
+ *
1066
+ * @param scmd an lcb_CMDSTORE pointer
1067
+ * @param valbuf the buffer for the value
1068
+ * @param vallen the length of the buffer
1069
+ *
1070
+ * The buffer needs to remain valid only until the command is passed to the
1071
+ * lcb_store3() function.
1072
+ */
1073
+ #define LCB_CMD_SET_VALUE(scmd, valbuf, vallen) do { \
1074
+ (scmd)->value.vtype = LCB_KV_COPY; \
1075
+ (scmd)->value.u_buf.contig.bytes = valbuf; \
1076
+ (scmd)->value.u_buf.contig.nbytes = vallen; \
1077
+ } while (0);
1078
+
1079
+ /**
1080
+ * @committed
1081
+ *
1082
+ * @brief Set value from a series of input buffers. This may be used when the
1083
+ * input buffer is not contiguous. Using this call eliminates the need for
1084
+ * creating a temporary contiguous buffer in which to store the value.
1085
+ *
1086
+ * @param scmd the command which needs a value
1087
+ * @param iovs an array of @ref lcb_IOV structures
1088
+ * @param niovs number of items in the array.
1089
+ *
1090
+ * The buffers (and the IOV array itself)
1091
+ * need to remain valid only until the scheduler function is called. Once the
1092
+ * scheduling function is called, the buffer contents are copied into the
1093
+ * library's internal buffers.
1094
+ */
1095
+ #define LCB_CMD_SET_VALUEIOV(scmd, iovs, niovs) do { \
1096
+ (scmd)->value.vtype = LCB_KV_IOVCOPY; \
1097
+ (scmd)->value.u_buf.multi.iov = iovs; \
1098
+ (scmd)->value.u_buf.multi.niov = niovs; \
1099
+ } while (0);
1100
+
1101
+ /**
1102
+ * @committed
1103
+ * @brief Schedule a single storage request
1104
+ * @param instance the handle
1105
+ * @param cookie pointer to associate with the command
1106
+ * @param cmd the command structure
1107
+ * @return LCB_SUCCESS on success, error code on failure
1108
+ *
1109
+ * ### Request
1110
+ *
1111
+ * @code{.c}
1112
+ * lcb_CMDSTORE cmd = { 0 };
1113
+ * LCB_CMD_SET_KEY(&cmd, "Key", 3);
1114
+ * LCB_CMD_SET_VALUE(&cmd, "value", 5);
1115
+ * cmd.operation = LCB_ADD; // Only create if it does not exist
1116
+ * cmd.exptime = 60; // expire in a minute
1117
+ * lcb_store3(instance, cookie, &cmd);
1118
+ * lcb_wait3(instance, LCB_WAIT_NOCHECK);
1119
+ * @endcode
1120
+ *
1121
+ * ### Response
1122
+ * @code{.c}
1123
+ * lcb_install_callback3(instance, LCB_CALLBACK_STORE, store_callback);
1124
+ * void store_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
1125
+ * {
1126
+ * if (rb->rc == LCB_SUCCESS) {
1127
+ * printf("Store success: CAS=%llx\n", rb->cas);
1128
+ * } else {
1129
+ * printf("Store failed: %s\n", lcb_strerorr(NULL, rb->rc);
1130
+ * }
1131
+ * }
1132
+ * @endcode
1133
+ *
1134
+ * Operation-specific error codes include:
1135
+ * @cb_err ::LCB_KEY_ENOENT if ::LCB_REPLACE was used and the key does not exist
1136
+ * @cb_err ::LCB_KEY_EEXISTS if ::LCB_ADD was used and the key already exists
1137
+ * @cb_err ::LCB_KEY_EEXISTS if the CAS was specified (for an operation other
1138
+ * than ::LCB_ADD) and the item exists on the server with a different
1139
+ * CAS
1140
+ * @cb_err ::LCB_KEY_EEXISTS if the item was locked and the CAS supplied did
1141
+ * not match the locked item's CAS (or if no CAS was supplied)
1142
+ * @cb_err ::LCB_NOT_STORED if an ::LCB_APPEND or ::LCB_PREPEND operation was
1143
+ * performed and the item did not exist on the server.
1144
+ * @cb_err ::LCB_E2BIG if the size of the value exceeds the cluster per-item
1145
+ * value limit (currently 20MB).
1146
+ *
1147
+ *
1148
+ * @note After a successful store operation you can use lcb_endure3_ctxnew()
1149
+ * to wait for the item to be persisted and/or replicated to other nodes.
1150
+ */
1151
+ LIBCOUCHBASE_API
1152
+ lcb_error_t
1153
+ lcb_store3(lcb_t instance, const void *cookie, const lcb_CMDSTORE *cmd);
1154
+ /**@}*/
1155
+
1156
+ /**
1157
+ * @ingroup lcb-kv-api
1158
+ * @defgroup lcb-remove Delete
1159
+ * @brief Remove documents from the cluster
1160
+ * @addtogroup lcb-remove
1161
+ * @{
1162
+ */
1163
+
1164
+ /**@brief
1165
+ * Command for removing an item from the server
1166
+ * @note The lcb_CMDREMOVE::exptime field here does nothing.
1167
+ *
1168
+ * The lcb_CMDREMOVE::cas field may be
1169
+ * set to the last CAS received from a previous operation if you wish to
1170
+ * ensure the item is removed only if it has not been mutated since the last
1171
+ * retrieval
1172
+ */
1173
+ typedef lcb_CMDBASE lcb_CMDREMOVE;
1174
+
1175
+ /**@brief
1176
+ * Response structure for removal operation. The lcb_RESPREMOVE::cas field
1177
+ * may be used to check that it no longer exists on any node's storage
1178
+ * using the lcb_endure3_ctxnew() function. You can also use the
1179
+ * @ref lcb_MUTATION_TOKEN (via lcb_resp_get_mutation_token)
1180
+ *
1181
+ * The lcb_RESPREMOVE::rc field may be set to ::LCB_KEY_ENOENT if the item does
1182
+ * not exist, or ::LCB_KEY_EEXISTS if a CAS was specified and the item has since
1183
+ * been mutated.
1184
+ */
1185
+ typedef lcb_RESPBASE lcb_RESPREMOVE;
1186
+
1187
+ /**@committed
1188
+ * @brief Spool a removal of an item
1189
+ * @param instance the handle
1190
+ * @param cookie pointer to associate with the request
1191
+ * @param cmd the command
1192
+ * @return LCB_SUCCESS on success, other code on failure
1193
+ *
1194
+ * ### Request
1195
+ * @code{.c}
1196
+ * lcb_CMDREMOVE cmd = { 0 };
1197
+ * LCB_CMD_SET_KEY(&cmd, "deleteme", strlen("deleteme"));
1198
+ * lcb_remove3(instance, cookie, &cmd);
1199
+ * @endcode
1200
+ *
1201
+ * ### Response
1202
+ * @code{.c}
1203
+ * lcb_install_callback3(instance, LCB_CALLBACK_REMOVE, rm_callback);
1204
+ * void rm_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
1205
+ * {
1206
+ * printf("Key: %.*s...", (int)resp->nkey, resp->key);
1207
+ * if (rb->rc != LCB_SUCCESS) {
1208
+ * printf("Failed to remove item!: %s\n", lcb_strerror(NULL, rb->rc));
1209
+ * } else {
1210
+ * printf("Removed item!\n");
1211
+ * }
1212
+ * }
1213
+ * @endcode
1214
+ *
1215
+ * The following operation-specific error codes are returned in the callback
1216
+ * @cb_err ::LCB_KEY_ENOENT if the key does not exist
1217
+ * @cb_err ::LCB_KEY_EEXISTS if the CAS was specified and it does not match the
1218
+ * CAS on the server
1219
+ * @cb_err ::LCB_KEY_EEXISTS if the item was locked and no CAS (or an incorrect
1220
+ * CAS) was specified.
1221
+ *
1222
+ */
1223
+ LIBCOUCHBASE_API
1224
+ lcb_error_t
1225
+ lcb_remove3(lcb_t instance, const void *cookie, const lcb_CMDREMOVE * cmd);
1226
+ /**@}*/
1227
+
1228
+ /**
1229
+ * @ingroup lcb-kv-api
1230
+ * @defgroup lcb-mctx MULTICMD API
1231
+ * @addtogroup lcb-mctx
1232
+ * @{
1233
+ */
1234
+ /**
1235
+ * Multi Command Context API
1236
+ * Some commands (notably, OBSERVE and its higher level equivalent, endue)
1237
+ * are handled more efficiently at the cluster side by stuffing multiple
1238
+ * items into a single packet.
1239
+ *
1240
+ * This structure defines three function pointers to invoke. The #addcmd()
1241
+ * function will add a new command to the current packet, the #done()
1242
+ * function will schedule the packet(s) into the current scheduling context
1243
+ * and the #fail() function will destroy the context without progressing
1244
+ * further.
1245
+ *
1246
+ * Some commands will return an lcb_MULTICMD_CTX object to be used for this
1247
+ * purpose:
1248
+ *
1249
+ * @code{.c}
1250
+ * lcb_MUTLICMD_CTX *ctx = lcb_observe3_ctxnew(instance);
1251
+ *
1252
+ * lcb_CMDOBSERVE cmd = { 0 };
1253
+ * LCB_CMD_SET_KEY(&cmd, "key1", strlen("key1"));
1254
+ * ctx->addcmd(ctx, &cmd);
1255
+ * LCB_CMD_SET_KEY(&cmd.key, "key2", strlen("key2"));
1256
+ * ctx->addcmd(ctx, &cmd);
1257
+ * LCB_CMD_SET_KEY(&cmd.key, "key3", strlen("key3"));
1258
+ * ctx->addcmd(ctx, &cmd);
1259
+ *
1260
+ * ctx->done(ctx);
1261
+ * lcb_wait(instance);
1262
+ * @endcode
1263
+ */
1264
+ typedef struct lcb_MULTICMD_CTX_st {
1265
+ /**
1266
+ * Add a command to the current context
1267
+ * @param ctx the context
1268
+ * @param cmd the command to add. Note that `cmd` may be a subclass of lcb_CMDBASE
1269
+ * @return LCB_SUCCESS, or failure if a command could not be added.
1270
+ */
1271
+ lcb_error_t (*addcmd)(struct lcb_MULTICMD_CTX_st *ctx, const lcb_CMDBASE *cmd);
1272
+
1273
+ /**
1274
+ * Indicate that no more commands are added to this context, and that the
1275
+ * context should assemble the packets and place them in the current
1276
+ * scheduling context
1277
+ * @param ctx The multi context
1278
+ * @param cookie The cookie for all commands
1279
+ * @return LCB_SUCCESS if scheduled successfully, or an error code if there
1280
+ * was a problem constructing the packet(s).
1281
+ */
1282
+ lcb_error_t (*done)(struct lcb_MULTICMD_CTX_st *ctx, const void *cookie);
1283
+
1284
+ /**
1285
+ * Indicate that no more commands should be added to this context, and that
1286
+ * the context should not add its contents to the packet queues, but rather
1287
+ * release its resources. Called if you don't want to actually perform
1288
+ * the operations.
1289
+ * @param ctx
1290
+ */
1291
+ void (*fail)(struct lcb_MULTICMD_CTX_st *ctx);
1292
+ } lcb_MULTICMD_CTX;
1293
+ /**@}*/
1294
+
1295
+ /**
1296
+ * @ingroup lcb-kv-api
1297
+ * @defgroup lcb-durability Durability
1298
+ * @brief Ensure persistence and mutation of documents
1299
+ * @addtogroup lcb-durability
1300
+ * @{
1301
+ */
1302
+
1303
+ /**
1304
+ * @name Wait for a mutation to be persisted/replicated
1305
+ * @{
1306
+ */
1307
+
1308
+ /**
1309
+ * Type of durability polling to use.
1310
+ */
1311
+ typedef enum {
1312
+ /**
1313
+ * Use the preferred durability. If ::LCB_CNTL_FETCH_MUTATION_TOKENS is
1314
+ * enabled and the server version is 4.0 or greater then ::LCB_DURABILITY_MODE_SEQNO
1315
+ * is used. Otherwise ::LCB_DURABILITY_MODE_CAS is used.
1316
+ */
1317
+ LCB_DURABILITY_MODE_DEFAULT = 0,
1318
+
1319
+ /**
1320
+ * Explicitly request CAS-based durability. This is done by checking the
1321
+ * CAS of the item on each server with the item specified in the input.
1322
+ * The durability operation is considered complete when all items' CAS
1323
+ * values match. If the CAS value on the master node changes then the
1324
+ * durability operation will fail with ::LCB_KEY_EEXISTS.
1325
+ *
1326
+ * @note
1327
+ * CAS may change either because of a failover or because of another
1328
+ * subsequent mutation. These scenarios are possible (though unlikely).
1329
+ * The ::LCB_DURABILITY_MODE_SEQNO mode is not subject to these constraints.
1330
+ */
1331
+ LCB_DURABILITY_MODE_CAS,
1332
+
1333
+ /**
1334
+ * Use sequence-number based polling. This is done by checking the current
1335
+ * "mutation sequence number" for the given mutation. To use this mode
1336
+ * either an explicit @ref lcb_MUTATION_TOKEN needs to be passed, or
1337
+ * the ::LCB_CNTL_DURABILITY_MUTATION_TOKENS should be set, allowing
1338
+ * the caching of the latest mutation token for each vBucket.
1339
+ */
1340
+ LCB_DURABILITY_MODE_SEQNO
1341
+ } lcb_DURMODE;
1342
+
1343
+ /** @brief Options for lcb_endure3_ctxnew() */
1344
+ typedef struct {
1345
+ /**
1346
+ * Upper limit in microseconds from the scheduling of the command. When
1347
+ * this timeout occurs, all remaining non-verified keys will have their
1348
+ * callbacks invoked with @ref LCB_ETIMEDOUT.
1349
+ *
1350
+ * If this field is not set, the value of @ref LCB_CNTL_DURABILITY_TIMEOUT
1351
+ * will be used.
1352
+ */
1353
+ lcb_U32 timeout;
1354
+
1355
+ /**
1356
+ * The durability check may involve more than a single call to observe - or
1357
+ * more than a single packet sent to a server to check the key status. This
1358
+ * value determines the time to wait (in microseconds)
1359
+ * between multiple probes for the same server.
1360
+ * If not set, the @ref LCB_CNTL_DURABILITY_INTERVAL will be used
1361
+ * instead.
1362
+ */
1363
+ lcb_U32 interval;
1364
+
1365
+ /**
1366
+ * how many nodes the key should be persisted to (including master).
1367
+ * If set to 0 then persistence will not be checked. If set to a large
1368
+ * number (i.e. UINT16_MAX) and #cap_max is also set, will be set to the
1369
+ * maximum number of nodes to which persistence is possible (which will
1370
+ * always contain at least the master node).
1371
+ *
1372
+ * The maximum valid value for this field is
1373
+ * 1 + the total number of configured replicas for the bucket which are part
1374
+ * of the cluster. If this number is higher then it will either be
1375
+ * automatically capped to the maximum available if (#cap_max is set) or
1376
+ * will result in an ::LCB_DURABILITY_ETOOMANY error.
1377
+ */
1378
+ lcb_U16 persist_to;
1379
+
1380
+ /**
1381
+ * how many nodes the key should be persisted to (excluding master).
1382
+ * If set to 0 then replication will not be checked. If set to a large
1383
+ * number (i.e. UINT16_MAX) and #cap_max is also set, will be set to the
1384
+ * maximum number of nodes to which replication is possible (which may
1385
+ * be 0 if the bucket is not configured for replicas).
1386
+ *
1387
+ * The maximum valid value for this field is the total number of configured
1388
+ * replicas which are part of the cluster. If this number is higher then
1389
+ * it will either be automatically capped to the maximum available
1390
+ * if (#cap_max is set) or will result in an ::LCB_DURABILITY_ETOOMANY
1391
+ * error.
1392
+ * */
1393
+ lcb_U16 replicate_to;
1394
+
1395
+ /**
1396
+ * this flag inverts the sense of the durability check and ensures that
1397
+ * the key does *not* exist. This should be used if checking durability
1398
+ * after an lcb_remove3() operation.
1399
+ */
1400
+ lcb_U8 check_delete;
1401
+
1402
+ /**
1403
+ * If replication/persistence requirements are excessive, cap to
1404
+ * the maximum available
1405
+ */
1406
+ lcb_U8 cap_max;
1407
+
1408
+ /**
1409
+ * Set the polling method to use.
1410
+ * The value for this field should be one of the @ref lcb_DURMODE constants.
1411
+ */
1412
+ lcb_U8 pollopts;
1413
+ } lcb_DURABILITYOPTSv0;
1414
+
1415
+ /**@brief Options for lcb_endure3_ctxnew() (wrapper)
1416
+ * @see lcb_DURABILITYOPTSv0 */
1417
+ typedef struct lcb_durability_opts_st {
1418
+ int version;
1419
+ union {
1420
+ lcb_DURABILITYOPTSv0 v0;
1421
+ } v;
1422
+ } lcb_durability_opts_t;
1423
+
1424
+ /**Must specify this flag if using the 'mutation_token' field, as it was added in
1425
+ * a later version */
1426
+ #define LCB_CMDENDURE_F_MUTATION_TOKEN 1<<16
1427
+
1428
+ /**@brief Command structure for endure.
1429
+ * If the lcb_CMDENDURE::cas field is specified, the operation will check and
1430
+ * verify that the CAS found on each of the nodes matches the CAS specified
1431
+ * and only then consider the item to be replicated and/or persisted to the
1432
+ * nodes. If the item exists on the master's cache with a different CAS then
1433
+ * the operation will fail
1434
+ */
1435
+ typedef struct {
1436
+ LCB_CMD_BASE;
1437
+ const lcb_MUTATION_TOKEN *mutation_token;
1438
+ } lcb_CMDENDURE;
1439
+
1440
+ /**@brief Response structure for endure */
1441
+ typedef struct {
1442
+ LCB_RESP_BASE
1443
+ /**
1444
+ * Total number of polls (i.e. how many packets per server) did this
1445
+ * operation require
1446
+ */
1447
+ lcb_U16 nresponses;
1448
+
1449
+ /**
1450
+ * Whether this item exists in the master in its current form. This can be
1451
+ * true even if #rc is not successful
1452
+ */
1453
+ lcb_U8 exists_master;
1454
+
1455
+ /**
1456
+ * True if item was persisted on the master node. This may be true even if
1457
+ * #rc is not successful.
1458
+ */
1459
+ lcb_U8 persisted_master;
1460
+
1461
+ /**
1462
+ * Total number of nodes (including master) on which this mutation has
1463
+ * been persisted. Valid even if #rc is not successful.
1464
+ */
1465
+ lcb_U8 npersisted;
1466
+
1467
+ /**
1468
+ * Total number of replica nodes to which this mutation has been replicated.
1469
+ * Valid even if #rc is not successful.
1470
+ */
1471
+ lcb_U8 nreplicated;
1472
+ } lcb_RESPENDURE;
1473
+
1474
+ /**
1475
+ * @committed
1476
+ *
1477
+ * @details
1478
+ * Ensure a key is replicated to a set of nodes
1479
+ *
1480
+ * The lcb_endure3_ctxnew() API is used to wait asynchronously until the item
1481
+ * have been persisted and/or replicated to at least the number of nodes
1482
+ * specified in the durability options.
1483
+ *
1484
+ * The command is implemented by sending a series of `OBSERVE` broadcasts
1485
+ * (see lcb_observe3_ctxnew()) to all the nodes in the cluster which are either
1486
+ * master or replica for a specific key. It polls repeatedly
1487
+ * (see lcb_DURABILITYOPTSv0::interval) until all the items have been persisted and/or
1488
+ * replicated to the number of nodes specified in the criteria, or the timeout
1489
+ * (aee lcb_DURABILITYOPTsv0::timeout) has been reached.
1490
+ *
1491
+ * The lcb_DURABILITYOPTSv0::persist_to and lcb_DURABILITYOPTS::replicate_to
1492
+ * control the number of nodes the item must be persisted/replicated to
1493
+ * in order for the durability polling to succeed.
1494
+ *
1495
+ * @brief Return a new command context for scheduling endure operations
1496
+ * @param instance the instance
1497
+ * @param options a structure containing the various criteria needed for
1498
+ * durability requirements
1499
+ * @param[out] err Error code if a new context could not be created
1500
+ * @return the new context, or NULL on error. Note that in addition to memory
1501
+ * allocation failure, this function might also return NULL because the `options`
1502
+ * structure contained bad values. Always check the `err` result.
1503
+ *
1504
+ * @par Scheduling Errors
1505
+ * The following errors may be encountered when scheduling:
1506
+ *
1507
+ * @cb_err ::LCB_DURABILITY_ETOOMANY if either lcb_DURABILITYOPTS::persist_to or
1508
+ * lcb_DURABILITYOPTS::replicate_to is too big. `err` may indicate this.
1509
+ * @cb_err ::LCB_DURABILITY_NO_MUTATION_TOKENS if no relevant mutation token
1510
+ * could be found for a given command (this is returned from the relevant
1511
+ * lcb_MULTICMD_CTX::addcmd call).
1512
+ * @cb_err ::LCB_DUPLICATE_COMMANDS if using CAS-based durability and the
1513
+ * same key was submitted twice to lcb_MULTICMD_CTX::addcmd(). This error is
1514
+ * returned from lcb_MULTICMD_CTX::done()
1515
+ *
1516
+ * @par Callback Errors
1517
+ * The following errors may be returned in the callback:
1518
+ * @cb_err ::LCB_ETIMEDOUT if the criteria could not be verified within the
1519
+ * accepted timeframe (see lcb_DURABILITYOPTSv0::timeout)
1520
+ * @cb_err ::LCB_KEY_EEXISTS if using CAS-based durability and the item's
1521
+ * CAS has been changed on the master node
1522
+ * @cb_err ::LCB_MUTATION_LOST if using sequence-based durability and the
1523
+ * server has detected that data loss has occurred due to a failover.
1524
+ *
1525
+ * @par Creating request context
1526
+ * @code{.c}
1527
+ * lcb_durability_opts_t dopts;
1528
+ * lcb_error_t rc;
1529
+ * memset(&dopts, 0, sizeof dopts);
1530
+ * dopts.v.v0.persist_to = -1;
1531
+ * dopts.v.v0.replicate_to = -1;
1532
+ * dopts.v.v0.cap_max = 1;
1533
+ * mctx = lcb_endure3_ctxnew(instance, &dopts, &rc);
1534
+ * // Check mctx != NULL and rc == LCB_SUCCESS
1535
+ * @endcode
1536
+ *
1537
+ * @par Adding keys - CAS
1538
+ * This can be used to add keys using CAS-based durability. This shows an
1539
+ * example within a store callback.
1540
+ * @code{.c}
1541
+ * lcb_RESPSTORE *resp = get_store_response();
1542
+ * lcb_CMDENDURE cmd = { 0 };
1543
+ * LCB_CMD_SET_KEY(&cmd, resp->key, resp->nkey);
1544
+ * cmd.cas = resp->cas;
1545
+ * rc = mctx->addcmd(mctx, (const lcb_CMDBASE*)&cmd);
1546
+ * rc = mctx->done(mctx, cookie);
1547
+ * @endcode
1548
+ *
1549
+ * @par Adding keys - explicit sequence number
1550
+ * Shows how to use an explicit sequence number as a basis for polling
1551
+ * @code{.c}
1552
+ * // during instance creation:
1553
+ * lcb_cntl_string(instance, "fetch_mutation_tokens", "true");
1554
+ * lcb_connect(instance);
1555
+ * // ...
1556
+ * lcb_RESPSTORE *resp = get_store_response();
1557
+ * lcb_CMDENDURE cmd = { 0 };
1558
+ * LCB_CMD_SET_KEY(&cmd, resp->key, resp->nkey);
1559
+ * cmd.mutation_token = &resp->mutation_token;
1560
+ * cmd.cmdflags |= LCB_CMDENDURE_F_MUTATION_TOKEN;
1561
+ * rc = mctx->addcmd(mctx, (const lcb_CMDBASE*)&cmd);
1562
+ * rc = mctx->done(mctx, cookie);
1563
+ * @endcode
1564
+ *
1565
+ * @par Adding keys - implicit sequence number
1566
+ * Shows how to use an implicit mutation token (internally tracked by the
1567
+ * library) for durability:
1568
+ * @code{.c}
1569
+ * // during instance creation
1570
+ * lcb_cntl_string(instance, "fetch_mutation_tokens", "true");
1571
+ * lcb_cntl_string(instance, "dur_mutation_tokens", "true");
1572
+ * lcb_connect(instance);
1573
+ * // ...
1574
+ * lcb_CMDENDURE cmd = { 0 };
1575
+ * LCB_CMD_SET_KEY(&cmd, "key", strlen("key"));
1576
+ * mctx->addcmd(mctx, (const lcb_CMDBASE*)&cmd);
1577
+ * mctx->done(mctx, cookie);
1578
+ * @endcode
1579
+ *
1580
+ * @par Response
1581
+ * @code{.c}
1582
+ * lcb_install_callback3(instance, LCB_CALLBACK_ENDURE, dur_callback);
1583
+ * void dur_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
1584
+ * {
1585
+ * const lcb_RESPENDURE *resp = (const lcb_RESPENDURE*)rb;
1586
+ * printf("Durability polling result for %.*s.. ", (int)resp->nkey, resp->key);
1587
+ * if (resp->rc != LCB_SUCCESS) {
1588
+ * printf("Failed: %s\n", lcb_strerror(NULL, resp->rc);
1589
+ * return;
1590
+ * }
1591
+ * }
1592
+ * @endcode
1593
+ */
1594
+ LIBCOUCHBASE_API
1595
+ lcb_MULTICMD_CTX *
1596
+ lcb_endure3_ctxnew(lcb_t instance,
1597
+ const lcb_durability_opts_t *options, lcb_error_t *err);
1598
+
1599
+ /**
1600
+ * Command structure for lcb_storedur3()
1601
+ * This is much like @ref lcb_CMDSTORE, but also includes durability options.
1602
+ */
1603
+ typedef struct {
1604
+ LCB_CMD_BASE;
1605
+ lcb_VALBUF value; /**< @see lcb_CMDSTORE::value */
1606
+ lcb_U32 flags; /**< @see lcb_CMDSTORE::flags */
1607
+ lcb_datatype_t datatype; /**< @private */
1608
+ lcb_storage_t operation; /**< @see lcb_CMDSTORE::operation */
1609
+
1610
+ /**
1611
+ * Number of nodes to persist to. If negative, will be capped at the maximum
1612
+ * allowable for the current cluster.
1613
+ * @see lcb_DURABILITYOPTSv0::persist_to
1614
+ */
1615
+ char persist_to;
1616
+
1617
+ /**
1618
+ * Number of nodes to replicate to. If negative, will be capped at the maximum
1619
+ * allowable for the current cluster.
1620
+ * @see lcb_DURABILITYOPTSv0::replicate_to
1621
+ */
1622
+ char replicate_to;
1623
+ } lcb_CMDSTOREDUR;
1624
+
1625
+ /**
1626
+ * Response structure for `LCB_CALLBACK_STOREDUR.
1627
+ */
1628
+ typedef struct {
1629
+ LCB_RESP_BASE
1630
+ /** Internal durability response structure. This should never be NULL */
1631
+ const lcb_RESPENDURE *dur_resp;
1632
+
1633
+ /**If the #rc field is not @ref LCB_SUCCESS, this field indicates
1634
+ * what failed. If this field is nonzero, then the store operation failed,
1635
+ * but the durability checking failed. If this field is zero then the
1636
+ * actual storage operation failed. */
1637
+ int store_ok;
1638
+ } lcb_RESPSTOREDUR;
1639
+
1640
+ /**
1641
+ * @volatile
1642
+ *
1643
+ * Schedule a storage operation with subsequent durability checking.
1644
+ *
1645
+ * This is a compound of a logical lcb_store3() followed by an
1646
+ * lcb_endure3_ctxnew() upon success.
1647
+ */
1648
+ LIBCOUCHBASE_API
1649
+ lcb_error_t
1650
+ lcb_storedur3(lcb_t instance, const void *cookie, const lcb_CMDSTOREDUR *cmd);
1651
+
1652
+ #define LCB_DURABILITY_VALIDATE_CAPMAX 1<<1
1653
+
1654
+ /**
1655
+ * @committed
1656
+ *
1657
+ * Validate durability settings.
1658
+ *
1659
+ * This function will validate (and optionally modify) the settings. This is
1660
+ * helpful to ensure the durability options are valid _before_ issuing a command
1661
+ *
1662
+ * @param instance the instance
1663
+ *
1664
+ * @param[in,out] persist_to The desired number of servers to persist to.
1665
+ * If the `CAPMAX` flag is set, on output this will contain the effective
1666
+ * number of servers the item can be persisted to
1667
+ *
1668
+ * @param[in,out] replicate_to The desired number of servers to replicate to.
1669
+ * If the `CAPMAX` flag is set, on output this will contain the effective
1670
+ * number of servers the item can be replicated to
1671
+ *
1672
+ * @param options Options to use for validating. The only recognized option
1673
+ * is currently `LCB_DURABILITY_VALIDATE_CAPMAX` which has the same semantics
1674
+ * as lcb_DURABILITYOPTSv0::cap_max.
1675
+ *
1676
+ * @return LCB_SUCCESS on success
1677
+ * @return LCB_DURABILITY_ETOOMANY if the requirements exceed the number of
1678
+ * servers currently available, and `CAPMAX` was not specifie
1679
+ * @return LCB_EINVAL if both `persist_to` and `replicate_to` are 0.
1680
+ */
1681
+ LIBCOUCHBASE_API
1682
+ lcb_error_t
1683
+ lcb_durability_validate(lcb_t instance,
1684
+ lcb_U16 *persist_to, lcb_U16 *replicate_to, int options);
1685
+ /**@} (NAME) */
1686
+
1687
+
1688
+ /**
1689
+ * @name Retrieve current persistence/replication status
1690
+ * @{
1691
+ */
1692
+
1693
+ /**Set this bit in the cmdflags field to indicate that only the master node
1694
+ * should be contacted*/
1695
+ #define LCB_CMDOBSERVE_F_MASTER_ONLY 1<<16
1696
+
1697
+ /**@brief Structure for an observe request.
1698
+ * To request the status from _only_ the master node of the key, set the
1699
+ * LCB_CMDOBSERVE_F_MASTERONLY bit inside the lcb_CMDOBSERVE::cmdflags field
1700
+ */
1701
+ typedef struct {
1702
+ LCB_CMD_BASE;
1703
+ /**For internal use: This determines the servers the command should be
1704
+ * routed to. Each entry is an index within the server. */
1705
+ const lcb_U16* servers_;
1706
+ size_t nservers_;
1707
+ } lcb_CMDOBSERVE;
1708
+
1709
+ /**
1710
+ * @brief Possible statuses for keys in OBSERVE response
1711
+ */
1712
+ typedef enum {
1713
+ /** The item found in the memory, but not yet on the disk */
1714
+ LCB_OBSERVE_FOUND = 0x00,
1715
+ /** The item hit the disk */
1716
+ LCB_OBSERVE_PERSISTED = 0x01,
1717
+ /** The item missing on the disk and the memory */
1718
+ LCB_OBSERVE_NOT_FOUND = 0x80,
1719
+ /** No knowledge of the key :) */
1720
+ LCB_OBSERVE_LOGICALLY_DELETED = 0x81,
1721
+
1722
+ LCB_OBSERVE_MAX = 0x82
1723
+ } lcb_observe_t;
1724
+
1725
+ /**@brief Response structure for an observe command.
1726
+ * Note that the lcb_RESPOBSERVE::cas contains the CAS of the item as it is
1727
+ * stored within that specific server. The CAS may be incorrect or stale
1728
+ * unless lcb_RESPOBSERVE::ismaster is true.
1729
+ */
1730
+ typedef struct {
1731
+ LCB_RESP_BASE
1732
+ lcb_U8 status; /**<Bit set of flags */
1733
+ lcb_U8 ismaster; /**< Set to true if this response came from the master node */
1734
+ lcb_U32 ttp; /**<Unused. For internal requests, contains the server index */
1735
+ lcb_U32 ttr; /**<Unused */
1736
+ } lcb_RESPOBSERVE;
1737
+
1738
+ /**@committed
1739
+ * @brief Create a new multi context for an observe operation
1740
+ * @param instance the instance
1741
+ * @return a new multi command context, or NULL on allocation failure.
1742
+ *
1743
+ * Note that the callback for this command will be invoked multiple times,
1744
+ * one for each node. To determine when no more callbacks will be invoked,
1745
+ * check for the LCB_RESP_F_FINAL flag inside the lcb_RESPOBSERVE::rflags
1746
+ * field.
1747
+ *
1748
+ * @code{.c}
1749
+ * void callback(lcb_t, lcb_CALLBACKTYPE, const lcb_RESPOBSERVE *resp)
1750
+ * {
1751
+ * if (resp->rflags & LCB_RESP_F_FINAL) {
1752
+ * return;
1753
+ * }
1754
+ *
1755
+ * printf("Got status for key %.*s\n", (int)resp->nkey, resp->key);
1756
+ * printf(" Node Type: %s\n", resp->ismaster ? "MASTER" : "REPLICA");
1757
+ * printf(" Status: 0x%x\n", resp->status);
1758
+ * printf(" Current CAS: 0x%"PRIx64"\n", resp->cas);
1759
+ * }
1760
+ *
1761
+ * lcb_MULTICMD_CTX *mctx = lcb_observe3_ctxnew(instance);
1762
+ * lcb_CMDOBSERVE cmd = { 0 };
1763
+ * LCB_CMD_SET_KEY(&cmd, "key", 3);
1764
+ * mctx->addcmd(mctx, (lcb_CMDBASE *)&cmd);
1765
+ * mctx->done(mctx, cookie);
1766
+ * lcb_install_callback3(instance, LCB_CALLBACK_OBSERVE, (lcb_RESP_cb)callback);
1767
+ * @endcode
1768
+ *
1769
+ * @warning
1770
+ * Operations created by observe cannot be undone using lcb_sched_fail().
1771
+ */
1772
+ LIBCOUCHBASE_API
1773
+ lcb_MULTICMD_CTX *
1774
+ lcb_observe3_ctxnew(lcb_t instance);
1775
+
1776
+ /**
1777
+ * @brief Command structure for lcb_observe_seqno3().
1778
+ * Note #key, #nkey, and #cas are not used in this command.
1779
+ */
1780
+ typedef struct {
1781
+ LCB_CMD_BASE;
1782
+ /**
1783
+ * Server index to target. The server index must be valid and must also
1784
+ * be either a master or a replica for the vBucket indicated in #vbid
1785
+ */
1786
+ lcb_U16 server_index;
1787
+ lcb_U16 vbid; /**< vBucket ID to query */
1788
+ lcb_U64 uuid; /**< UUID known to client which should be queried */
1789
+ } lcb_CMDOBSEQNO;
1790
+
1791
+ /**
1792
+ * @brief Response structure for lcb_observe_seqno3()
1793
+ *
1794
+ * Note that #key, #nkey and #cas are empty because the operand is the relevant
1795
+ * mutation token fields in @ref lcb_CMDOBSEQNO
1796
+ */
1797
+ typedef struct {
1798
+ LCB_RESP_BASE
1799
+ lcb_U16 vbid; /**< vBucket ID (for potential mapping) */
1800
+ lcb_U16 server_index; /**< Input server index */
1801
+ lcb_U64 cur_uuid; /**< UUID for this vBucket as known to the server */
1802
+ lcb_U64 persisted_seqno; /**< Highest persisted sequence */
1803
+ lcb_U64 mem_seqno; /**< Highest known sequence */
1804
+
1805
+ /**
1806
+ * In the case where the command's uuid is not the most current, this
1807
+ * contains the last known UUID
1808
+ */
1809
+ lcb_U64 old_uuid;
1810
+
1811
+ /**
1812
+ * If #old_uuid is nonzero, contains the highest sequence number persisted
1813
+ * in the #old_uuid snapshot.
1814
+ */
1815
+ lcb_U64 old_seqno;
1816
+ } lcb_RESPOBSEQNO;
1817
+
1818
+ /**
1819
+ * @volatile
1820
+ * @brief Get the persistence/replication status for a given mutation token
1821
+ * @param instance the handle
1822
+ * @param cookie callback cookie
1823
+ * @param cmd the command
1824
+ */
1825
+ LIBCOUCHBASE_API
1826
+ lcb_error_t
1827
+ lcb_observe_seqno3(lcb_t instance, const void *cookie, const lcb_CMDOBSEQNO *cmd);
1828
+
1829
+ /**@} (Name: OBSERVE) */
1830
+ /**@} (Group: Durability) */
1831
+
1832
+ /**
1833
+ * @ingroup lcb-public-api
1834
+ * @defgroup lcb-mutation-tokens Mutation Tokens
1835
+ *
1836
+ * @details Mutation Tokens are returned with mutations if
1837
+ * ::LCB_CNTL_FETCH_MUTATION_TOKENS is enabled (off by default). Mutation tokens
1838
+ * are largely of internal use, but can be used by N1QL queries and durability
1839
+ * requirement polling
1840
+ *
1841
+ * @addtogroup lcb-mutation-tokens
1842
+ * @{
1843
+ */
1844
+
1845
+ /**
1846
+ * @brief
1847
+ * Structure representing a synchronization token. This token may be used
1848
+ * for durability operations and N1QL queries. The contents of this structure
1849
+ * should be considered opaque, and accessed via the various macros
1850
+ * @struct lcb_MUTATION_TOKEN
1851
+ */
1852
+
1853
+ /** Get the vBucket UUID */
1854
+ #define LCB_MUTATION_TOKEN_ID(p) (p)->uuid_
1855
+ /** Get the sequence number */
1856
+ #define LCB_MUTATION_TOKEN_SEQ(p) (p)->seqno_
1857
+ /** Get the vBucket number itself */
1858
+ #define LCB_MUTATION_TOKEN_VB(p) (p)->vbid_
1859
+ /** Whether this mutation token has valid contents */
1860
+ #define LCB_MUTATION_TOKEN_ISVALID(p) \
1861
+ (p && !((p)->uuid_ == 0 && (p)->seqno_ == 0 && (p)->vbid_ == 0))
1862
+
1863
+ /**
1864
+ * Retrieves the mutation token from the response structure
1865
+ * @param cbtype the type of callback invoked
1866
+ * @param rb the pointer to the response
1867
+ * @return The embedded mutation token, or NULL if the response does not have a
1868
+ * mutation token. This may be either because the command does not support
1869
+ * mutation tokens, or because they have been disabled at the connection
1870
+ * level.
1871
+ */
1872
+ LIBCOUCHBASE_API
1873
+ const lcb_MUTATION_TOKEN *
1874
+ lcb_resp_get_mutation_token(int cbtype, const lcb_RESPBASE *rb);
1875
+
1876
+ /**
1877
+ * @volatile
1878
+ *
1879
+ * Retrieves the last mutation token for a given key.
1880
+ * This relies on the @ref LCB_CNTL_DURABILITY_MUTATION_TOKENS option, and will
1881
+ * check the instance-level log to determine the latest MUTATION_TOKEN for
1882
+ * the given vBucket ID which the key maps to.
1883
+ *
1884
+ * @param instance the instance
1885
+ * @param kb The buffer representing the key. The type of the buffer (see
1886
+ * lcb_KEYBUF::type) may either be ::LCB_KV_COPY or ::LCB_KV_VBID
1887
+ * @param[out] errp Set to an error if this function returns NULL
1888
+ * @return The mutation token if successful, otherwise NULL.
1889
+ *
1890
+ * Getting the latest mutation token for a key:
1891
+ *
1892
+ * @code{.c}
1893
+ * lcb_KEYBUF kb;
1894
+ * kb.type = LCB_KV_COPY;
1895
+ * kb.contig.bytes = "Hello";
1896
+ * kv.config.nbytes = 5;
1897
+ * mt = lcb_get_mutation_token(instance, &kb, &rc);
1898
+ * @endcode
1899
+ *
1900
+ * Getting the latest mutation token for a vbucket:
1901
+ * @code{.c}
1902
+ * lcb_KEYBUF kb;
1903
+ * kv.type = LCB_KV_VBID;
1904
+ * kv.contig.nbytes = 543;
1905
+ * kv.config.bytes = NULL;
1906
+ * mt = lcb_get_mutation_token(instance, &kb, &rc);
1907
+ * @endcode
1908
+ *
1909
+ * Getting the mutation token for each vbucket
1910
+ * @code{.c}
1911
+ * size_t ii, nvb;
1912
+ * lcbvb_CONFIG *vbc;
1913
+ * lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_VBCONFIG, &vbc);
1914
+ * nvb = vbucket_get_num_vbuckets(vbc);
1915
+ * for (ii = 0; ii < nvb; ii++) {
1916
+ * lcb_KEYBUF kb;
1917
+ * const lcb_MUTATION_TOKEN *mt;
1918
+ * kb.type = LCB_KV_VBID;
1919
+ * kb.contig.nbytes = ii;
1920
+ * kb.config.bytes = NULL;
1921
+ * mt = lcb_get_mutation_token(instance, &kb, &rc);
1922
+ * }
1923
+ * @endcode
1924
+ */
1925
+ LIBCOUCHBASE_API
1926
+ const lcb_MUTATION_TOKEN *
1927
+ lcb_get_mutation_token(lcb_t instance, const lcb_KEYBUF *kb, lcb_error_t *errp);
1928
+
1929
+ /**@} (Group: Mutation Tokens) */
1930
+
1931
+ /**@ingroup lcb-kv-api
1932
+ * @defgroup lcb-counter Counters
1933
+ * @brief Manipulate the numeric content of a document
1934
+ * @details Counter operations treat the document being accessed as a numeric
1935
+ * value (the document should contain a parseable integer as its content). This
1936
+ * value may then be incremented or decremented.
1937
+ *
1938
+ * @addtogroup lcb-counter
1939
+ * @{
1940
+ */
1941
+
1942
+ /**@brief Command for counter operations.
1943
+ * @see lcb_counter3(), lcb_RESPCOUNTER.
1944
+ *
1945
+ * @warning You may only set the #exptime member if the #create member is set
1946
+ * to a true value. Setting `exptime` otherwise will cause the operation to
1947
+ * fail with @ref LCB_OPTIONS_CONFLICT
1948
+ *
1949
+ * @warning The #cas member should be set to 0 for this operation. As this
1950
+ * operation itself is atomic, specifying a CAS is not necessary.
1951
+ */
1952
+ typedef struct {
1953
+ LCB_CMD_BASE;
1954
+ /**Delta value. If this number is negative the item on the server is
1955
+ * decremented. If this number is positive then the item on the server
1956
+ * is incremented */
1957
+ lcb_int64_t delta;
1958
+ /**If the item does not exist on the server (and `create` is true) then
1959
+ * this will be the initial value for the item. */
1960
+ lcb_U64 initial;
1961
+ /**Boolean value. Create the item and set it to `initial` if it does not
1962
+ * already exist */
1963
+ int create;
1964
+ } lcb_CMDCOUNTER;
1965
+
1966
+ /**@brief Response structure for counter operations
1967
+ * @see lcb_counter3()
1968
+ */
1969
+ typedef struct {
1970
+ LCB_RESP_BASE
1971
+ /** Contains the _current_ value after the operation was performed */
1972
+ lcb_U64 value;
1973
+ } lcb_RESPCOUNTER;
1974
+
1975
+ /**@committed
1976
+ * @brief Schedule single counter operation
1977
+ * @param instance the instance
1978
+ * @param cookie the pointer to associate with the request
1979
+ * @param cmd the command to use
1980
+ * @return LCB_SUCCESS on success, other error on failure
1981
+ *
1982
+ * @par Request
1983
+ * @code{.c}
1984
+ * lcb_CMDCOUNTER cmd = { 0 };
1985
+ * LCB_CMD_SET_KEY(&cmd, "counter", strlen("counter"));
1986
+ * cmd.delta = 1; // Increment by one
1987
+ * cmd.initial = 42; // Default value is 42 if it does not exist
1988
+ * cmd.exptime = 300; // Expire in 5 minutes
1989
+ * lcb_counter3(instance, NULL, &cmd);
1990
+ * lcb_wait3(instance, LCB_WAIT_NOCHECK);
1991
+ * @endcode
1992
+ *
1993
+ * @par Response
1994
+ * @code{.c}
1995
+ * lcb_install_callback3(instance, LCB_CALLBACKTYPE_COUNTER, counter_cb);
1996
+ * void counter_cb(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
1997
+ * {
1998
+ * const lcb_RESPCOUNTER *resp = (const lcb_RESPCOUNTER *)rb;
1999
+ * if (resp->rc == LCB_SUCCESS) {
2000
+ * printf("Incremented counter for %.*s. Current value %llu\n",
2001
+ * (int)resp->nkey, resp->key, resp->value);
2002
+ * }
2003
+ * }
2004
+ * @endcode
2005
+ *
2006
+ * @par Callback Errors
2007
+ * In addition to generic errors, the following errors may be returned in the
2008
+ * callback (via lcb_RESPBASE::rc):
2009
+ *
2010
+ * @cb_err ::LCB_KEY_ENOENT if the counter doesn't exist
2011
+ * (and lcb_CMDCOUNTER::create was not set)
2012
+ * @cb_err ::LCB_DELTA_BADVAL if the existing document's content could not
2013
+ * be parsed as a number by the server.
2014
+ */
2015
+ LIBCOUCHBASE_API
2016
+ lcb_error_t
2017
+ lcb_counter3(lcb_t instance, const void *cookie, const lcb_CMDCOUNTER *cmd);
2018
+ /**@} (Group: Counter) */
2019
+
2020
+ /**@ingroup lcb-kv-api
2021
+ * @defgroup lcb-lock Lock/Unlock
2022
+ * @details Documents may be locked and unlocked on the server. While a document
2023
+ * is locked, any attempt to modify it (or lock it again) will fail.
2024
+ *
2025
+ * @note Locks are not persistent across nodes (if a node fails over, the lock
2026
+ * is not transferred to a replica).
2027
+ * @note The recommended way to manage access and concurrency control for
2028
+ * documents in Couchbase is through the CAS (See lcb_CMDBASE::cas and
2029
+ * lcb_RESPBASE::cas), which can also be considered a form of opportunistic
2030
+ * locking.
2031
+ *
2032
+ * @par Locking an item
2033
+ * There is no exclusive function to lock an item. Locking an item is done
2034
+ * using @ref lcb_get3(), by setting the lcb_CMDGET::lock option to true.
2035
+ *
2036
+ * @addtogroup lcb-lock
2037
+ * @{
2038
+ */
2039
+
2040
+ /**@brief Command for lcb_unlock3()
2041
+ * @attention lcb_CMDBASE::cas must be specified, or the operation will fail on
2042
+ * the server*/
2043
+ typedef lcb_CMDBASE lcb_CMDUNLOCK;
2044
+
2045
+ /**@brief Response structure for an unlock command.
2046
+ * @note the lcb_RESPBASE::cas field does not contain the CAS of the item*/
2047
+ typedef lcb_RESPBASE lcb_RESPUNLOCK;
2048
+
2049
+ /**
2050
+ * @committed
2051
+ * @brief
2052
+ * Unlock a previously locked item using lcb_CMDGET::lock
2053
+ *
2054
+ * @param instance the instance
2055
+ * @param cookie the context pointer to associate with the command
2056
+ * @param cmd the command containing the information about the locked key
2057
+ * @return LCB_SUCCESS if successful, an error code otherwise
2058
+ * @see lcb_get3()
2059
+ *
2060
+ * @par Request
2061
+ *
2062
+ * @code{.c}
2063
+ * void locked_callback(lcb_t, lcb_CALLBACKTYPE, const lcb_RESPBASE *resp) {
2064
+ * lcb_CMDUNLOCK cmd = { 0 };
2065
+ * LCB_CMD_SET_KEY(&cmd, resp->key, resp->nkey);
2066
+ * cmd.cas = resp->cas;
2067
+ * lcb_unlock3(instance, cookie, &cmd);
2068
+ * }
2069
+ *
2070
+ * @endcode
2071
+ */
2072
+ LIBCOUCHBASE_API
2073
+ lcb_error_t
2074
+ lcb_unlock3(lcb_t instance, const void *cookie, const lcb_CMDUNLOCK *cmd);
2075
+ /**@} (Group: Unlock) */
2076
+
2077
+ /**@ingroup lcb-kv-api
2078
+ * @defgroup lcb-touch Touch/Expiry
2079
+ * @brief Modify or clear a document's expiration time
2080
+ * @details Couchbase allows documents to contain expiration times
2081
+ * (see lcb_CMDBASE::exptime). Most operations allow the expiry time to be
2082
+ * updated, however lcb_touch3() allows the exclusive update of the expiration
2083
+ * time without additional network overhead.
2084
+ *
2085
+ * @addtogroup lcb-touch
2086
+ * @{
2087
+ */
2088
+
2089
+ /**
2090
+ * @brief Command structure for a touch request
2091
+ * @note The lcb_CMDTOUCH::cas field is ignored. The item's modification time
2092
+ * is always updated regardless if the CAS on the server differs.
2093
+ * The #exptime field is always used. If 0 then the expiry on the server is
2094
+ * cleared.
2095
+ */
2096
+ typedef lcb_CMDBASE lcb_CMDTOUCH;
2097
+
2098
+ /**@brief Response structure for a touch request
2099
+ * @note the lcb_RESPTOUCH::cas field contains the current CAS of the item*/
2100
+ typedef lcb_RESPBASE lcb_RESPTOUCH;
2101
+
2102
+ /**@committed
2103
+ * @brief Spool a touch request
2104
+ * @param instance the handle
2105
+ * @param cookie the pointer to associate with the request
2106
+ * @param cmd the command
2107
+ * @return LCB_SUCCESS on success, other error code on failure
2108
+ *
2109
+ * @par Request
2110
+ * @code{.c}
2111
+ * lcb_CMDTOUCH cmd = { 0 };
2112
+ * LCB_CMD_SET_KEY(&cmd, "keep_me", strlen("keep_me"));
2113
+ * cmd.exptime = 0; // Clear the expiration
2114
+ * lcb_touch3(instance, cookie, &cmd);
2115
+ * @endcode
2116
+ *
2117
+ * @par Response
2118
+ * @code{.c}
2119
+ * lcb_install_callback3(instance, LCB_CALLBACK_TOUCH, touch_callback);
2120
+ * void touch_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
2121
+ * {
2122
+ * if (rb->rc == LCB_SUCCESS) {
2123
+ * printf("Touch succeeded\n");
2124
+ * }
2125
+ * }
2126
+ * @endcode
2127
+ */
2128
+ LIBCOUCHBASE_API
2129
+ lcb_error_t
2130
+ lcb_touch3(lcb_t instance, const void *cookie, const lcb_CMDTOUCH *cmd);
2131
+ /**@} (Group: Touch) */
2132
+ /**@} (Group: KV API) */
2133
+
2134
+ /**@ingroup lcb-public-api
2135
+ * @defgroup lcb-misc-cmds Miscellaneous Commands
2136
+ * @brief Additional miscellaneous commands which can be executed on the server.
2137
+ *
2138
+ * @addtogroup lcb-misc-cmds
2139
+ * @{
2140
+ */
2141
+
2142
+ /**
2143
+ * @name Server Statistics
2144
+ * @{
2145
+ */
2146
+
2147
+ /**
2148
+ * @brief Command structure for stats request
2149
+ * The lcb_CMDSTATS::key field should contain the statistics key, or be empty
2150
+ * if the default statistics are desired.
2151
+ * The #cmdflags field may contain the @ref LCB_CMDSTATS_F_KV flag.
2152
+ */
2153
+ typedef lcb_CMDBASE lcb_CMDSTATS;
2154
+
2155
+ /**
2156
+ * The key is a stored item for which statistics should be retrieved. This
2157
+ * invokes the 'keystats' semantics. Note that when using _keystats_, a key
2158
+ * must be present, and must not have any spaces in it.
2159
+ */
2160
+ #define LCB_CMDSTATS_F_KV (1 << 16)
2161
+
2162
+ /**@brief Response structure for cluster statistics.
2163
+ * The lcb_RESPSTATS::key field contains the statistic name (_not_ the same
2164
+ * as was passed in lcb_CMDSTATS::key which is the name of the statistical
2165
+ * _group_).*/
2166
+ typedef struct {
2167
+ LCB_RESP_BASE
2168
+ LCB_RESP_SERVER_FIELDS
2169
+ const char *value; /**< The value, if any, for the given statistic */
2170
+ lcb_SIZE nvalue; /**< Length of value */
2171
+ } lcb_RESPSTATS;
2172
+
2173
+ /**@committed
2174
+ * @brief Schedule a request for statistics from the cluster.
2175
+ * @param instance the instance
2176
+ * @param cookie pointer to associate with the request
2177
+ * @param cmd the command
2178
+ * @return LCB_SUCCESS on success, other error code on failure.
2179
+ *
2180
+ * Note that the callback for this command is invoked an indeterminate amount
2181
+ * of times. The callback is invoked once for each statistic for each server.
2182
+ * When all the servers have responded with their statistics, a final callback
2183
+ * is delivered to the application with the LCB_RESP_F_FINAL flag set in the
2184
+ * lcb_RESPSTATS::rflags field. When this response is received no more callbacks
2185
+ * for this command shall be invoked.
2186
+ *
2187
+ * @par Request
2188
+ * @code{.c}
2189
+ * lcb_CMDSTATS cmd = { 0 };
2190
+ * // Using default stats, no further initialization
2191
+ * lcb_stats3(instance, fp, &cmd);
2192
+ * lcb_wait(instance);
2193
+ * @endcode
2194
+ *
2195
+ * @par Response
2196
+ * @code{.c}
2197
+ * lcb_install_callback3(instance, LCB_CALLBACK_STATS, stats_callback);
2198
+ * void stats_callback(lcb_t, int, const lcb_RESPBASE *rb)
2199
+ * {
2200
+ * const lcb_RESPSTATS *resp = (const lcb_RESPSTATS*)rb;
2201
+ * if (resp->key) {
2202
+ * printf("Server %s: %.*s = %.*s\n", resp->server,
2203
+ * (int)resp->nkey, resp->key,
2204
+ * (int)resp->nvalue, resp->value);
2205
+ * }
2206
+ * if (resp->rflags & LCB_RESP_F_FINAL) {
2207
+ * printf("No more replies remaining!\n");
2208
+ * }
2209
+ * }
2210
+ * @endcode
2211
+ */
2212
+ LIBCOUCHBASE_API
2213
+ lcb_error_t
2214
+ lcb_stats3(lcb_t instance, const void *cookie, const lcb_CMDSTATS * cmd);
2215
+ /**@} (Name: Stats) */
2216
+
2217
+ /**@name Server Versions
2218
+ * @warning This does not return the actual _Couchbase_ version but rather
2219
+ * the internal version of the memcached server.
2220
+ * @{
2221
+ */
2222
+
2223
+ /**@brief Response structure for the version command */
2224
+ typedef struct {
2225
+ LCB_RESP_BASE
2226
+ LCB_RESP_SERVER_FIELDS
2227
+ const char *mcversion; /**< The version string */
2228
+ lcb_SIZE nversion; /**< Length of the version string */
2229
+ } lcb_RESPMCVERSION;
2230
+
2231
+ /**@volatile*/
2232
+ LIBCOUCHBASE_API
2233
+ lcb_error_t
2234
+ lcb_server_versions3(lcb_t instance, const void *cookie, const lcb_CMDBASE * cmd);
2235
+
2236
+ /**@} (Name: MCversion) */
2237
+
2238
+ /**@name Server Log Verbosity
2239
+ * @{
2240
+ */
2241
+
2242
+ /** @brief `level` field for lcb_server_verbosity3 () */
2243
+ typedef enum {
2244
+ LCB_VERBOSITY_DETAIL = 0x00,
2245
+ LCB_VERBOSITY_DEBUG = 0x01,
2246
+ LCB_VERBOSITY_INFO = 0x02,
2247
+ LCB_VERBOSITY_WARNING = 0x03
2248
+ } lcb_verbosity_level_t;
2249
+
2250
+ typedef struct {
2251
+ /* unused */
2252
+ LCB_CMD_BASE;
2253
+ const char *server;
2254
+ lcb_verbosity_level_t level;
2255
+ } lcb_CMDVERBOSITY;
2256
+ typedef lcb_RESPSERVERBASE lcb_RESPVERBOSITY;
2257
+ /**@volatile*/
2258
+ LIBCOUCHBASE_API
2259
+ lcb_error_t
2260
+ lcb_server_verbosity3(lcb_t instance, const void *cookie, const lcb_CMDVERBOSITY *cmd);
2261
+ /**@} (Name: Verbosity) */
2262
+ /**@} (Group: Misc) */
2263
+
2264
+ /**@ingroup lcb-public-api
2265
+ * @defgroup lcb-flush Flush
2266
+ * @brief Clear the contents of a bucket
2267
+ *
2268
+ * Flush is useful for development environments (for example clearing a bucket
2269
+ * before running tests).
2270
+ *
2271
+ * @addtogroup lcb-flush
2272
+ * @{
2273
+ */
2274
+ typedef lcb_CMDBASE lcb_CMDCBFLUSH;
2275
+ typedef lcb_RESPBASE lcb_RESPCBFLUSH;
2276
+
2277
+ /**
2278
+ * @uncomitted
2279
+ *
2280
+ * Flush a bucket
2281
+ * This function will properly flush any type of bucket using the REST API
2282
+ * via HTTP. This may be used in a manner similar to the older lcb_flush3().
2283
+ *
2284
+ * The callback invoked under ::LCB_CALLBACK_CBFLUSH will be invoked with either
2285
+ * a success or failure status depending on the outcome of the operation. Note
2286
+ * that in order for lcb_cbflush3() to succeed, flush must already be enabled
2287
+ * on the bucket via the administrative interface.
2288
+ *
2289
+ * @param instance the library handle
2290
+ * @param cookie the cookie passed in the callback
2291
+ * @param cmd empty command structure. Currently there are no options for this
2292
+ * command.
2293
+ * @return status code for scheduling.
2294
+ *
2295
+ * @attention
2296
+ * Because this command is built using HTTP, this is not subject to operation
2297
+ * pipeline calls such as lcb_sched_enter()/lcb_sched_leave()
2298
+ */
2299
+ LIBCOUCHBASE_API
2300
+ lcb_error_t
2301
+ lcb_cbflush3(lcb_t instance, const void *cookie, const lcb_CMDCBFLUSH *cmd);
2302
+
2303
+
2304
+ typedef lcb_CMDBASE lcb_CMDFLUSH;
2305
+ typedef lcb_RESPSERVERBASE lcb_RESPFLUSH;
2306
+ /**
2307
+ * @volatile
2308
+ * @deprecated
2309
+ */
2310
+ LIBCOUCHBASE_API
2311
+ lcb_error_t
2312
+ lcb_flush3(lcb_t instance, const void *cookie, const lcb_CMDFLUSH *cmd);
2313
+ /**@} (Group: Flush) */
2314
+
2315
+ /**@ingroup lcb-public-api
2316
+ * @defgroup lcb-http HTTP Client
2317
+ * @brief Access Couchbase HTTP APIs
2318
+ * @details The low-level HTTP client may be used to access various HTTP-based
2319
+ * Couchbase APIs.
2320
+ *
2321
+ * Note that existing higher level APIs can be used for N1QL queries (see
2322
+ * @ref lcb-n1ql-api) and MapReduce view queries (see @ref lcb-view-api)
2323
+ *
2324
+ * @addtogroup lcb-http
2325
+ * @{
2326
+ */
2327
+
2328
+ /**
2329
+ * @brief The type of HTTP request to execute
2330
+ */
2331
+ typedef enum {
2332
+ /**
2333
+ * Execute a request against the bucket. The handle must be of
2334
+ * @ref LCB_TYPE_BUCKET and must be connected.
2335
+ */
2336
+ LCB_HTTP_TYPE_VIEW = 0,
2337
+
2338
+ /**
2339
+ * Execute a management API request. The credentials used will match
2340
+ * those passed during the instance creation time. Thus is the instance
2341
+ * type is @ref LCB_TYPE_BUCKET then only bucket-level credentials will
2342
+ * be used.
2343
+ */
2344
+ LCB_HTTP_TYPE_MANAGEMENT = 1,
2345
+
2346
+ /**
2347
+ * Execute an arbitrary request against a host and port
2348
+ */
2349
+ LCB_HTTP_TYPE_RAW = 2,
2350
+
2351
+ /** Execute an N1QL Query */
2352
+ LCB_HTTP_TYPE_N1QL = 3,
2353
+
2354
+ /** Search a fulltext index */
2355
+ LCB_HTTP_TYPE_FTS = 4,
2356
+
2357
+ LCB_HTTP_TYPE_MAX
2358
+ } lcb_http_type_t;
2359
+
2360
+ /**
2361
+ * @brief HTTP Request method enumeration
2362
+ * These just enumerate the various types of HTTP request methods supported.
2363
+ * Refer to the specific cluster or view API to see which method is appropriate
2364
+ * for your request
2365
+ */
2366
+ typedef enum {
2367
+ LCB_HTTP_METHOD_GET = 0,
2368
+ LCB_HTTP_METHOD_POST = 1,
2369
+ LCB_HTTP_METHOD_PUT = 2,
2370
+ LCB_HTTP_METHOD_DELETE = 3,
2371
+ LCB_HTTP_METHOD_MAX = 4
2372
+ } lcb_http_method_t;
2373
+
2374
+ /**
2375
+ * Command flag for HTTP to indicate that the callback is to be invoked
2376
+ * multiple times for each new chunk of incoming data. Once the entire body
2377
+ * have been received, the callback will be invoked once more with the
2378
+ * LCB_RESP_F_FINAL flag (in lcb_RESPHTTP::rflags) and an empty content.
2379
+ *
2380
+ * To use streaming requests, this flag should be set in the
2381
+ * lcb_CMDHTTP::cmdflags field
2382
+ */
2383
+ #define LCB_CMDHTTP_F_STREAM 1<<16
2384
+
2385
+ /**
2386
+ * @private
2387
+ * If specified, the lcb_CMDHTTP::cas field becomes the timeout for this
2388
+ * specific request.
2389
+ */
2390
+ #define LCB_CMDHTTP_F_CASTMO 1<<17
2391
+
2392
+ /**
2393
+ * @private
2394
+ * Do not inject authentication header into the request.
2395
+ */
2396
+ #define LCB_CMDHTTP_F_NOUPASS 1<<18
2397
+
2398
+ /**
2399
+ * Structure for performing an HTTP request.
2400
+ * Note that the key and nkey fields indicate the _path_ for the API
2401
+ */
2402
+ typedef struct {
2403
+ LCB_CMD_BASE;
2404
+ /**Type of request to issue. LCB_HTTP_TYPE_VIEW will issue a request
2405
+ * against a random node's view API. LCB_HTTP_TYPE_MANAGEMENT will issue
2406
+ * a request against a random node's administrative API, and
2407
+ * LCB_HTTP_TYPE_RAW will issue a request against an arbitrary host. */
2408
+ lcb_http_type_t type;
2409
+ lcb_http_method_t method; /**< HTTP Method to use */
2410
+
2411
+ /** If the request requires a body (e.g. `PUT` or `POST`) then it will
2412
+ * go here. Be sure to indicate the length of the body too. */
2413
+ const char *body;
2414
+
2415
+ /** Length of the body for the request */
2416
+ lcb_SIZE nbody;
2417
+
2418
+ /** If non-NULL, will be assigned a handle which may be used to
2419
+ * subsequently cancel the request */
2420
+ lcb_http_request_t *reqhandle;
2421
+
2422
+ /** For views, set this to `application/json` */
2423
+ const char *content_type;
2424
+
2425
+ /** Username to authenticate with, if left empty, will use the credentials
2426
+ * passed to lcb_create() */
2427
+ const char *username;
2428
+
2429
+ /** Password to authenticate with, if left empty, will use the credentials
2430
+ * passed to lcb_create() */
2431
+ const char *password;
2432
+
2433
+ /** If set, this must be a string in the form of `http://host:port`. Should
2434
+ * only be used for raw requests. */
2435
+ const char *host;
2436
+ } lcb_CMDHTTP;
2437
+
2438
+ /**
2439
+ * Structure for HTTP responses.
2440
+ * Note that #rc being `LCB_SUCCESS` does not always indicate that the HTTP
2441
+ * request itself was successful. It only indicates that the outgoing request
2442
+ * was submitted to the server and the client received a well-formed HTTP
2443
+ * response. Check the #hstatus field to see the actual HTTP-level status
2444
+ * code received.
2445
+ */
2446
+ typedef struct {
2447
+ LCB_RESP_BASE
2448
+ /**HTTP status code. The value is only valid if #rc is ::LCB_SUCCESS
2449
+ * (if #rc is not LCB_SUCCESS then this field may be 0 as the response may
2450
+ * have not been read/sent) */
2451
+ short htstatus;
2452
+
2453
+ /**List of key-value headers. This field itself may be `NULL`. The list
2454
+ * is terminated by a `NULL` pointer to indicate no more headers. */
2455
+ const char * const * headers;
2456
+
2457
+ /**If @ref LCB_CMDHTTP_F_STREAM is true, contains the current chunk
2458
+ * of response content. Otherwise, contains the entire response body.*/
2459
+ const void *body;
2460
+ /** Length of buffer in #body */
2461
+ lcb_SIZE nbody;
2462
+ /**@private*/
2463
+ lcb_http_request_t _htreq;
2464
+ } lcb_RESPHTTP;
2465
+
2466
+ /**
2467
+ * @committed
2468
+ * Issue an HTTP API request.
2469
+ * @param instance the library handle
2470
+ * @param cookie cookie to be associated with the request
2471
+ * @param cmd the command
2472
+ * @return LCB_SUCCESS if the request was scheduled successfully.
2473
+ *
2474
+ *
2475
+ * @par Simple Response
2476
+ * @code{.c}
2477
+ * void http_callback(lcb_t, int, const lcb_RESPBASE *rb)
2478
+ * {
2479
+ * const lcb_RESPHTTP *resp = (const lcb_RESPHTTP *)rb;
2480
+ * if (resp->rc != LCB_SUCCESS) {
2481
+ * printf("I/O Error for HTTP: %s\n", lcb_strerror(NULL, resp->rc));
2482
+ * return;
2483
+ * }
2484
+ * printf("Got HTTP Status: %d\n", resp->htstatus);
2485
+ * printf("Got paylod: %.*s\n", (int)resp->nbody, resp->body);
2486
+ * const char **hdrp = resp->headers;
2487
+ * while (*hdrp != NULL) {
2488
+ * printf("%s: %s\n", hdrp[0], hdrp[1]);
2489
+ * hdrp += 2;
2490
+ * }
2491
+ * }
2492
+ * @endcode
2493
+ *
2494
+ * @par Streaming Response
2495
+ * If the @ref LCB_CMDHTTP_F_STREAM flag is set in lcb_CMDHTTP::cmdflags then the
2496
+ * response callback is invoked multiple times as data arrives off the socket.
2497
+ * @code{.c}
2498
+ * void http_strm_callback(lcb_t, int, const lcb_RESPBASE *rb)
2499
+ * {
2500
+ * const lcb_RESPHTTP *resp = (const lcb_RESPHTTP *)resp;
2501
+ * if (resp->rflags & LCB_RESP_F_FINAL) {
2502
+ * if (resp->rc != LCB_SUCCESS) {
2503
+ * // ....
2504
+ * }
2505
+ * const char **hdrp = resp->headers;
2506
+ * // ...
2507
+ * } else {
2508
+ * handle_body(resp->body, resp->nbody);
2509
+ * }
2510
+ * }
2511
+ * @endcode
2512
+ *
2513
+ * @par Connection Reuse
2514
+ * The library will attempt to reuse connections for frequently contacted hosts.
2515
+ * By default the library will keep one idle connection to each host for a maximum
2516
+ * of 10 seconds. The number of open idle HTTP connections can be controlled with
2517
+ * @ref LCB_CNTL_HTTP_POOLSIZE.
2518
+ *
2519
+ */
2520
+ LIBCOUCHBASE_API
2521
+ lcb_error_t
2522
+ lcb_http3(lcb_t instance, const void *cookie, const lcb_CMDHTTP *cmd);
2523
+
2524
+ /**
2525
+ * @brief Cancel ongoing HTTP request
2526
+ *
2527
+ * This API will stop the current request. Any pending callbacks will not be
2528
+ * invoked any any pending data will not be delivered. Useful for a long running
2529
+ * request which is no longer needed
2530
+ *
2531
+ * @param instance The handle to lcb
2532
+ * @param request The request handle
2533
+ *
2534
+ * @committed
2535
+ *
2536
+ * @par Example
2537
+ * @code{.c}
2538
+ * lcb_CMDHTTP htcmd = { 0 };
2539
+ * populate_htcmd(&htcmd); // dummy function
2540
+ * lcb_http_request_t reqhandle;
2541
+ * htcmd.reqhandle = &reqhandle;
2542
+ * lcb_http3(instance, cookie, &htcmd);
2543
+ * do_stuff();
2544
+ * lcb_cancel_http_request(instance, reqhandle);
2545
+ * @endcode
2546
+ */
2547
+ LIBCOUCHBASE_API
2548
+ void
2549
+ lcb_cancel_http_request(lcb_t instance, lcb_http_request_t request);
2550
+ /**@} (Group: HTTP) */
2551
+
2552
+ /**@ingroup lcb-public-api
2553
+ * @defgroup lcb-cookie User Cookies
2554
+ * @brief Associate user-defined data with operations
2555
+ * @details
2556
+ *
2557
+ * User-defined pointers may be passed to all operations in the form of a
2558
+ * `cookie` parameter. This cookie parameter allows any kind of application
2559
+ * context to be accessible via the callback (in lcb_RESPBASE::cookie).
2560
+ *
2561
+ * The library will not inspect or manage the address or contents of the
2562
+ * cookie; it may live on the stack (especially if using the library
2563
+ * synchronously), on the heap, or may be NULL altogether.
2564
+ *
2565
+ * In addition to per-operation cookies, the library allows the instance itself
2566
+ * (i.e. the `lcb_t` object) to contain its own cookie. This is helpful when
2567
+ * there is a wrapper object which needs to be accessed from within the callback
2568
+ *
2569
+ * @addtogroup lcb-cookie
2570
+ * @{
2571
+ */
2572
+
2573
+ /**
2574
+ * Associate a cookie with an instance of lcb. The _cookie_ is a user defined
2575
+ * pointer which will remain attached to the specified `lcb_t` for its duration.
2576
+ * This is the way to associate user data with the `lcb_t`.
2577
+ *
2578
+ * @param instance the instance to associate the cookie to
2579
+ * @param cookie the cookie to associate with this instance.
2580
+ *
2581
+ * @attention
2582
+ * There is no destructor for the specified `cookie` stored with the instance;
2583
+ * thus you must ensure to manually free resources to the pointer (if it was
2584
+ * dynamically allocated) when it is no longer required.
2585
+ * @committed
2586
+ *
2587
+ * @code{.c}
2588
+ * typedef struct {
2589
+ * const char *status;
2590
+ * // ....
2591
+ * } instance_info;
2592
+ *
2593
+ * static void bootstrap_callback(lcb_t instance, lcb_error_t err) {
2594
+ * instance_info *info = (instance_info *)lcb_get_cookie(instance);
2595
+ * if (err == LCB_SUCCESS) {
2596
+ * info->status = "Connected";
2597
+ * } else {
2598
+ * info->status = "Error";
2599
+ * }
2600
+ * }
2601
+ *
2602
+ * static void do_create(void) {
2603
+ * instance_info *info = calloc(1, sizeof(*info));
2604
+ * // info->status is currently NULL
2605
+ * // .. create the instance here
2606
+ * lcb_set_cookie(instance, info);
2607
+ * lcb_set_bootstrap_callback(instance, bootstrap_callback);
2608
+ * lcb_connect(instance);
2609
+ * lcb_wait(instance);
2610
+ * printf("Status of instance is %s\n", info->status);
2611
+ * }
2612
+ * @endcode
2613
+ */
2614
+ LIBCOUCHBASE_API
2615
+ void lcb_set_cookie(lcb_t instance, const void *cookie);
2616
+
2617
+ /**
2618
+ * Retrieve the cookie associated with this instance
2619
+ * @param instance the instance of lcb
2620
+ * @return The cookie associated with this instance or NULL
2621
+ * @see lcb_set_cookie()
2622
+ * @committed
2623
+ */
2624
+ LIBCOUCHBASE_API
2625
+ const void *lcb_get_cookie(lcb_t instance);
2626
+ /**@} (Group: Cookies) */
2627
+
2628
+ /**
2629
+ * @defgroup lcb-wait Waiting
2630
+ * @brief Functions for synchronous I/O execution
2631
+ * @details The lcb_wait() family of functions allow to control when the
2632
+ * library sends the operations to the cluster and waits for their execution.
2633
+ *
2634
+ * It is also possible to use non-blocking I/O with the library
2635
+ *
2636
+ * @addtogroup lcb-wait
2637
+ * @{
2638
+ */
2639
+
2640
+ /**
2641
+ * @brief Wait for the execution of all batched requests
2642
+ *
2643
+ * A batched request is any request which requires network I/O.
2644
+ * This includes most of the APIs. You should _not_ use this API if you are
2645
+ * integrating with an asynchronous event loop (i.e. one where your application
2646
+ * code is invoked asynchronously via event loops).
2647
+ *
2648
+ * This function will block the calling thread until either
2649
+ *
2650
+ * * All operations have been completed
2651
+ * * lcb_breakout() is explicitly called
2652
+ *
2653
+ * @param instance the instance containing the requests
2654
+ * @return whether the wait operation failed, or LCB_SUCCESS
2655
+ * @committed
2656
+ */
2657
+ LIBCOUCHBASE_API
2658
+ lcb_error_t lcb_wait(lcb_t instance);
2659
+
2660
+ /**
2661
+ * @volatile
2662
+ * This function will cause a single "tick" in the underlying event loop,
2663
+ * causing operations whose I/O can be executed immediately to be sent to
2664
+ * the server.
2665
+ *
2666
+ * Like lcb_wait(), callbacks for operations may be delivered here, however
2667
+ * some operations may be left incomplete if their I/O could not be processed
2668
+ * immediately. This function is intended as an optimization for large batches
2669
+ * of operations - so that some I/O can be completed during the batching process
2670
+ * itself, and only the remainder of those operations (which would have blocked)
2671
+ * will be completed with lcb_wait() (which should be invoked after the batch).
2672
+ *
2673
+ * This function is mainly useful if there is a significant delay in time
2674
+ * between each scheduling function, in which I/O may be completed during these
2675
+ * gaps (thereby emptying the socket's kernel write buffer, and allowing for
2676
+ * new operations to be added after the interval). Calling this function for
2677
+ * batches where all data is available up-front may actually make things slower.
2678
+ *
2679
+ * @warning
2680
+ * You must call lcb_wait() at least one after any batch of operations to ensure
2681
+ * they have been completed. This function is provided as an optimization only.
2682
+ *
2683
+ * @return LCB_CLIENT_FEATURE_UNAVAILABLE if the event loop does not support
2684
+ * the "tick" mode.
2685
+ */
2686
+ LIBCOUCHBASE_API
2687
+ lcb_error_t lcb_tick_nowait(lcb_t instance);
2688
+
2689
+ /**@brief Flags for lcb_wait3()*/
2690
+ typedef enum {
2691
+ /**Behave like the old lcb_wait()*/
2692
+ LCB_WAIT_DEFAULT = 0x00,
2693
+
2694
+ /**Do not check pending operations before running the event loop. By default
2695
+ * lcb_wait() will traverse the server list to check if any operations are
2696
+ * pending, and if nothing is pending the function will return without
2697
+ * running the event loop. This is usually not necessary for applications
2698
+ * which already _only_ call lcb_wait() when they know they have scheduled
2699
+ * at least one command.
2700
+ */
2701
+ LCB_WAIT_NOCHECK = 0x01
2702
+ } lcb_WAITFLAGS;
2703
+
2704
+ /**
2705
+ * @committed
2706
+ * @brief Wait for completion of scheduled operations.
2707
+ * @param instance the instance
2708
+ * @param flags flags to modify the behavior of lcb_wait(). Pass 0 to obtain
2709
+ * behavior identical to lcb_wait().
2710
+ */
2711
+ LIBCOUCHBASE_API
2712
+ void lcb_wait3(lcb_t instance, lcb_WAITFLAGS flags);
2713
+
2714
+ /**
2715
+ * @brief Forcefully break from the event loop.
2716
+ *
2717
+ * You may call this function from within any callback to signal to the library
2718
+ * that it return control to the function calling lcb_wait() as soon as possible.
2719
+ * Note that if there are pending functions which have not been processed, you
2720
+ * are responsible for calling lcb_wait() a second time.
2721
+ *
2722
+ * @param instance the instance to run the event loop for.
2723
+ * @committed
2724
+ */
2725
+ LIBCOUCHBASE_API
2726
+ void lcb_breakout(lcb_t instance);
2727
+
2728
+ /**
2729
+ * @brief Check if instance is blocked in the event loop
2730
+ * @param instance the instance to run the event loop for.
2731
+ * @return non-zero if nobody is waiting for IO interaction
2732
+ * @uncomitted
2733
+ */
2734
+ LIBCOUCHBASE_API
2735
+ int lcb_is_waiting(lcb_t instance);
2736
+ /**@} (Group: Wait) */
2737
+
2738
+ /**
2739
+ * @uncommitted
2740
+ *
2741
+ * @brief Force the library to refetch the cluster configuration
2742
+ *
2743
+ * The library by default employs various heuristics to determine if a new
2744
+ * configuration is needed from the cluster. However there are some situations
2745
+ * in which an application may wish to force a refresh of the configuration:
2746
+ *
2747
+ * * If a specific node has been failed
2748
+ * over and the library has received a configuration in which there is no
2749
+ * master node for a given key, the library will immediately return the error
2750
+ * `LCB_NO_MATCHING_SERVER` for the given item and will not request a new
2751
+ * configuration. In this state, the client will not perform any network I/O
2752
+ * until a request has been made to it using a key that is mapped to a known
2753
+ * active node.
2754
+ *
2755
+ * * The library's heuristics may have failed to detect an error warranting
2756
+ * a configuration change, but the application either through its own
2757
+ * heuristics, or through an out-of-band channel knows that the configuration
2758
+ * has changed.
2759
+ *
2760
+ *
2761
+ * This function is provided as an aid to assist in such situations
2762
+ *
2763
+ * If you wish for your application to block until a new configuration is
2764
+ * received, you _must_ call lcb_wait3() with the LCB_WAIT_NO_CHECK flag as
2765
+ * this function call is not bound to a specific operation. Additionally there
2766
+ * is no status notification as to whether this operation succeeded or failed
2767
+ * (the configuration callback via lcb_set_configuration_callback() may
2768
+ * provide hints as to whether a configuration was received or not, but by no
2769
+ * means should be considered to be part of this function's control flow).
2770
+ *
2771
+ * In general the use pattern of this function is like so:
2772
+ *
2773
+ * @code{.c}
2774
+ * unsigned retries = 5;
2775
+ * lcb_error_t err;
2776
+ * do {
2777
+ * retries--;
2778
+ * err = lcb_get(instance, cookie, ncmds, cmds);
2779
+ * if (err == LCB_NO_MATCHING_SERVER) {
2780
+ * lcb_refresh_config(instance);
2781
+ * usleep(100000);
2782
+ * lcb_wait3(instance, LCB_WAIT_NO_CHECK);
2783
+ * } else {
2784
+ * break;
2785
+ * }
2786
+ * } while (retries);
2787
+ * if (err == LCB_SUCCESS) {
2788
+ * lcb_wait3(instance, 0); // equivalent to lcb_wait(instance);
2789
+ * } else {
2790
+ * printf("Tried multiple times to fetch the key, but its node is down\n");
2791
+ * }
2792
+ * @endcode
2793
+ */
2794
+ LIBCOUCHBASE_API
2795
+ void
2796
+ lcb_refresh_config(lcb_t instance);
2797
+
2798
+ /**
2799
+ * @ingroup lcb-public-api
2800
+ * @defgroup lcb-sched Advanced Scheduling
2801
+ * @brief Additional functions for scheduling operations
2802
+ *
2803
+ * @details
2804
+ *
2805
+ * An application may spool multiple operations into the library with the
2806
+ * option of unspooling previously-spooled operations in case one of
2807
+ * the operations cannot be spooled. These semantics exist primarily to
2808
+ * support "all-or-nothing" scheduling found in the V2 API as well as in
2809
+ * some other wrapping SDKs.
2810
+ *
2811
+ * From version 2.4.0 to version 2.5.5, use of the explicit scheduling
2812
+ * API was mandatory to schedule operations. This API is optional since 2.5.6.
2813
+ *
2814
+ * The following operation APIs are low level entry points which create a
2815
+ * single operation. To use these operation APIs you should call the
2816
+ * lcb_sched_enter() which creates a virtual scope in which to create operations.
2817
+ *
2818
+ * For each of these operation APIs, the actual API call will insert the
2819
+ * created packet into a "Scheduling Queue" (this is done through
2820
+ * mcreq_sched_add() which is in mcreq.h). You may add as many items to this
2821
+ * scheduling queue as you would like.
2822
+ *
2823
+ * Note that an operation is only added to the queue if it was able to be
2824
+ * scheduled properly. If a scheduling failure occurred (for example, if a
2825
+ * configuration is missing, the command had invalid input, or memory allocation
2826
+ * failed) then the command will not be placed into the queue.
2827
+ *
2828
+ * Once all operations have been scheduled you can call
2829
+ * lcb_sched_leave() which will place all commands scheduled into the I/O
2830
+ * queue.
2831
+ *
2832
+ * If you wish to _discard_ all scheduled operations (for example, if one of
2833
+ * them errored, and your application cannot handle partial scheduling failures)
2834
+ * then you may call lcb_sched_fail() which will release all the resources
2835
+ * of the packets placed into the temporary queue.
2836
+ *
2837
+ * @par Behavior from version 2.5.6
2838
+ *
2839
+ * Starting from version 2.5.6, use of this API is optional. Scheduling functions
2840
+ * will now check if an empty call to lcb_sched_enter() is present. If no call
2841
+ * to lcb_sched_enter() is found then the library will implicitly call
2842
+ * lcb_sched_leave().
2843
+ *
2844
+ * @addtogroup lcb-sched
2845
+ * @{
2846
+ */
2847
+
2848
+ /**
2849
+ * @brief Enter a scheduling context.
2850
+ *
2851
+ * @uncommitted
2852
+ *
2853
+ * A scheduling context is an ephemeral list of
2854
+ * commands issued to various servers. Operations (like lcb_get3(), lcb_store3())
2855
+ * place packets into the current context.
2856
+ *
2857
+ * The context mechanism allows you to efficiently pipeline and schedule multiple
2858
+ * operations of different types and quantities. The network is not touched
2859
+ * and nothing is scheduled until the context is exited.
2860
+ *
2861
+ * @param instance the instance
2862
+ *
2863
+ * @code{.c}
2864
+ * lcb_sched_enter(instance);
2865
+ * lcb_get3(...);
2866
+ * lcb_store3(...);
2867
+ * lcb_counter3(...);
2868
+ * lcb_sched_leave(instance);
2869
+ * lcb_wait3(instance, LCB_WAIT_NOCHECK);
2870
+ * @endcode
2871
+ */
2872
+ LIBCOUCHBASE_API
2873
+ void lcb_sched_enter(lcb_t instance);
2874
+
2875
+ /**
2876
+ * @uncommitted
2877
+ *
2878
+ * @brief Leave the current scheduling context, scheduling the commands within the
2879
+ * context to be flushed to the network.
2880
+ *
2881
+ * @details This will initiate a network-level flush (depending on the I/O system)
2882
+ * to the network. For completion-based I/O systems this typically means
2883
+ * allocating a temporary write context to contain the buffer. If using a
2884
+ * completion-based I/O module (for example, Windows or libuv) then it is
2885
+ * recommended to limit the number of calls to one per loop iteration. If
2886
+ * limiting the number of calls to this function is not possible (for example,
2887
+ * if the legacy API is being used, or you wish to use implicit scheduling) then
2888
+ * the flushing may be decoupled from this function - see the documentation for
2889
+ * lcb_sched_flush().
2890
+ *
2891
+ * @param instance the instance
2892
+ */
2893
+ LIBCOUCHBASE_API
2894
+ void lcb_sched_leave(lcb_t instance);
2895
+
2896
+
2897
+ /**
2898
+ * @uncommitted
2899
+ * @brief Fail all commands in the current scheduling context.
2900
+ *
2901
+ * The commands placed within the current
2902
+ * scheduling context are released and are never flushed to the network.
2903
+ * @param instance
2904
+ *
2905
+ * @warning
2906
+ * This function only affects commands which have a direct correspondence
2907
+ * to memcached packets. Currently these are commands scheduled by:
2908
+ *
2909
+ * * lcb_get3()
2910
+ * * lcb_rget3()
2911
+ * * lcb_unlock3()
2912
+ * * lcb_touch3()
2913
+ * * lcb_store3()
2914
+ * * lcb_counter3()
2915
+ * * lcb_remove3()
2916
+ * * lcb_stats3()
2917
+ * * lcb_observe3_ctxnew()
2918
+ * * lcb_observe_seqno3()
2919
+ *
2920
+ * Other commands are _compound_ commands and thus should be in their own
2921
+ * scheduling context.
2922
+ */
2923
+ LIBCOUCHBASE_API
2924
+ void lcb_sched_fail(lcb_t instance);
2925
+
2926
+ /**
2927
+ * @committed
2928
+ * @brief Request commands to be flushed to the network
2929
+ *
2930
+ * By default, the library will implicitly request a flush to the network upon
2931
+ * every call to lcb_sched_leave().
2932
+ *
2933
+ * [ Note, this does not mean the items are flushed
2934
+ * and I/O is performed, but it means the relevant event loop watchers are
2935
+ * activated to perform the operations on the next iteration ]. If
2936
+ * @ref LCB_CNTL_SCHED_IMPLICIT_FLUSH
2937
+ * is disabled then this behavior is disabled and the
2938
+ * application must explicitly call lcb_sched_flush(). This may be considered
2939
+ * more performant in the cases where multiple discreet operations are scheduled
2940
+ * in an lcb_sched_enter()/lcb_sched_leave() pair. With implicit flush enabled,
2941
+ * each call to lcb_sched_leave() will possibly invoke system repeatedly.
2942
+ */
2943
+ LIBCOUCHBASE_API
2944
+ void lcb_sched_flush(lcb_t instance);
2945
+
2946
+ /**@} (Group: Adanced Scheduling) */
2947
+
2948
+ /**@ingroup lcb-public-api
2949
+ * @defgroup lcb-destroy Destroying
2950
+ * @brief Library destruction routines
2951
+ * @addtogroup lcb-destroy
2952
+ * @{
2953
+ */
2954
+ /**
2955
+ * Destroy (and release all allocated resources) an instance of lcb.
2956
+ * Using instance after calling destroy will most likely cause your
2957
+ * application to crash.
2958
+ *
2959
+ * Note that any pending operations will not have their callbacks invoked.
2960
+ *
2961
+ * @param instance the instance to destroy.
2962
+ * @committed
2963
+ */
2964
+ LIBCOUCHBASE_API
2965
+ void lcb_destroy(lcb_t instance);
2966
+
2967
+ /**
2968
+ * @brief Callback received when instance is about to be destroyed
2969
+ * @param cookie cookie passed to lcb_destroy_async()
2970
+ */
2971
+ typedef void (*lcb_destroy_callback)(const void *cookie);
2972
+
2973
+ /**
2974
+ * @brief Set the callback to be invoked when the instance is destroyed
2975
+ * asynchronously.
2976
+ * @return the previous callback.
2977
+ */
2978
+ LIBCOUCHBASE_API
2979
+ lcb_destroy_callback
2980
+ lcb_set_destroy_callback(lcb_t, lcb_destroy_callback);
2981
+ /**
2982
+ * @brief Asynchronously schedule the destruction of an instance.
2983
+ *
2984
+ * This function provides a safe way for asynchronous environments to destroy
2985
+ * the lcb_t handle without worrying about reentrancy issues.
2986
+ *
2987
+ * @param instance
2988
+ * @param arg a pointer passed to the callback.
2989
+ *
2990
+ * While the callback and cookie are optional, they are very much recommended
2991
+ * for testing scenarios where you wish to ensure that all resources allocated
2992
+ * by the instance have been closed. Specifically when the callback is invoked,
2993
+ * all timers (save for the one actually triggering the destruction) and sockets
2994
+ * will have been closed.
2995
+ *
2996
+ * As with lcb_destroy() you may call this function only once. You may not
2997
+ * call this function together with lcb_destroy as the two are mutually
2998
+ * exclusive.
2999
+ *
3000
+ * If for whatever reason this function is being called in a synchronous
3001
+ * flow, lcb_wait() must be invoked in order for the destruction to take effect
3002
+ *
3003
+ * @see lcb_set_destroy_callback
3004
+ *
3005
+ * @committed
3006
+ */
3007
+ LIBCOUCHBASE_API
3008
+ void lcb_destroy_async(lcb_t instance, const void *arg);
3009
+ /**@} (Group: Destroy) */
3010
+
3011
+ /**@}*/
3012
+
3013
+ /** @private */
3014
+ #define LCB_DATATYPE_JSON 0x01
3015
+
3016
+ /** @private */
3017
+ typedef enum { LCB_VALUE_RAW = 0x00, LCB_VALUE_F_JSON = 0x01, LCB_VALUE_F_SNAPPYCOMP } lcb_VALUEFLAGS;
3018
+
3019
+
3020
+ /**
3021
+ * @ingroup lcb-public-api
3022
+ * @defgroup lcb-cluster-status Cluster Information
3023
+ * @brief These functions return status information about the handle, the current
3024
+ * connection, and the number of nodes found within the cluster.
3025
+ *
3026
+ * @see lcb_cntl() for more functions to retrieve status info
3027
+ *
3028
+ * @addtogroup lcb-cluster-status
3029
+ * @{
3030
+ */
3031
+
3032
+ /**@brief
3033
+ * Type of node to retrieve for the lcb_get_node() function
3034
+ */
3035
+ typedef enum {
3036
+ /** Get an HTTP configuration (Rest API) node */
3037
+ LCB_NODE_HTCONFIG = 0x01,
3038
+ /** Get a data (memcached) node */
3039
+ LCB_NODE_DATA = 0x02,
3040
+ /** Get a view (CAPI) node */
3041
+ LCB_NODE_VIEWS = 0x04,
3042
+ /** Only return a node which is connected, or a node which is known to be up */
3043
+ LCB_NODE_CONNECTED = 0x08,
3044
+
3045
+ /** Specifying this flag adds additional semantics which instruct the library
3046
+ * to search additional resources to return a host, and finally,
3047
+ * if no host can be found, return the string
3048
+ * constant @ref LCB_GETNODE_UNAVAILABLE. */
3049
+ LCB_NODE_NEVERNULL = 0x10,
3050
+
3051
+ /** Equivalent to `LCB_NODE_HTCONFIG|LCB_NODE_CONNECTED` */
3052
+ LCB_NODE_HTCONFIG_CONNECTED = 0x09,
3053
+
3054
+ /**Equivalent to `LCB_NODE_HTCONFIG|LCB_NODE_NEVERNULL`.
3055
+ * When this is passed, some additional attempts may be made by the library
3056
+ * to return any kind of host, including searching the initial list of hosts
3057
+ * passed to the lcb_create() function. */
3058
+ LCB_NODE_HTCONFIG_ANY = 0x11
3059
+ } lcb_GETNODETYPE;
3060
+
3061
+ /** String constant returned by lcb_get_node() when the @ref LCB_NODE_NEVERNULL
3062
+ * flag is specified, and no node can be returned */
3063
+ #define LCB_GETNODE_UNAVAILABLE "invalid_host:0"
3064
+
3065
+ /**
3066
+ * @brief Return a string of `host:port` for a node of the given type.
3067
+ *
3068
+ * @param instance the instance from which to retrieve the node
3069
+ * @param type the type of node to return
3070
+ * @param index the node number if index is out of bounds it will be wrapped
3071
+ * around, thus there is never an invalid value for this parameter
3072
+ *
3073
+ * @return a string in the form of `host:port`. If LCB_NODE_NEVERNULL was specified
3074
+ * as an option in `type` then the string constant LCB_GETNODE_UNAVAILABLE is
3075
+ * returned. Otherwise `NULL` is returned if the type is unrecognized or the
3076
+ * LCB_NODE_CONNECTED option was specified and no connected node could be found
3077
+ * or a memory allocation failed.
3078
+ *
3079
+ * @note The index parameter is _ignored_ if `type` is
3080
+ * LCB_NODE_HTCONFIG|LCB_NODE_CONNECTED as there will always be only a single
3081
+ * HTTP bootstrap node.
3082
+ *
3083
+ * @code{.c}
3084
+ * const char *viewnode = lcb_get_node(instance, LCB_NODE_VIEWS, 0);
3085
+ * // Get the connected REST endpoint:
3086
+ * const char *restnode = lcb_get_node(instance, LCB_NODE_HTCONFIG|LCB_NODE_CONNECTED, 0);
3087
+ * if (!restnode) {
3088
+ * printf("Instance not connected via HTTP!\n");
3089
+ * }
3090
+ * @endcode
3091
+ *
3092
+ * Iterate over all the data nodes:
3093
+ * @code{.c}
3094
+ * unsigned ii;
3095
+ * for (ii = 0; ii < lcb_get_num_servers(instance); ii++) {
3096
+ * const char *kvnode = lcb_get_node(instance, LCB_NODE_DATA, ii);
3097
+ * if (kvnode) {
3098
+ * printf("KV node %s exists at index %u\n", kvnode, ii);
3099
+ * } else {
3100
+ * printf("No node for index %u\n", ii);
3101
+ * }
3102
+ * }
3103
+ * @endcode
3104
+ *
3105
+ * @committed
3106
+ */
3107
+ LIBCOUCHBASE_API
3108
+ const char *
3109
+ lcb_get_node(lcb_t instance, lcb_GETNODETYPE type, unsigned index);
3110
+
3111
+ /**
3112
+ * @committed
3113
+ *
3114
+ * @brief Get the target server for a given key.
3115
+ *
3116
+ * This is a convenience function wrapping around the vBucket API which allows
3117
+ * you to retrieve the target node (the node which will be contacted) when
3118
+ * performing KV operations involving the key.
3119
+ *
3120
+ * @param instance the instance
3121
+ * @param key the key to use
3122
+ * @param nkey the length of the key
3123
+ * @return a string containing the hostname, or NULL on error.
3124
+ *
3125
+ * Since this is a convenience function, error details are not contained here
3126
+ * in favor of brevity. Use the full vBucket API for more powerful functions.
3127
+ */
3128
+ LIBCOUCHBASE_API
3129
+ const char *
3130
+ lcb_get_keynode(lcb_t instance, const void *key, size_t nkey);
3131
+
3132
+ /**
3133
+ * @brief Get the number of the replicas in the cluster
3134
+ *
3135
+ * @param instance The handle to lcb
3136
+ * @return -1 if the cluster wasn't configured yet, and number of replicas
3137
+ * otherwise. This may be `0` if there are no replicas.
3138
+ * @committed
3139
+ */
3140
+ LIBCOUCHBASE_API
3141
+ lcb_S32 lcb_get_num_replicas(lcb_t instance);
3142
+
3143
+ /**
3144
+ * @brief Get the number of the nodes in the cluster
3145
+ * @param instance The handle to lcb
3146
+ * @return -1 if the cluster wasn't configured yet, and number of nodes otherwise.
3147
+ * @committed
3148
+ */
3149
+ LIBCOUCHBASE_API
3150
+ lcb_S32 lcb_get_num_nodes(lcb_t instance);
3151
+
3152
+
3153
+ /**
3154
+ * @brief Get a list of nodes in the cluster
3155
+ *
3156
+ * @return a NULL-terminated list of 0-terminated strings consisting of
3157
+ * node hostnames:admin_ports for the entire cluster.
3158
+ * The storage duration of this list is only valid until the
3159
+ * next call to a libcouchbase function and/or when returning control to
3160
+ * libcouchbase' event loop.
3161
+ *
3162
+ * @code{.c}
3163
+ * const char * const * curp = lcb_get_server_list(instance);
3164
+ * for (; *curp; curp++) {
3165
+ * printf("Have node %s\n", *curp);
3166
+ * }
3167
+ * @endcode
3168
+ * @committed
3169
+ */
3170
+ LIBCOUCHBASE_API
3171
+ const char *const *lcb_get_server_list(lcb_t instance);
3172
+
3173
+ /**
3174
+ * @volatile
3175
+ * @brief Write a textual dump to a file.
3176
+ *
3177
+ * This function will inspect the various internal structures of the current
3178
+ * client handle (indicated by `instance`) and write the state information
3179
+ * to the file indicated by `fp`.
3180
+ * @param instance the handle to dump
3181
+ * @param fp the file to which the dump should be written
3182
+ * @param flags a set of modifiers (of @ref lcb_DUMPFLAGS) indicating what
3183
+ * information to dump. Note that a standard set of information is always
3184
+ * dumped, but by default more verbose information is hidden, and may be
3185
+ * enabled with these flags.
3186
+ */
3187
+ LIBCOUCHBASE_API
3188
+ void
3189
+ lcb_dump(lcb_t instance, FILE *fp, lcb_U32 flags);
3190
+ /**@} (Group: Cluster Info) */
3191
+
3192
+ /**
3193
+ * @ingroup lcb-public-api
3194
+ * @defgroup lcb-cntl Settings
3195
+ * @brief Get/Set Library Options
3196
+ *
3197
+ * @details
3198
+ *
3199
+ * The lcb_cntl() function and its various helpers are the means by which to
3200
+ * modify settings within the library
3201
+ *
3202
+ * @addtogroup lcb-cntl
3203
+ * @see <cntl.h>
3204
+ * @{
3205
+ */
3206
+
3207
+ /**
3208
+ * This function exposes an ioctl/fcntl-like interface to read and write
3209
+ * various configuration properties to and from an lcb_t handle.
3210
+ *
3211
+ * @param instance The instance to modify
3212
+ *
3213
+ * @param mode One of LCB_CNTL_GET (to retrieve a setting) or LCB_CNTL_SET
3214
+ * (to modify a setting). Note that not all configuration properties
3215
+ * support SET.
3216
+ *
3217
+ * @param cmd The specific command/property to modify. This is one of the
3218
+ * LCB_CNTL_* constants defined in this file. Note that it is safe
3219
+ * (and even recommanded) to use the raw numeric value (i.e.
3220
+ * to be backwards and forwards compatible with libcouchbase
3221
+ * versions), as they are not subject to change.
3222
+ *
3223
+ * Using the actual value may be useful in ensuring your application
3224
+ * will still compile with an older libcouchbase version (though
3225
+ * you may get a runtime error (see return) if the command is not
3226
+ * supported
3227
+ *
3228
+ * @param arg The argument passed to the configuration handler.
3229
+ * The actual type of this pointer is dependent on the
3230
+ * command in question. Typically for GET operations, the
3231
+ * value of 'arg' is set to the current configuration value;
3232
+ * and for SET operations, the current configuration is
3233
+ * updated with the contents of *arg.
3234
+ *
3235
+ * @return ::LCB_NOT_SUPPORTED if the code is unrecognized
3236
+ * @return ::LCB_EINVAL if there was a problem with the argument
3237
+ * (typically for LCB_CNTL_SET) other error codes depending on the command.
3238
+ *
3239
+ * The following error codes are returned if the ::LCB_CNTL_DETAILED_ERRCODES
3240
+ * are enabled.
3241
+ *
3242
+ * @return ::LCB_ECTL_UNKNOWN if the code is unrecognized
3243
+ * @return ::LCB_ECTL_UNSUPPMODE An invalid _mode_ was passed
3244
+ * @return ::LCB_ECTL_BADARG if the value was invalid
3245
+ *
3246
+ * @committed
3247
+ *
3248
+ * @see lcb_cntl_setu32()
3249
+ * @see lcb_cntl_string()
3250
+ */
3251
+ LIBCOUCHBASE_API
3252
+ lcb_error_t lcb_cntl(lcb_t instance, int mode, int cmd, void *arg);
3253
+
3254
+ /**
3255
+ * Alternate way to set configuration settings by passing a string key
3256
+ * and value. This may be used to provide a simple interface from a command
3257
+ * line or higher level language to allow the setting of specific key-value
3258
+ * pairs.
3259
+ *
3260
+ * The format for the value is dependent on the option passed, the following
3261
+ * value types exist:
3262
+ *
3263
+ * - **Timeout**. A _timeout_ value can either be specified as fractional
3264
+ * seconds (`"1.5"` for 1.5 seconds), or in microseconds (`"1500000"`).
3265
+ * - **Number**. This is any valid numerical value. This may be signed or
3266
+ * unsigned depending on the setting.
3267
+ * - **Boolean**. This specifies a boolean. A true value is either a positive
3268
+ * numeric value (i.e. `"1"`) or the string `"true"`. A false value
3269
+ * is a zero (i.e. `"0"`) or the string `"false"`.
3270
+ * - **Float**. This is like a _Number_, but also allows fractional specification,
3271
+ * e.g. `"2.4"`.
3272
+ *
3273
+ * | Code | Name | Type
3274
+ * |------|------|-----
3275
+ * |@ref LCB_CNTL_OP_TIMEOUT | `"operation_timeout"` | Timeout |
3276
+ * |@ref LCB_CNTL_VIEW_TIMEOUT | `"view_timeout"` | Timeout |
3277
+ * |@ref LCB_CNTL_DURABILITY_TIMEOUT | `"durability_timeout"` | Timeout |
3278
+ * |@ref LCB_CNTL_DURABILITY_INTERVAL | `"durability_interval"`| Timeout |
3279
+ * |@ref LCB_CNTL_HTTP_TIMEOUT | `"http_timeout"` | Timeout |
3280
+ * |@ref LCB_CNTL_RANDOMIZE_BOOTSTRAP_HOSTS | `"randomize_nodes"` | Boolean|
3281
+ * |@ref LCB_CNTL_CONFERRTHRESH | `"error_thresh_count"`| Number (Positive)|
3282
+ * |@ref LCB_CNTL_CONFDELAY_THRESH |`"error_thresh_delay"` | Timeout |
3283
+ * |@ref LCB_CNTL_CONFIGURATION_TIMEOUT | `"config_total_timeout"`|Timeout|
3284
+ * |@ref LCB_CNTL_CONFIG_NODE_TIMEOUT | `"config_node_timeout"` | Timeout |
3285
+ * |@ref LCB_CNTL_CONFIGCACHE | `"config_cache"` | Path |
3286
+ * |@ref LCB_CNTL_DETAILED_ERRCODES | `"detailed_errcodes"` | Boolean |
3287
+ * |@ref LCB_CNTL_HTCONFIG_URLTYPE | `"http_urlmode"` | Number (values are the constant values) |
3288
+ * |@ref LCB_CNTL_RETRY_BACKOFF | `"retry_backoff"` | Float |
3289
+ * |@ref LCB_CNTL_HTTP_POOLSIZE | `"http_poolsize"` | Number |
3290
+ * |@ref LCB_CNTL_VBGUESS_PERSIST | `"vbguess_persist"` | Boolean |
3291
+ *
3292
+ *
3293
+ * @committed - Note, the actual API call is considered committed and will
3294
+ * not disappear, however the existence of the various string settings are
3295
+ * dependendent on the actual settings they map to. It is recommended that
3296
+ * applications use the numerical lcb_cntl() as the string names are
3297
+ * subject to change.
3298
+ *
3299
+ * @see lcb_cntl()
3300
+ * @see lcb-cntl-settings
3301
+ */
3302
+ LIBCOUCHBASE_API
3303
+ lcb_error_t
3304
+ lcb_cntl_string(lcb_t instance, const char *key, const char *value);
3305
+
3306
+ /**
3307
+ * @brief Convenience function to set a value as an lcb_U32
3308
+ * @param instance
3309
+ * @param cmd setting to modify
3310
+ * @param arg the new value
3311
+ * @return see lcb_cntl() for details
3312
+ * @committed
3313
+ */
3314
+ LIBCOUCHBASE_API
3315
+ lcb_error_t lcb_cntl_setu32(lcb_t instance, int cmd, lcb_U32 arg);
3316
+
3317
+ /**
3318
+ * @brief Retrieve an lcb_U32 setting
3319
+ * @param instance
3320
+ * @param cmd setting to retrieve
3321
+ * @return the value.
3322
+ * @warning This function does not return an error code. Ensure that the cntl is
3323
+ * correct for this version, or use lcb_cntl() directly.
3324
+ * @committed
3325
+ */
3326
+ LIBCOUCHBASE_API
3327
+ lcb_U32 lcb_cntl_getu32(lcb_t instance, int cmd);
3328
+
3329
+ /**
3330
+ * Determine if a specific control code exists
3331
+ * @param ctl the code to check for
3332
+ * @return 0 if it does not exist, nonzero if it exists.
3333
+ */
3334
+ LIBCOUCHBASE_API
3335
+ int
3336
+ lcb_cntl_exists(int ctl);
3337
+ /**@}*/ /* settings */
3338
+
3339
+ /**
3340
+ * @ingroup lcb-public-api
3341
+ * @defgroup lcb-timings Timings
3342
+ * @brief Determine how long operations are taking to be completed
3343
+ *
3344
+ * libcouchbase provides a simple form of per-command timings you may use
3345
+ * to figure out the current lantency for the request-response cycle as
3346
+ * generated by your application. Please note that these numbers are not
3347
+ * necessarily accurate as you may affect the timing recorded by doing
3348
+ * work in the event loop.
3349
+ *
3350
+ * The time recorded with this library is the time elapsed from the
3351
+ * command being called, and the response packet being received from the
3352
+ * server. Everything the application does before driving the event loop
3353
+ * will affect the timers.
3354
+ *
3355
+ * The function lcb_enable_timings() is used to enable the timings for
3356
+ * the given instance, and lcb_disable_timings is used to disable the
3357
+ * timings. The overhead of using the timers should be negligible.
3358
+ *
3359
+ * The function lcb_get_timings is used to retrieve the current timing.
3360
+ * values from the given instance. The cookie is passed transparently to
3361
+ * the callback function.
3362
+ *
3363
+ * Here is an example of the usage of this module:
3364
+ *
3365
+ * @code{.c}
3366
+ * #include <libcouchbase/couchbase.h>
3367
+ *
3368
+ * static void callback(
3369
+ * lcb_t instance, const void *cookie, lcb_timeunit_t timeunit, lcb_U32 min,
3370
+ * lcb_U32 max, lcb_U32 total, lcb_U32 maxtotal)
3371
+ * {
3372
+ * FILE* out = (void*)cookie;
3373
+ * int num = (float)10.0 * (float)total / ((float)maxtotal);
3374
+ * fprintf(out, "[%3u - %3u]", min, max);
3375
+ * switch (timeunit) {
3376
+ * case LCB_TIMEUNIT_NSEC:
3377
+ * fprintf(out, "ns");
3378
+ * break;
3379
+ * case LCB_TIMEUNIT_USEC:
3380
+ * fprintf(out, "us");
3381
+ * break;
3382
+ * case LCB_TIMEUNIT_MSEC:
3383
+ * fsprintf(out, "ms");
3384
+ * break;
3385
+ * case LCB_TIMEUNIT_SEC:
3386
+ * fprintf(out, "s ");
3387
+ * break;
3388
+ * default:
3389
+ * ;
3390
+ * }
3391
+ *
3392
+ * fprintf(out, " |");
3393
+ * for (int ii = 0; ii < num; ++ii) {
3394
+ * fprintf(out, "#");
3395
+ * }
3396
+ * fprintf(out, " - %u\n", total);
3397
+ * }
3398
+ *
3399
+ *
3400
+ * lcb_enable_timings(instance);
3401
+ * ... do a lot of operations ...
3402
+ * fprintf(stderr, " +---------+\n"
3403
+ * lcb_get_timings(instance, stderr, callback);
3404
+ * fprintf(stderr, " +---------+\n"
3405
+ * lcb_disable_timings(instance);
3406
+ * @endcode
3407
+ *
3408
+ * @addtogroup lcb-timings
3409
+ * @{
3410
+ */
3411
+
3412
+ /**
3413
+ * @brief Time units reported by lcb_get_timings()
3414
+ */
3415
+ enum lcb_timeunit_t {
3416
+ LCB_TIMEUNIT_NSEC = 0, /**< @brief Time is in nanoseconds */
3417
+ LCB_TIMEUNIT_USEC = 1, /**< @brief Time is in microseconds */
3418
+ LCB_TIMEUNIT_MSEC = 2, /**< @brief Time is in milliseconds */
3419
+ LCB_TIMEUNIT_SEC = 3 /**< @brief Time is in seconds */
3420
+ };
3421
+ typedef enum lcb_timeunit_t lcb_timeunit_t;
3422
+
3423
+ /**
3424
+ * Start recording timing metrics for the different operations.
3425
+ * The timer is started when the command is called (and the data
3426
+ * spooled to the server), and the execution time is the time until
3427
+ * we parse the response packets. This means that you can affect
3428
+ * the timers by doing a lot of other stuff before checking if
3429
+ * there is any results available..
3430
+ *
3431
+ * @param instance the handle to lcb
3432
+ * @return Status of the operation.
3433
+ * @committed
3434
+ */
3435
+ LIBCOUCHBASE_API
3436
+ lcb_error_t lcb_enable_timings(lcb_t instance);
3437
+
3438
+
3439
+ /**
3440
+ * Stop recording (and release all resources from previous measurements)
3441
+ * timing metrics.
3442
+ *
3443
+ * @param instance the handle to lcb
3444
+ * @return Status of the operation.
3445
+ * @committed
3446
+ */
3447
+ LIBCOUCHBASE_API
3448
+ lcb_error_t lcb_disable_timings(lcb_t instance);
3449
+
3450
+ /**
3451
+ * The following function is called for each bucket in the timings
3452
+ * histogram when you call lcb_get_timings.
3453
+ * You are guaranteed that the callback will be called with the
3454
+ * lowest [min,max] range first.
3455
+ *
3456
+ * @param instance the handle to lcb
3457
+ * @param cookie the cookie you provided that allows you to pass
3458
+ * arbitrary user data to the callback
3459
+ * @param timeunit the "scale" for the values
3460
+ * @param min The lower bound for this histogram bucket
3461
+ * @param max The upper bound for this histogram bucket
3462
+ * @param total The number of hits in this histogram bucket
3463
+ * @param maxtotal The highest value in all of the buckets
3464
+ */
3465
+ typedef void (*lcb_timings_callback)(lcb_t instance,
3466
+ const void *cookie,
3467
+ lcb_timeunit_t timeunit,
3468
+ lcb_U32 min,
3469
+ lcb_U32 max,
3470
+ lcb_U32 total,
3471
+ lcb_U32 maxtotal);
3472
+
3473
+ /**
3474
+ * Get the timings histogram
3475
+ *
3476
+ * @param instance the handle to lcb
3477
+ * @param cookie a cookie that will be present in all of the callbacks
3478
+ * @param callback Callback to invoke which will handle the timings
3479
+ * @return Status of the operation.
3480
+ * @committed
3481
+ */
3482
+ LIBCOUCHBASE_API
3483
+ lcb_error_t lcb_get_timings(lcb_t instance,
3484
+ const void *cookie,
3485
+ lcb_timings_callback callback);
3486
+ /**@} (Group: Timings) */
3487
+
3488
+ /**
3489
+ * @ingroup lcb-public-api
3490
+ * @defgroup lcb-build-info Build Information
3491
+ * @brief Get library version and supported features
3492
+ * @details
3493
+ * These functions and macros may be used to conditionally compile features
3494
+ * depending on the version of the library being used. They may also be used
3495
+ * to employ various features at runtime and to retrieve the version for
3496
+ * informational purposes.
3497
+ * @addtogroup lcb-build-info
3498
+ * @{
3499
+ */
3500
+
3501
+ #if !defined(LCB_VERSION_STRING) || defined(__LCB_DOXYGEN__)
3502
+ /** @brief libcouchbase version string */
3503
+ #define LCB_VERSION_STRING "unknown"
3504
+ #endif
3505
+
3506
+ #if !defined(LCB_VERSION) || defined(__LCB_DOXYGEN__)
3507
+ /**@brief libcouchbase hex version
3508
+ *
3509
+ * This number contains the hexadecimal representation of the library version.
3510
+ * It is in a format of `0xXXYYZZ` where `XX` is the two digit major version
3511
+ * (e.g. `02`), `YY` is the minor version (e.g. `05`) and `ZZ` is the patch
3512
+ * version (e.g. `24`).
3513
+ *
3514
+ * For example:
3515
+ *
3516
+ * String |Hex
3517
+ * ---------|---------
3518
+ * 2.0.0 | 0x020000
3519
+ * 2.1.3 | 0x020103
3520
+ * 3.0.15 | 0x030015
3521
+ */
3522
+ #define LCB_VERSION 0x000000
3523
+ #endif
3524
+
3525
+ #if !defined(LCB_VERSION_CHANGESET) || defined(__LCB_DOXYGEN__)
3526
+ /**@brief The SCM revision ID. @see LCB_CNTL_CHANGESET */
3527
+ #define LCB_VERSION_CHANGESET "0xdeadbeef"
3528
+ #endif
3529
+
3530
+ /**
3531
+ * Get the version of the library.
3532
+ *
3533
+ * @param version where to store the numeric representation of the
3534
+ * version (or NULL if you don't care)
3535
+ *
3536
+ * @return the textual description of the version ('\0'
3537
+ * terminated). Do <b>not</b> try to release this string.
3538
+ *
3539
+ */
3540
+ LIBCOUCHBASE_API
3541
+ const char *lcb_get_version(lcb_U32 *version);
3542
+
3543
+ /** Global/extern variable containing the version of the library */
3544
+ LIBCOUCHBASE_API LCB_EXTERN_VAR
3545
+ const lcb_U32 lcb_version_g;
3546
+
3547
+ /**@brief Whether the library has SSL support*/
3548
+ #define LCB_SUPPORTS_SSL 1
3549
+ /**@brief Whether the library has experimental compression support */
3550
+ #define LCB_SUPPORTS_SNAPPY 2
3551
+
3552
+ /**
3553
+ * @committed
3554
+ * Determine if this version has support for a particularl feature
3555
+ * @param n the feature ID to check for
3556
+ * @return 0 if not supported, nonzero if supported.
3557
+ */
3558
+ LIBCOUCHBASE_API
3559
+ int
3560
+ lcb_supports_feature(int n);
3561
+
3562
+ /**@} (Group: Build Info) */
3563
+
3564
+
3565
+ /**
3566
+ * Functions to allocate and free memory related to libcouchbase. This is
3567
+ * mainly for use on Windows where it is possible that the DLL and EXE
3568
+ * are using two different CRTs
3569
+ */
3570
+ LIBCOUCHBASE_API
3571
+ void *lcb_mem_alloc(lcb_SIZE size);
3572
+
3573
+ /** Use this to free memory allocated with lcb_mem_alloc */
3574
+ LIBCOUCHBASE_API
3575
+ void lcb_mem_free(void *ptr);
3576
+
3577
+ /**
3578
+ * @private
3579
+ *
3580
+ * These two functions unconditionally start and stop the event loop. These
3581
+ * should be used _only_ when necessary. Use lcb_wait and lcb_breakout
3582
+ * for safer variants.
3583
+ *
3584
+ * Internally these proxy to the run_event_loop/stop_event_loop calls
3585
+ */
3586
+ LCB_INTERNAL_API
3587
+ void lcb_run_loop(lcb_t instance);
3588
+
3589
+ /** @private */
3590
+ LCB_INTERNAL_API
3591
+ void lcb_stop_loop(lcb_t instance);
3592
+
3593
+ /** @private */
3594
+ /* This returns the library's idea of time */
3595
+ LCB_INTERNAL_API
3596
+ lcb_U64 lcb_nstime(void);
3597
+
3598
+ typedef enum {
3599
+ /** Dump the raw vbucket configuration */
3600
+ LCB_DUMP_VBCONFIG = 0x01,
3601
+ /** Dump information about each packet */
3602
+ LCB_DUMP_PKTINFO = 0x02,
3603
+ /** Dump memory usage/reservation information about buffers */
3604
+ LCB_DUMP_BUFINFO = 0x04,
3605
+ /** Dump everything */
3606
+ LCB_DUMP_ALL = 0xff
3607
+ } lcb_DUMPFLAGS;
3608
+
3609
+ /** Internal histogram APIs, used by pillowfight and others */
3610
+ struct lcb_histogram_st;
3611
+ typedef struct lcb_histogram_st lcb_HISTOGRAM;
3612
+
3613
+ /**
3614
+ * @private
3615
+ * Create a histogram structure
3616
+ * @return a new histogram structure
3617
+ */
3618
+ LCB_INTERNAL_API
3619
+ lcb_HISTOGRAM *
3620
+ lcb_histogram_create(void);
3621
+
3622
+ /**
3623
+ * @private free a histogram structure
3624
+ * @param hg the histogram
3625
+ */
3626
+ LCB_INTERNAL_API
3627
+ void
3628
+ lcb_histogram_destroy(lcb_HISTOGRAM *hg);
3629
+
3630
+ /**
3631
+ * @private
3632
+ * Add an entry to a histogram structure
3633
+ * @param hg the histogram
3634
+ * @param duration the duration in nanoseconds
3635
+ */
3636
+ LCB_INTERNAL_API
3637
+ void
3638
+ lcb_histogram_record(lcb_HISTOGRAM *hg, lcb_U64 duration);
3639
+
3640
+ typedef void (*lcb_HISTOGRAM_CALLBACK)
3641
+ (const void *cookie, lcb_timeunit_t timeunit, lcb_U32 min, lcb_U32 max,
3642
+ lcb_U32 total, lcb_U32 maxtotal);
3643
+
3644
+ /**
3645
+ * @private
3646
+ * Repeatedly invoke a callback for all entries in the histogram
3647
+ * @param hg the histogram
3648
+ * @param cookie pointer passed to callback
3649
+ * @param cb callback to invoke
3650
+ */
3651
+ LCB_INTERNAL_API
3652
+ void
3653
+ lcb_histogram_read(const lcb_HISTOGRAM *hg, const void *cookie,
3654
+ lcb_HISTOGRAM_CALLBACK cb);
3655
+
3656
+ /**
3657
+ * Print the histogram to the specified FILE.
3658
+ *
3659
+ * This essentially outputs the same raw information as lcb_histogram_read(),
3660
+ * except it prints in implementation-defined format. It's simpler to use
3661
+ * than lcb_histogram_read, but less flexible.
3662
+ *
3663
+ * @param hg the histogram
3664
+ * @param stream File to print the histogram to.
3665
+ */
3666
+ LCB_INTERNAL_API
3667
+ void lcb_histogram_print(lcb_HISTOGRAM* hg, FILE* stream);
3668
+
3669
+ /* Post-include some other headers */
3670
+ #ifdef __cplusplus
3671
+ }
3672
+ #endif /* __cplusplus */
3673
+ #include <libcouchbase/subdoc.h>
3674
+ #include <libcouchbase/cntl.h>
3675
+ #include <libcouchbase/deprecated.h>
3676
+ #include <libcouchbase/api-legacy.h>
3677
+ #endif /* LIBCOUCHBASE_COUCHBASE_H */