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,157 @@
1
+ /*
2
+ * Copyright 2015 Couchbase, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #define LCBDUR_PRIV_SYMS
18
+
19
+ #include "internal.h"
20
+ #include <libcouchbase/api3.h>
21
+ #include "durability_internal.h"
22
+
23
+ #define ENT_SEQNO(ent) (ent)->reqseqno
24
+
25
+ static void
26
+ seqno_callback(lcb_t instance, int ign, const lcb_RESPBASE *rb)
27
+ {
28
+ const lcb_RESPOBSEQNO *resp = (const lcb_RESPOBSEQNO*)rb;
29
+ char *pp = resp->cookie;
30
+ lcb_DURITEM *ent;
31
+ int flags = 0;
32
+ lcb_U64 seqno_mem, seqno_disk;
33
+
34
+ pp -= offsetof(lcb_DURITEM, callback);
35
+ ent = (lcb_DURITEM *)pp;
36
+ /* Now, process the response */
37
+
38
+ if (resp->rc != LCB_SUCCESS) {
39
+ RESFLD(ent, rc) = resp->rc;
40
+ goto GT_TALLY;
41
+ }
42
+
43
+ if (resp->old_uuid) {
44
+ /* Failover! */
45
+ seqno_mem = seqno_disk = resp->old_seqno;
46
+ if (seqno_mem < ENT_SEQNO(ent)) {
47
+ RESFLD(ent, rc) = LCB_MUTATION_LOST;
48
+ lcbdur_ent_finish(ent);
49
+ goto GT_TALLY;
50
+ }
51
+ } else {
52
+ seqno_mem = resp->mem_seqno;
53
+ seqno_disk = resp->persisted_seqno;
54
+ }
55
+
56
+ if (seqno_mem < ENT_SEQNO(ent)) {
57
+ goto GT_TALLY;
58
+ }
59
+
60
+ flags = LCBDUR_UPDATE_REPLICATED;
61
+ if (seqno_disk >= ENT_SEQNO(ent)) {
62
+ flags |= LCBDUR_UPDATE_PERSISTED;
63
+ }
64
+
65
+ lcbdur_update_item(ent, flags, resp->server_index);
66
+
67
+ GT_TALLY:
68
+ if (!--ent->parent->waiting) {
69
+ /* avoid ssertion (wait==0)! */
70
+ ent->parent->waiting = 1;
71
+ lcbdur_reqs_done(ent->parent);
72
+ }
73
+
74
+ (void)ign; (void)instance;
75
+ }
76
+
77
+ static lcb_error_t
78
+ seqno_poll(lcb_DURSET *dset)
79
+ {
80
+ lcb_error_t ret_err = LCB_EINTERNAL; /* This should never be returned */
81
+ size_t ii;
82
+ int has_ops = 0;
83
+ lcb_t instance = dset->instance;
84
+
85
+ lcb_sched_enter(instance);
86
+ for (ii = 0; ii < DSET_COUNT(dset); ii++) {
87
+ lcb_DURITEM *ent = DSET_ENTRIES(dset) + ii;
88
+ size_t jj, nservers = 0;
89
+ lcb_U16 servers[4];
90
+ lcb_CMDOBSEQNO cmd = { 0 };
91
+
92
+ if (ent->done) {
93
+ continue;
94
+ }
95
+
96
+ cmd.uuid = ent->uuid;
97
+ cmd.vbid = ent->vbid;
98
+ cmd.cmdflags = LCB_CMD_F_INTERNAL_CALLBACK;
99
+ ent->callback = seqno_callback;
100
+
101
+ lcbdur_prepare_item(ent, servers, &nservers);
102
+ for (jj = 0; jj < nservers; jj++) {
103
+ lcb_error_t err;
104
+ cmd.server_index = servers[jj];
105
+ err = lcb_observe_seqno3(instance, &ent->callback, &cmd);
106
+ if (err == LCB_SUCCESS) {
107
+ dset->waiting++;
108
+ has_ops = 1;
109
+ } else {
110
+ RESFLD(ent, rc) = ret_err = err;
111
+ }
112
+ }
113
+ }
114
+ lcb_sched_leave(instance);
115
+ if (!has_ops) {
116
+ return ret_err;
117
+ } else {
118
+ return LCB_SUCCESS;
119
+ }
120
+ }
121
+
122
+ static lcb_error_t
123
+ seqno_ent_add(lcb_DURSET *dset, lcb_DURITEM *item, const lcb_CMDENDURE *cmd)
124
+ {
125
+ const lcb_MUTATION_TOKEN *stok = NULL;
126
+
127
+ if (cmd->cmdflags & LCB_CMDENDURE_F_MUTATION_TOKEN) {
128
+ stok = cmd->mutation_token;
129
+ }
130
+
131
+ if (stok == NULL) {
132
+ lcb_t instance = dset->instance;
133
+ if (!instance->dcpinfo) {
134
+ return LCB_DURABILITY_NO_MUTATION_TOKENS;
135
+ }
136
+ if (item->vbid >= LCBT_VBCONFIG(instance)->nvb) {
137
+ return LCB_EINVAL;
138
+ }
139
+ stok = instance->dcpinfo + item->vbid;
140
+ if (LCB_MUTATION_TOKEN_ID(stok) == 0) {
141
+ return LCB_DURABILITY_NO_MUTATION_TOKENS;
142
+ }
143
+ }
144
+
145
+ /* Set the fields */
146
+ memset(item->sinfo, 0, sizeof(item->sinfo[0]) * 4);
147
+ item->uuid = LCB_MUTATION_TOKEN_ID(stok);
148
+ ENT_SEQNO(item) = LCB_MUTATION_TOKEN_SEQ(stok);
149
+ return LCB_SUCCESS;
150
+ }
151
+
152
+ lcbdur_PROCS lcbdur_seqno_procs = {
153
+ seqno_poll,
154
+ seqno_ent_add,
155
+ NULL, /*schedule*/
156
+ NULL /*clean*/
157
+ };
@@ -0,0 +1,668 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 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
+ #define LCBDUR_PRIV_SYMS 1
19
+
20
+ #include "internal.h"
21
+ #include "durability_internal.h"
22
+ #include <lcbio/iotable.h>
23
+ #define LOGARGS(c, lvl) (c)->instance->settings, "endure", LCB_LOG_##lvl, __FILE__, __LINE__
24
+
25
+ static void timer_callback(lcb_socket_t sock, short which, void *arg);
26
+ static void poll_once(lcb_DURSET *dset);
27
+
28
+ int
29
+ lcbdur_ent_check_done(lcb_DURITEM *ent)
30
+ {
31
+ lcb_DURABILITYOPTSv0 *opts = &ent->parent->opts;
32
+
33
+ if (!RESFLD(ent, exists_master)) {
34
+ /** Primary cache doesn't have correct version */
35
+ return 0;
36
+ }
37
+ if (opts->persist_to) {
38
+ if (!RESFLD(ent, persisted_master)) {
39
+ return 0;
40
+ }
41
+ if (RESFLD(ent, npersisted) < opts->persist_to) {
42
+ return 0;
43
+ }
44
+ }
45
+
46
+ if (opts->replicate_to) {
47
+ if (RESFLD(ent, nreplicated) < opts->replicate_to) {
48
+ return 0;
49
+ }
50
+ }
51
+
52
+ return 1;
53
+ }
54
+
55
+ static int
56
+ server_criteria_satisfied(const lcb_DURITEM *item,
57
+ const lcbdur_SERVINFO *info, int is_master)
58
+ {
59
+ const lcb_DURSET *dset = item->parent;
60
+ if (!info->exists) {
61
+ return 0;
62
+ }
63
+ if (info->persisted) {
64
+ return 1;
65
+ }
66
+ if (DSET_OPTFLD(dset, persist_to) == 0) {
67
+ return 1;
68
+ }
69
+ if (DSET_OPTFLD(dset, persist_to) == 1 && !is_master) {
70
+ return 1;
71
+ }
72
+ return 0;
73
+ }
74
+
75
+ void
76
+ lcbdur_prepare_item(lcb_DURITEM *ent, lcb_U16 *ixarray, size_t *nitems)
77
+ {
78
+ size_t ii, oix = 0, maxix = 0;
79
+ lcb_DURSET *dset = ent->parent;
80
+ lcb_t instance = dset->instance;
81
+ lcbvb_CONFIG *vbc = LCBT_VBCONFIG(instance);
82
+
83
+ RESFLD(ent, persisted_master) = 0;
84
+ RESFLD(ent, exists_master) = 0;
85
+ RESFLD(ent, npersisted) = 0;
86
+ RESFLD(ent, nreplicated) = 0;
87
+ RESFLD(ent, cas) = 0;
88
+ RESFLD(ent, rc) = LCB_SUCCESS;
89
+
90
+ if (DSET_OPTFLD(dset, persist_to) == 1 &&
91
+ DSET_OPTFLD(dset, replicate_to) == 0) {
92
+ maxix = 1; /* Only master! */
93
+ } else {
94
+ maxix = LCBT_NREPLICAS(instance) + 1;
95
+ }
96
+
97
+ for (ii = 0; ii < maxix; ii++) {
98
+ int cur_ix;
99
+ lcbdur_SERVINFO *info = &ent->sinfo[ii];
100
+ const mc_SERVER *s_exp;
101
+
102
+ cur_ix = lcbvb_vbserver(vbc, ent->vbid, ii);
103
+ if (cur_ix < 0) {
104
+ memset(info, 0, sizeof(*info));
105
+ continue;
106
+ }
107
+
108
+ s_exp = LCBT_GET_SERVER(instance, cur_ix);
109
+ if (s_exp != info->server) {
110
+ memset(info, 0, sizeof(*info));
111
+
112
+ } else if (server_criteria_satisfied(ent, info, ii==0)) {
113
+ /* Update counters as required */
114
+ if (ii == 0) {
115
+ RESFLD(ent, exists_master) = 1;
116
+ } else {
117
+ RESFLD(ent, nreplicated)++;
118
+ }
119
+
120
+ if (info->persisted) {
121
+ RESFLD(ent, npersisted)++;
122
+ if (ii == 0) {
123
+ RESFLD(ent, persisted_master) = 1;
124
+ }
125
+ }
126
+ continue;
127
+ }
128
+
129
+ /* Otherwise, write the expected server out */
130
+ ixarray[oix++] = s_exp->pipeline.index;
131
+ }
132
+ *nitems = oix;
133
+ }
134
+
135
+ void
136
+ lcbdur_update_item(lcb_DURITEM *item, int flags, int srvix)
137
+ {
138
+ lcbdur_SERVINFO *info;
139
+ lcb_t instance;
140
+ int is_master;
141
+ const mc_SERVER *server;
142
+
143
+ if (!flags || item->done) {
144
+ return;
145
+ }
146
+
147
+ info = lcbdur_ent_getinfo(item, srvix);
148
+ if (!info) {
149
+ lcb_log(LOGARGS(item->parent, DEBUG), "Ignoring response from server %d. Not a master or replica for vBucket %d", srvix, item->vbid);
150
+ return;
151
+ }
152
+
153
+ instance = item->parent->instance;
154
+ is_master = lcbvb_vbmaster(LCBT_VBCONFIG(instance), item->vbid) == srvix;
155
+ server = LCBT_GET_SERVER(instance, srvix);
156
+
157
+ memset(info, 0, sizeof(*info));
158
+ info->server = server;
159
+
160
+ if (flags & LCBDUR_UPDATE_PERSISTED) {
161
+ info->persisted = 1;
162
+ RESFLD(item, npersisted)++;
163
+ if (is_master) {
164
+ RESFLD(item, persisted_master) = 1;
165
+ }
166
+ }
167
+ if (flags & LCBDUR_UPDATE_REPLICATED) {
168
+ info->exists = 1;
169
+ if (is_master) {
170
+ RESFLD(item, exists_master) = 1;
171
+ } else {
172
+ RESFLD(item, nreplicated)++;
173
+ }
174
+ }
175
+ if (lcbdur_ent_check_done(item)) {
176
+ RESFLD(item, rc) = LCB_SUCCESS;
177
+ lcbdur_ent_finish(item);
178
+ }
179
+ }
180
+
181
+ lcbdur_SERVINFO *
182
+ lcbdur_ent_getinfo(lcb_DURITEM *item, int srvix)
183
+ {
184
+ size_t ii;
185
+ lcb_t instance = item->parent->instance;
186
+
187
+ for (ii = 0; ii < LCBT_NREPLICAS(instance)+1; ii++) {
188
+ int ix = lcbvb_vbserver(LCBT_VBCONFIG(instance), item->vbid, ii);
189
+ if (ix > -1 && ix == srvix) {
190
+ return &item->sinfo[ii];
191
+ }
192
+ }
193
+ return NULL;
194
+ }
195
+
196
+ void lcbdur_ent_finish(lcb_DURITEM *ent)
197
+ {
198
+ lcb_RESPCALLBACK callback;
199
+ lcb_t instance;
200
+
201
+ if (ent->done) {
202
+ return;
203
+ }
204
+
205
+ ent->done = 1;
206
+ ent->parent->nremaining--;
207
+
208
+ /** Invoke the callback now :) */
209
+ ent->result.cookie = (void *)ent->parent->cookie;
210
+ instance = ent->parent->instance;
211
+
212
+ if (ent->parent->is_durstore) {
213
+ lcb_RESPSTOREDUR resp = { 0 };
214
+ resp.key = ent->result.key;
215
+ resp.nkey = ent->result.nkey;
216
+ resp.rc = ent->result.rc;
217
+ resp.cas = ent->reqcas;
218
+ resp.cookie = ent->result.cookie;
219
+ resp.store_ok = 1;
220
+ resp.dur_resp = &ent->result;
221
+
222
+ callback = lcb_find_callback(instance, LCB_CALLBACK_STOREDUR);
223
+ callback(instance, LCB_CALLBACK_STOREDUR, (lcb_RESPBASE*)&resp);
224
+ } else {
225
+ callback = lcb_find_callback(instance, LCB_CALLBACK_ENDURE);
226
+ callback(instance, LCB_CALLBACK_ENDURE, (lcb_RESPBASE*)&ent->result);
227
+ }
228
+
229
+ if (ent->parent->nremaining == 0) {
230
+ lcbdur_unref(ent->parent);
231
+ }
232
+ }
233
+
234
+ /**
235
+ * Called when the last (primitive) OBSERVE response is received for the entry.
236
+ */
237
+ void lcbdur_reqs_done(lcb_DURSET *dset)
238
+ {
239
+ lcb_assert(dset->waiting || ("Got NULL callback twice!" && 0));
240
+
241
+ dset->waiting = 0;
242
+
243
+ if (dset->nremaining > 0) {
244
+ lcbdur_switch_state(dset, LCBDUR_STATE_OBSPOLL);
245
+ }
246
+ lcbdur_unref(dset);
247
+ }
248
+
249
+ /**
250
+ * Schedules a single sweep of observe requests.
251
+ * The `initial` parameter determines if this is a retry or if this is the
252
+ * initial scheduling.
253
+ */
254
+ static void poll_once(lcb_DURSET *dset)
255
+ {
256
+ lcb_error_t err;
257
+
258
+ /* We should never be called while an 'iter' operation is still in progress */
259
+ lcb_assert(dset->waiting == 0);
260
+ lcbdur_ref(dset);
261
+
262
+ err = DSET_PROCS(dset)->poll(dset);
263
+ if (err == LCB_SUCCESS) {
264
+ lcbdur_ref(dset);
265
+ lcbdur_switch_state(dset, LCBDUR_STATE_TIMEOUT);
266
+ } else {
267
+ dset->lasterr = err;
268
+ lcbdur_switch_state(dset, LCBDUR_STATE_OBSPOLL);
269
+ }
270
+
271
+ lcbdur_unref(dset);
272
+ }
273
+
274
+ #define DUR_MIN(a,b) (a) < (b) ? (a) : (b)
275
+
276
+ LIBCOUCHBASE_API
277
+ lcb_error_t
278
+ lcb_durability_validate(lcb_t instance,
279
+ lcb_U16 *persist_to, lcb_U16 *replicate_to, int options)
280
+ {
281
+ int replica_max = DUR_MIN(
282
+ LCBT_NREPLICAS(instance),
283
+ LCBT_NDATASERVERS(instance)-1);
284
+ int persist_max = replica_max + 1;
285
+
286
+ if (*persist_to == 0 && *replicate_to == 0) {
287
+ /* Empty values! */
288
+ return LCB_EINVAL;
289
+ }
290
+
291
+ /* persist_max is always one more than replica_max */
292
+ if ((int)*persist_to > persist_max) {
293
+ if (options & LCB_DURABILITY_VALIDATE_CAPMAX) {
294
+ *persist_to = persist_max;
295
+ } else {
296
+ return LCB_DURABILITY_ETOOMANY;
297
+ }
298
+ }
299
+
300
+ if (*replicate_to == 0) {
301
+ return LCB_SUCCESS;
302
+ }
303
+
304
+ if (replica_max < 0) {
305
+ replica_max = 0;
306
+ }
307
+
308
+ /* now, we need at least as many nodes as we have replicas */
309
+ if ((int)*replicate_to > replica_max) {
310
+ if (options & LCB_DURABILITY_VALIDATE_CAPMAX) {
311
+ *replicate_to = replica_max;
312
+ } else {
313
+ return LCB_DURABILITY_ETOOMANY;
314
+ }
315
+ }
316
+ return LCB_SUCCESS;
317
+
318
+ }
319
+
320
+ #define CTX_FROM_MULTI(mcmd) (void *) ((((char *) (mcmd))) - offsetof(lcb_DURSET, mctx))
321
+
322
+ static lcb_error_t
323
+ dset_ctx_add(lcb_MULTICMD_CTX *mctx, const lcb_CMDBASE *cmd)
324
+ {
325
+ lcb_DURSET *dset = CTX_FROM_MULTI(mctx);
326
+ lcb_DURITEM *ent;
327
+ int vbid, srvix;
328
+
329
+ if (LCB_KEYBUF_IS_EMPTY(&cmd->key)) {
330
+ return LCB_EMPTY_KEY;
331
+ }
332
+
333
+ LCB_SSOBUF_ALLOC(&ent, &dset->entries_, lcb_DURITEM);
334
+ if (!ent) {
335
+ return LCB_CLIENT_ENOMEM;
336
+ }
337
+
338
+ mcreq_map_key(&dset->instance->cmdq, &cmd->key, &cmd->_hashkey,
339
+ MCREQ_PKT_BASESIZE, &vbid, &srvix);
340
+
341
+ /* ok. now let's initialize the entry..*/
342
+ memset(ent, 0, sizeof (*ent));
343
+ RESFLD(ent, nkey) = cmd->key.contig.nbytes;
344
+ ent->reqcas = cmd->cas;
345
+ ent->parent = dset;
346
+ ent->vbid = vbid;
347
+
348
+ lcb_string_append(&dset->kvbufs,
349
+ cmd->key.contig.bytes, cmd->key.contig.nbytes);
350
+ if (DSET_PROCS(dset)->ent_add) {
351
+ return DSET_PROCS(dset)->ent_add(dset, ent, (lcb_CMDENDURE*)cmd);
352
+ } else {
353
+ return LCB_SUCCESS;
354
+ }
355
+ }
356
+
357
+ static lcb_error_t
358
+ dset_ctx_schedule(lcb_MULTICMD_CTX *mctx, const void *cookie)
359
+ {
360
+ size_t ii;
361
+ lcb_error_t err;
362
+ lcb_DURSET *dset = CTX_FROM_MULTI(mctx);
363
+ char *kptr = dset->kvbufs.base;
364
+
365
+ if (!DSET_COUNT(dset)) {
366
+ lcbdur_destroy(dset);
367
+ return LCB_EINVAL;
368
+ }
369
+
370
+ for (ii = 0; ii < DSET_COUNT(dset); ii++) {
371
+ lcb_DURITEM *ent = DSET_ENTRIES(dset) + ii;
372
+ RESFLD(ent, key) = kptr;
373
+ kptr += RESFLD(ent, nkey);
374
+ }
375
+
376
+ if (DSET_PROCS(dset)->schedule) {
377
+ err = DSET_PROCS(dset)->schedule(dset);
378
+ if (err != LCB_SUCCESS) {
379
+ lcbdur_destroy(dset);
380
+ return err;
381
+ }
382
+ }
383
+
384
+ lcbdur_ref(dset);
385
+ dset->cookie = cookie;
386
+ dset->nremaining = DSET_COUNT(dset);
387
+ dset->ns_timeout = gethrtime() + LCB_US2NS(DSET_OPTFLD(dset, timeout));
388
+
389
+ lcb_aspend_add(&dset->instance->pendops, LCB_PENDTYPE_DURABILITY, dset);
390
+ lcbdur_switch_state(dset, LCBDUR_STATE_INIT);
391
+ return LCB_SUCCESS;
392
+ }
393
+
394
+ static void
395
+ dset_ctx_fail(lcb_MULTICMD_CTX *mctx)
396
+ {
397
+ lcb_DURSET *dset = CTX_FROM_MULTI(mctx);
398
+ lcbdur_destroy(dset);
399
+ }
400
+
401
+ void lcbdurctx_set_durstore(lcb_MULTICMD_CTX *mctx, int enabled)
402
+ {
403
+
404
+ lcb_DURSET *dset = CTX_FROM_MULTI(mctx);
405
+ dset->is_durstore = enabled;
406
+ }
407
+
408
+ static lcb_U8
409
+ get_poll_meth(lcb_t instance, const lcb_DURABILITYOPTSv0 *options)
410
+ {
411
+ /* Need to call this first, so we can actually allocate the appropriate
412
+ * data for this.. */
413
+ lcb_U8 meth = options->pollopts;
414
+ if (meth == LCB_DURABILITY_MODE_DEFAULT) {
415
+ meth = LCB_DURABILITY_MODE_CAS;
416
+
417
+ if (LCBT_SETTING(instance, fetch_mutation_tokens) &&
418
+ LCBT_SETTING(instance, dur_mutation_tokens)) {
419
+ size_t ii;
420
+ for (ii = 0; ii < LCBT_NSERVERS(instance); ii++) {
421
+ mc_SERVER *s = LCBT_GET_SERVER(instance, ii);
422
+ if (s->mutation_tokens) {
423
+ meth = LCB_DURABILITY_MODE_SEQNO;
424
+ break;
425
+ }
426
+ }
427
+ }
428
+ }
429
+ return meth;
430
+ }
431
+
432
+ LIBCOUCHBASE_API
433
+ lcb_MULTICMD_CTX *
434
+ lcb_endure3_ctxnew(lcb_t instance, const lcb_durability_opts_t *options,
435
+ lcb_error_t *errp)
436
+ {
437
+ lcb_DURSET *dset;
438
+ lcb_error_t err_s;
439
+ lcbio_pTABLE io = instance->iotable;
440
+ const lcb_DURABILITYOPTSv0 *opts_in = &options->v.v0;
441
+
442
+ if (!errp) {
443
+ errp = &err_s;
444
+ }
445
+
446
+ *errp = LCB_SUCCESS;
447
+
448
+ if (!LCBT_VBCONFIG(instance)) {
449
+ *errp = LCB_CLIENT_ETMPFAIL;
450
+ return NULL;
451
+ }
452
+
453
+ dset = calloc(1, sizeof(*dset));
454
+ if (!dset) {
455
+ *errp = LCB_CLIENT_ENOMEM;
456
+ return NULL;
457
+ }
458
+
459
+ /* Ensure we don't clobber options from older versions */
460
+ dset->opts.cap_max = opts_in->cap_max;
461
+ dset->opts.check_delete = opts_in->check_delete;
462
+ dset->opts.interval = opts_in->interval;
463
+ dset->opts.persist_to = opts_in->persist_to;
464
+ dset->opts.replicate_to = opts_in->replicate_to;
465
+ dset->opts.timeout = opts_in->timeout;
466
+
467
+ if (options->version > 0) {
468
+ dset->opts.pollopts = opts_in->pollopts;
469
+ }
470
+
471
+ dset->opts.pollopts = get_poll_meth(instance, &dset->opts);
472
+
473
+ dset->instance = instance;
474
+ dset->mctx.addcmd = dset_ctx_add;
475
+ dset->mctx.done = dset_ctx_schedule;
476
+ dset->mctx.fail = dset_ctx_fail;
477
+
478
+ if (!DSET_OPTFLD(dset, timeout)) {
479
+ DSET_OPTFLD(dset, timeout) = LCBT_SETTING(instance, durability_timeout);
480
+ }
481
+ if (!DSET_OPTFLD(dset, interval)) {
482
+ DSET_OPTFLD(dset, interval) = LCBT_SETTING(instance, durability_interval);
483
+ }
484
+
485
+ *errp = lcb_durability_validate(instance,
486
+ &dset->opts.persist_to, &dset->opts.replicate_to,
487
+ dset->opts.cap_max ? LCB_DURABILITY_VALIDATE_CAPMAX : 0);
488
+
489
+ if (*errp != LCB_SUCCESS) {
490
+ free(dset);
491
+ return NULL;
492
+ }
493
+
494
+ dset->timer = io->timer.create(io->p);
495
+ lcb_string_init(&dset->kvbufs);
496
+ return &dset->mctx;
497
+ }
498
+
499
+ LIBCOUCHBASE_API
500
+ lcb_error_t
501
+ lcb_durability_poll(lcb_t instance, const void *cookie,
502
+ const lcb_durability_opts_t *options, lcb_size_t ncmds,
503
+ const lcb_durability_cmd_t *const *cmds)
504
+ {
505
+ lcb_MULTICMD_CTX *mctx;
506
+ unsigned ii;
507
+ lcb_error_t err;
508
+
509
+ if (ncmds == 0) {
510
+ return LCB_EINVAL;
511
+ }
512
+
513
+ mctx = lcb_endure3_ctxnew(instance, options, &err);
514
+ if (!mctx) {
515
+ return err;
516
+ }
517
+
518
+ for (ii = 0; ii < ncmds; ii++) {
519
+ lcb_CMDENDURE cmd = { 0 };
520
+ const lcb_DURABILITYCMDv0 *src = &cmds[ii]->v.v0;
521
+ cmd.key.contig.bytes = src->key;
522
+ cmd.key.contig.nbytes = src->nkey;
523
+ cmd._hashkey.contig.bytes = src->hashkey;
524
+ cmd._hashkey.contig.nbytes = src->nhashkey;
525
+ cmd.cas = src->cas;
526
+
527
+ err = mctx->addcmd(mctx, (lcb_CMDBASE*)&cmd);
528
+ if (err != LCB_SUCCESS) {
529
+ mctx->fail(mctx);
530
+ return err;
531
+ }
532
+ }
533
+
534
+ lcb_sched_enter(instance);
535
+ err = mctx->done(mctx, cookie);
536
+ if (err != LCB_SUCCESS) {
537
+ lcb_sched_fail(instance);
538
+ return err;
539
+ } else {
540
+ lcb_sched_leave(instance);
541
+ SYNCMODE_INTERCEPT(instance)
542
+ }
543
+ }
544
+
545
+ /**
546
+ * Decrement the refcount for the 'dset'. When it hits zero then the dset is
547
+ * freed.
548
+ */
549
+ void lcbdur_unref(lcb_DURSET *dset)
550
+ {
551
+ if (--dset->refcnt == 0) {
552
+ lcbdur_destroy(dset);
553
+ }
554
+ }
555
+
556
+ /**
557
+ * Actually free the resources allocated by the dset (and all its entries).
558
+ * Called by some other functions in libcouchbase
559
+ */
560
+ void lcbdur_destroy(lcb_DURSET *dset)
561
+ {
562
+ lcb_t instance = dset->instance;
563
+
564
+ if (DSET_PROCS(dset)->clean) {
565
+ DSET_PROCS(dset)->clean(dset);
566
+ }
567
+
568
+ if (dset->timer) {
569
+ lcbio_TABLE *io = instance->iotable;
570
+ io->timer.cancel(io->p, dset->timer);
571
+ io->timer.destroy(io->p, dset->timer);
572
+ dset->timer = NULL;
573
+ }
574
+
575
+ lcb_aspend_del(&dset->instance->pendops, LCB_PENDTYPE_DURABILITY, dset);
576
+ LCB_SSOBUF_CLEAN(&dset->entries_);
577
+ lcb_string_release(&dset->kvbufs);
578
+ free(dset);
579
+ lcb_maybe_breakout(instance);
580
+ }
581
+
582
+ /**
583
+ * All-purpose callback dispatcher.
584
+ */
585
+ static void timer_callback(lcb_socket_t sock, short which, void *arg)
586
+ {
587
+ lcb_DURSET *dset = arg;
588
+ hrtime_t now = gethrtime();
589
+
590
+ if (dset->ns_timeout && now > dset->ns_timeout) {
591
+ dset->next_state = LCBDUR_STATE_TIMEOUT;
592
+ }
593
+
594
+ switch (dset->next_state) {
595
+ case LCBDUR_STATE_OBSPOLL:
596
+ case LCBDUR_STATE_INIT:
597
+ poll_once(dset);
598
+ break;
599
+
600
+ case LCBDUR_STATE_TIMEOUT: {
601
+ lcb_size_t ii;
602
+ lcb_error_t err = dset->lasterr ? dset->lasterr : LCB_ETIMEDOUT;
603
+ dset->ns_timeout = 0;
604
+ dset->next_state = LCBDUR_STATE_IGNORE;
605
+
606
+ lcb_log(LOGARGS(dset, WARN), "Polling durability timed out!");
607
+
608
+ lcbdur_ref(dset);
609
+
610
+ for (ii = 0; ii < DSET_COUNT(dset); ii++) {
611
+ lcb_DURITEM *ent = DSET_ENTRIES(dset) + ii;
612
+ if (ent->done) {
613
+ continue;
614
+ }
615
+ if (RESFLD(ent, rc) == LCB_SUCCESS) {
616
+ RESFLD(ent, rc) = err;
617
+ }
618
+ lcbdur_ent_finish(ent);
619
+ }
620
+
621
+ lcbdur_unref(dset);
622
+ break;
623
+ }
624
+
625
+ case LCBDUR_STATE_IGNORE:
626
+ break;
627
+
628
+ default:
629
+ lcb_assert("unexpected state" && 0);
630
+ break;
631
+ }
632
+
633
+ (void)sock;
634
+ (void)which;
635
+ }
636
+
637
+ /**
638
+ * Schedules us to be notified with the given state within a particular amount
639
+ * of time. This is used both for the timeout and for the interval
640
+ */
641
+ void
642
+ lcbdur_switch_state(lcb_DURSET *dset, unsigned int state)
643
+ {
644
+ lcb_U32 delay = 0;
645
+ lcbio_TABLE* io = dset->instance->iotable;
646
+ hrtime_t now = gethrtime();
647
+
648
+ if (state == LCBDUR_STATE_TIMEOUT) {
649
+ if (dset->ns_timeout && now < dset->ns_timeout) {
650
+ delay = LCB_NS2US(dset->ns_timeout - now);
651
+ } else {
652
+ delay = 0;
653
+ }
654
+ } else if (state == LCBDUR_STATE_OBSPOLL) {
655
+ if (now + LCB_US2NS(DSET_OPTFLD(dset, interval)) < dset->ns_timeout) {
656
+ delay = DSET_OPTFLD(dset, interval);
657
+ } else {
658
+ delay = 0;
659
+ state = LCBDUR_STATE_TIMEOUT;
660
+ }
661
+ } else if (state == LCBDUR_STATE_INIT) {
662
+ delay = 0;
663
+ }
664
+
665
+ dset->next_state = state;
666
+ io->timer.cancel(io->p, dset->timer);
667
+ io->timer.schedule(io->p, dset->timer, delay, dset, timer_callback);
668
+ }