couchbase 3.4.1 → 3.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (278) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/couchbase/CMakeLists.txt +59 -7
  4. data/ext/couchbase/cmake/Documentation.cmake +0 -1
  5. data/ext/couchbase/cmake/OpenSSL.cmake +98 -3
  6. data/ext/couchbase/cmake/Testing.cmake +12 -4
  7. data/ext/couchbase/cmake/ThirdPartyDependencies.cmake +4 -0
  8. data/ext/couchbase/cmake/build_config.hxx.in +3 -0
  9. data/ext/couchbase/core/bucket.cxx +3 -2
  10. data/ext/couchbase/core/bucket.hxx +9 -0
  11. data/ext/couchbase/core/cluster.hxx +17 -0
  12. data/ext/couchbase/core/cluster_options.cxx +2 -2
  13. data/ext/couchbase/core/cluster_options.hxx +4 -7
  14. data/ext/couchbase/core/{config_profile.cxx → cluster_options_fwd.hxx} +7 -6
  15. data/ext/couchbase/core/config_profile.hxx +2 -65
  16. data/ext/couchbase/core/config_profiles.cxx +79 -0
  17. data/ext/couchbase/core/config_profiles.hxx +56 -0
  18. data/ext/couchbase/core/error_context/search.hxx +1 -1
  19. data/ext/couchbase/core/impl/analytics.cxx +237 -0
  20. data/ext/couchbase/core/impl/boolean_field_query.cxx +40 -0
  21. data/ext/couchbase/core/impl/boolean_query.cxx +62 -0
  22. data/ext/couchbase/core/impl/cluster.cxx +2 -1
  23. data/ext/couchbase/core/impl/conjunction_query.cxx +51 -0
  24. data/ext/couchbase/core/impl/date_range.cxx +89 -0
  25. data/ext/couchbase/core/impl/date_range_facet.cxx +54 -0
  26. data/ext/couchbase/core/impl/date_range_facet_result.cxx +64 -0
  27. data/ext/couchbase/core/impl/date_range_query.cxx +125 -0
  28. data/ext/couchbase/core/impl/disjunction_query.cxx +51 -0
  29. data/ext/couchbase/core/impl/dns_srv_tracker.cxx +5 -3
  30. data/ext/couchbase/core/impl/encoded_search_facet.hxx +29 -0
  31. data/ext/couchbase/core/impl/encoded_search_query.hxx +29 -0
  32. data/ext/couchbase/core/impl/encoded_search_sort.hxx +29 -0
  33. data/ext/couchbase/core/impl/geo_bounding_box_query.cxx +46 -0
  34. data/ext/couchbase/core/impl/geo_distance_query.cxx +43 -0
  35. data/ext/couchbase/core/impl/geo_polygon_query.cxx +46 -0
  36. data/ext/couchbase/core/impl/internal_date_range_facet_result.cxx +80 -0
  37. data/ext/couchbase/core/impl/internal_date_range_facet_result.hxx +48 -0
  38. data/ext/couchbase/core/impl/internal_numeric_range_facet_result.cxx +80 -0
  39. data/ext/couchbase/core/impl/internal_numeric_range_facet_result.hxx +48 -0
  40. data/ext/couchbase/core/impl/internal_search_error_context.cxx +141 -0
  41. data/ext/couchbase/core/impl/internal_search_error_context.hxx +61 -0
  42. data/ext/couchbase/core/impl/internal_search_meta_data.cxx +60 -0
  43. data/ext/couchbase/core/impl/internal_search_meta_data.hxx +41 -0
  44. data/ext/couchbase/core/impl/internal_search_result.cxx +84 -0
  45. data/ext/couchbase/core/impl/internal_search_result.hxx +43 -0
  46. data/ext/couchbase/core/impl/internal_search_row.cxx +82 -0
  47. data/ext/couchbase/core/impl/internal_search_row.hxx +56 -0
  48. data/ext/couchbase/core/impl/internal_search_row_location.hxx +32 -0
  49. data/ext/couchbase/core/impl/internal_search_row_locations.cxx +137 -0
  50. data/ext/couchbase/core/impl/internal_search_row_locations.hxx +45 -0
  51. data/ext/couchbase/core/impl/internal_term_facet_result.cxx +80 -0
  52. data/ext/couchbase/core/impl/internal_term_facet_result.hxx +48 -0
  53. data/ext/couchbase/core/impl/match_all_query.cxx +35 -0
  54. data/ext/couchbase/core/impl/match_none_query.cxx +35 -0
  55. data/ext/couchbase/core/impl/match_phrase_query.cxx +43 -0
  56. data/ext/couchbase/core/impl/match_query.cxx +59 -0
  57. data/ext/couchbase/core/impl/numeric_range.cxx +49 -0
  58. data/ext/couchbase/core/impl/numeric_range_facet.cxx +54 -0
  59. data/ext/couchbase/core/impl/numeric_range_facet_result.cxx +64 -0
  60. data/ext/couchbase/core/impl/numeric_range_query.cxx +56 -0
  61. data/ext/couchbase/core/impl/phrase_query.cxx +42 -0
  62. data/ext/couchbase/core/impl/prefix_query.cxx +40 -0
  63. data/ext/couchbase/core/impl/query.cxx +5 -5
  64. data/ext/couchbase/core/impl/query_string_query.cxx +37 -0
  65. data/ext/couchbase/core/impl/regexp_query.cxx +40 -0
  66. data/ext/couchbase/core/impl/search.cxx +191 -0
  67. data/ext/couchbase/core/impl/search_error_context.cxx +147 -0
  68. data/ext/couchbase/core/impl/search_meta_data.cxx +46 -0
  69. data/ext/couchbase/core/impl/search_result.cxx +66 -0
  70. data/ext/couchbase/core/impl/search_row.cxx +74 -0
  71. data/ext/couchbase/core/impl/search_row_location.cxx +64 -0
  72. data/ext/couchbase/core/impl/search_row_locations.cxx +66 -0
  73. data/ext/couchbase/core/impl/search_sort_field.cxx +104 -0
  74. data/ext/couchbase/core/impl/search_sort_id.cxx +43 -0
  75. data/ext/couchbase/core/impl/search_sort_score.cxx +43 -0
  76. data/ext/couchbase/core/impl/term_facet.cxx +36 -0
  77. data/ext/couchbase/core/impl/term_facet_result.cxx +64 -0
  78. data/ext/couchbase/core/impl/term_query.cxx +56 -0
  79. data/ext/couchbase/core/impl/term_range_query.cxx +57 -0
  80. data/ext/couchbase/core/impl/wildcard_query.cxx +40 -0
  81. data/ext/couchbase/core/io/dns_client.cxx +225 -0
  82. data/ext/couchbase/core/io/dns_client.hxx +19 -188
  83. data/ext/couchbase/core/io/http_context.hxx +1 -1
  84. data/ext/couchbase/core/io/http_session.hxx +10 -0
  85. data/ext/couchbase/core/io/http_session_manager.hxx +5 -3
  86. data/ext/couchbase/core/io/mcbp_session.cxx +28 -1
  87. data/ext/couchbase/core/io/retry_orchestrator.hxx +3 -2
  88. data/ext/couchbase/core/json_string.hxx +5 -0
  89. data/ext/couchbase/core/meta/version.cxx +18 -4
  90. data/ext/couchbase/core/mozilla_ca_bundle.hxx +39 -0
  91. data/ext/couchbase/core/operations/document_analytics.cxx +1 -0
  92. data/ext/couchbase/core/operations/document_analytics.hxx +1 -0
  93. data/ext/couchbase/core/operations/document_append.hxx +1 -1
  94. data/ext/couchbase/core/operations/document_decrement.hxx +1 -1
  95. data/ext/couchbase/core/operations/document_exists.hxx +1 -1
  96. data/ext/couchbase/core/operations/document_get.hxx +1 -1
  97. data/ext/couchbase/core/operations/document_get_and_lock.hxx +1 -1
  98. data/ext/couchbase/core/operations/document_get_and_touch.hxx +1 -1
  99. data/ext/couchbase/core/operations/document_get_projected.hxx +1 -1
  100. data/ext/couchbase/core/operations/document_increment.hxx +1 -1
  101. data/ext/couchbase/core/operations/document_insert.hxx +1 -1
  102. data/ext/couchbase/core/operations/document_lookup_in.hxx +1 -1
  103. data/ext/couchbase/core/operations/document_mutate_in.hxx +1 -1
  104. data/ext/couchbase/core/operations/document_prepend.hxx +1 -1
  105. data/ext/couchbase/core/operations/document_query.cxx +2 -0
  106. data/ext/couchbase/core/operations/document_query.hxx +6 -0
  107. data/ext/couchbase/core/operations/document_remove.hxx +1 -1
  108. data/ext/couchbase/core/operations/document_replace.hxx +1 -1
  109. data/ext/couchbase/core/operations/document_search.cxx +4 -1
  110. data/ext/couchbase/core/operations/document_search.hxx +2 -1
  111. data/ext/couchbase/core/operations/document_touch.hxx +1 -1
  112. data/ext/couchbase/core/operations/document_unlock.hxx +1 -1
  113. data/ext/couchbase/core/operations/document_upsert.hxx +1 -1
  114. data/ext/couchbase/core/operations/document_view.hxx +1 -0
  115. data/ext/couchbase/core/protocol/client_request.hxx +11 -2
  116. data/ext/couchbase/core/public_fwd.hxx +21 -0
  117. data/ext/couchbase/core/tls_verify_mode.hxx +26 -0
  118. data/ext/couchbase/core/topology/configuration.cxx +15 -2
  119. data/ext/couchbase/core/topology/configuration.hxx +5 -1
  120. data/ext/couchbase/core/transactions/active_transaction_record.hxx +2 -2
  121. data/ext/couchbase/core/transactions/attempt_context_impl.cxx +3 -0
  122. data/ext/couchbase/core/transactions/attempt_context_impl.hxx +1 -1
  123. data/ext/couchbase/core/transactions/attempt_context_testing_hooks.cxx +93 -0
  124. data/ext/couchbase/core/transactions/attempt_context_testing_hooks.hxx +48 -75
  125. data/ext/couchbase/core/transactions/cleanup_testing_hooks.cxx +52 -0
  126. data/ext/couchbase/core/transactions/cleanup_testing_hooks.hxx +17 -31
  127. data/ext/couchbase/core/transactions/exceptions.hxx +12 -9
  128. data/ext/couchbase/core/transactions/internal/transaction_context.hxx +12 -12
  129. data/ext/couchbase/core/transactions/internal/transactions_cleanup.hxx +7 -1
  130. data/ext/couchbase/core/transactions/transaction_context.cxx +1 -0
  131. data/ext/couchbase/core/transactions/transactions_cleanup.cxx +144 -155
  132. data/ext/couchbase/core/utils/connection_string.cxx +27 -3
  133. data/ext/couchbase/core/utils/connection_string.hxx +3 -3
  134. data/ext/couchbase/core/utils/json.cxx +4 -1
  135. data/ext/couchbase/couchbase/analytics_error_context.hxx +143 -0
  136. data/ext/couchbase/couchbase/analytics_meta_data.hxx +155 -0
  137. data/ext/couchbase/couchbase/analytics_metrics.hxx +163 -0
  138. data/ext/couchbase/couchbase/analytics_options.hxx +359 -0
  139. data/ext/couchbase/couchbase/analytics_result.hxx +102 -0
  140. data/ext/couchbase/couchbase/analytics_scan_consistency.hxx +46 -0
  141. data/ext/couchbase/couchbase/analytics_status.hxx +41 -0
  142. data/ext/couchbase/couchbase/analytics_warning.hxx +85 -0
  143. data/ext/couchbase/couchbase/behavior_options.hxx +10 -1
  144. data/ext/couchbase/couchbase/boolean_field_query.hxx +77 -0
  145. data/ext/couchbase/couchbase/boolean_query.hxx +223 -0
  146. data/ext/couchbase/couchbase/cluster.hxx +75 -1
  147. data/ext/couchbase/couchbase/conjunction_query.hxx +88 -0
  148. data/ext/couchbase/couchbase/date_range.hxx +69 -0
  149. data/ext/couchbase/couchbase/date_range_facet.hxx +56 -0
  150. data/ext/couchbase/couchbase/date_range_facet_result.hxx +55 -0
  151. data/ext/couchbase/couchbase/date_range_query.hxx +265 -0
  152. data/ext/couchbase/couchbase/disjunction_query.hxx +109 -0
  153. data/ext/couchbase/couchbase/doc_id_query.hxx +111 -0
  154. data/ext/couchbase/couchbase/error_context.hxx +7 -6
  155. data/ext/couchbase/couchbase/fmt/analytics_scan_consistency.hxx +52 -0
  156. data/ext/couchbase/couchbase/fmt/analytics_status.hxx +76 -0
  157. data/ext/couchbase/couchbase/fmt/search_scan_consistency.hxx +49 -0
  158. data/ext/couchbase/couchbase/geo_bounding_box_query.hxx +107 -0
  159. data/ext/couchbase/couchbase/geo_distance_query.hxx +109 -0
  160. data/ext/couchbase/couchbase/geo_point.hxx +32 -0
  161. data/ext/couchbase/couchbase/geo_polygon_query.hxx +85 -0
  162. data/ext/couchbase/couchbase/highlight_style.hxx +45 -0
  163. data/ext/couchbase/couchbase/match_all_query.hxx +43 -0
  164. data/ext/couchbase/couchbase/match_none_query.hxx +43 -0
  165. data/ext/couchbase/couchbase/match_operator.hxx +45 -0
  166. data/ext/couchbase/couchbase/match_phrase_query.hxx +108 -0
  167. data/ext/couchbase/couchbase/match_query.hxx +163 -0
  168. data/ext/couchbase/couchbase/numeric_range.hxx +58 -0
  169. data/ext/couchbase/couchbase/numeric_range_facet.hxx +56 -0
  170. data/ext/couchbase/couchbase/numeric_range_facet_result.hxx +55 -0
  171. data/ext/couchbase/couchbase/numeric_range_query.hxx +143 -0
  172. data/ext/couchbase/couchbase/phrase_query.hxx +93 -0
  173. data/ext/couchbase/couchbase/prefix_query.hxx +82 -0
  174. data/ext/couchbase/couchbase/query_options.hxx +0 -1
  175. data/ext/couchbase/couchbase/query_string_query.hxx +72 -0
  176. data/ext/couchbase/couchbase/regexp_query.hxx +82 -0
  177. data/ext/couchbase/couchbase/scope.hxx +73 -0
  178. data/ext/couchbase/couchbase/search_date_range.hxx +68 -0
  179. data/ext/couchbase/couchbase/search_error_context.hxx +138 -0
  180. data/ext/couchbase/couchbase/search_facet.hxx +60 -0
  181. data/ext/couchbase/couchbase/search_facet_result.hxx +50 -0
  182. data/ext/couchbase/couchbase/search_meta_data.hxx +85 -0
  183. data/ext/couchbase/couchbase/search_metrics.hxx +127 -0
  184. data/ext/couchbase/couchbase/search_numeric_range.hxx +69 -0
  185. data/ext/couchbase/couchbase/search_options.hxx +509 -0
  186. data/ext/couchbase/couchbase/search_query.hxx +69 -0
  187. data/ext/couchbase/couchbase/search_result.hxx +77 -0
  188. data/ext/couchbase/couchbase/search_row.hxx +104 -0
  189. data/ext/couchbase/couchbase/search_row_location.hxx +55 -0
  190. data/ext/couchbase/couchbase/search_row_locations.hxx +86 -0
  191. data/ext/couchbase/couchbase/search_scan_consistency.hxx +34 -0
  192. data/ext/couchbase/couchbase/search_sort.hxx +58 -0
  193. data/ext/couchbase/couchbase/search_sort_field.hxx +117 -0
  194. data/ext/couchbase/couchbase/search_sort_field_missing.hxx +26 -0
  195. data/ext/couchbase/couchbase/search_sort_field_mode.hxx +27 -0
  196. data/ext/couchbase/couchbase/search_sort_field_type.hxx +28 -0
  197. data/ext/couchbase/couchbase/search_sort_id.hxx +60 -0
  198. data/ext/couchbase/couchbase/search_sort_score.hxx +60 -0
  199. data/ext/couchbase/couchbase/search_term_range.hxx +51 -0
  200. data/ext/couchbase/couchbase/security_options.hxx +3 -0
  201. data/ext/couchbase/couchbase/term_facet.hxx +48 -0
  202. data/ext/couchbase/couchbase/term_facet_result.hxx +55 -0
  203. data/ext/couchbase/couchbase/term_query.hxx +151 -0
  204. data/ext/couchbase/couchbase/term_range_query.hxx +142 -0
  205. data/ext/couchbase/couchbase/tracing/request_span.hxx +63 -0
  206. data/ext/couchbase/couchbase/tracing/request_tracer.hxx +2 -40
  207. data/ext/couchbase/couchbase/transactions/async_attempt_context.hxx +83 -4
  208. data/ext/couchbase/couchbase/transactions/attempt_context.hxx +68 -1
  209. data/ext/couchbase/couchbase/transactions/transaction_get_result.hxx +2 -0
  210. data/ext/couchbase/couchbase/transactions/transaction_keyspace.hxx +11 -1
  211. data/ext/couchbase/couchbase/transactions/transaction_options.hxx +79 -8
  212. data/ext/couchbase/couchbase/transactions/transaction_query_options.hxx +128 -15
  213. data/ext/couchbase/couchbase/transactions/transaction_query_result.hxx +4 -0
  214. data/ext/couchbase/couchbase/transactions/transaction_result.hxx +1 -1
  215. data/ext/couchbase/couchbase/transactions/transactions_cleanup_config.hxx +5 -3
  216. data/ext/couchbase/couchbase/transactions/transactions_config.hxx +9 -5
  217. data/ext/couchbase/couchbase/transactions/transactions_query_config.hxx +6 -3
  218. data/ext/couchbase/couchbase/transactions.hxx +34 -1
  219. data/ext/couchbase/couchbase/wildcard_query.hxx +83 -0
  220. data/ext/couchbase/test/CMakeLists.txt +8 -7
  221. data/ext/couchbase/test/benchmark_helper_integration.hxx +2 -2
  222. data/ext/couchbase/test/test_helper.hxx +6 -6
  223. data/ext/couchbase/test/test_integration_analytics.cxx +314 -16
  224. data/ext/couchbase/test/test_integration_collections.cxx +7 -3
  225. data/ext/couchbase/test/test_integration_connect.cxx +7 -3
  226. data/ext/couchbase/test/test_integration_crud.cxx +19 -2
  227. data/ext/couchbase/test/test_integration_diagnostics.cxx +11 -5
  228. data/ext/couchbase/test/test_integration_durability.cxx +12 -7
  229. data/ext/couchbase/test/test_integration_examples.cxx +324 -11
  230. data/ext/couchbase/test/test_integration_management.cxx +162 -94
  231. data/ext/couchbase/test/test_integration_query.cxx +68 -10
  232. data/ext/couchbase/test/test_integration_range_scan.cxx +12 -12
  233. data/ext/couchbase/test/test_integration_read_replica.cxx +48 -11
  234. data/ext/couchbase/test/test_integration_search.cxx +621 -0
  235. data/ext/couchbase/test/test_integration_subdoc.cxx +62 -11
  236. data/ext/couchbase/test/test_integration_tracer.cxx +5 -0
  237. data/ext/couchbase/test/test_integration_transcoders.cxx +13 -5
  238. data/ext/couchbase/test/{test_transaction_transaction_context.cxx → test_transaction_context.cxx} +1 -1
  239. data/ext/couchbase/test/test_transaction_examples.cxx +195 -0
  240. data/ext/couchbase/test/{test_transaction_transaction_simple.cxx → test_transaction_simple.cxx} +90 -5
  241. data/ext/couchbase/test/{test_transaction_transaction_simple_async.cxx → test_transaction_simple_async.cxx} +19 -21
  242. data/ext/couchbase/test/test_unit_config_profiles.cxx +13 -13
  243. data/ext/couchbase/test/test_unit_connection_string.cxx +35 -0
  244. data/ext/couchbase/test/test_unit_json_transcoder.cxx +4 -0
  245. data/ext/couchbase/test/test_unit_search.cxx +427 -0
  246. data/ext/couchbase/test/test_unit_transaction_utils.cxx +10 -1
  247. data/ext/couchbase/test/test_unit_utils.cxx +8 -4
  248. data/ext/couchbase/third_party/snappy/CMakeLists.txt +150 -27
  249. data/ext/couchbase/third_party/snappy/cmake/config.h.in +28 -24
  250. data/ext/couchbase/third_party/snappy/snappy-internal.h +189 -25
  251. data/ext/couchbase/third_party/snappy/snappy-sinksource.cc +26 -9
  252. data/ext/couchbase/third_party/snappy/snappy-sinksource.h +11 -11
  253. data/ext/couchbase/third_party/snappy/snappy-stubs-internal.cc +1 -1
  254. data/ext/couchbase/third_party/snappy/snappy-stubs-internal.h +227 -308
  255. data/ext/couchbase/third_party/snappy/snappy-stubs-public.h.in +0 -11
  256. data/ext/couchbase/third_party/snappy/snappy.cc +1176 -410
  257. data/ext/couchbase/third_party/snappy/snappy.h +19 -4
  258. data/ext/couchbase.cxx +85 -22
  259. data/ext/revisions.rb +3 -3
  260. data/lib/couchbase/authenticator.rb +0 -1
  261. data/lib/couchbase/cluster.rb +13 -13
  262. data/lib/couchbase/cluster_registry.rb +7 -2
  263. data/lib/couchbase/config_profiles.rb +1 -1
  264. data/lib/couchbase/configuration.rb +3 -4
  265. data/lib/couchbase/json_transcoder.rb +12 -5
  266. data/lib/couchbase/management/collection_query_index_manager.rb +54 -15
  267. data/lib/couchbase/management/query_index_manager.rb +70 -5
  268. data/lib/couchbase/options.rb +85 -2
  269. data/lib/couchbase/raw_binary_transcoder.rb +37 -0
  270. data/lib/couchbase/raw_json_transcoder.rb +38 -0
  271. data/lib/couchbase/raw_string_transcoder.rb +40 -0
  272. data/lib/couchbase/search_options.rb +163 -240
  273. data/lib/couchbase/transcoder_flags.rb +62 -0
  274. data/lib/couchbase/version.rb +1 -1
  275. metadata +151 -12
  276. data/ext/couchbase/core/CMakeLists.txt +0 -0
  277. /data/ext/couchbase/test/{test_transaction_transaction_public_async_api.cxx → test_transaction_public_async_api.cxx} +0 -0
  278. /data/ext/couchbase/test/{test_transaction_transaction_public_blocking_api.cxx → test_transaction_public_blocking_api.cxx} +0 -0
@@ -28,33 +28,6 @@ class attempt_context;
28
28
  using error_func1 = std::function<std::optional<error_class>(attempt_context*)>;
29
29
  using error_func2 = std::function<std::optional<error_class>(attempt_context*, const std::string&)>;
30
30
 
31
- namespace
32
- {
33
- std::optional<error_class>
34
- noop_1(attempt_context*)
35
- {
36
- return {};
37
- }
38
-
39
- std::optional<error_class>
40
- noop_2(attempt_context*, const std::string&)
41
- {
42
- return {};
43
- }
44
-
45
- std::optional<const std::string>
46
- noop_3(attempt_context*)
47
- {
48
- return {};
49
- }
50
-
51
- bool
52
- noop_4(attempt_context*, const std::string&, std::optional<const std::string>)
53
- {
54
- return false;
55
- }
56
- } // namespace
57
-
58
31
  static const std::string STAGE_ROLLBACK = "rollback";
59
32
  static const std::string STAGE_GET = "get";
60
33
  static const std::string STAGE_INSERT = "insert";
@@ -91,55 +64,55 @@ static const std::string STAGE_QUERY_KV_INSERT = "queryKvInsert";
91
64
  * about your use-case: we are always open to adding good ideas into the transactions library.
92
65
  */
93
66
  struct attempt_context_testing_hooks {
94
- error_func1 before_atr_commit = noop_1;
95
- error_func1 before_atr_commit_ambiguity_resolution = noop_1;
96
- error_func1 after_atr_commit = noop_1;
97
- error_func2 before_doc_committed = noop_2;
98
- error_func2 before_removing_doc_during_staged_insert = noop_2;
99
- error_func2 before_rollback_delete_inserted = noop_2;
100
- error_func2 after_doc_committed_before_saving_cas = noop_2;
101
- error_func2 after_doc_committed = noop_2;
102
- error_func2 before_staged_insert = noop_2;
103
- error_func2 before_staged_remove = noop_2;
104
- error_func2 before_staged_replace = noop_2;
105
- error_func2 before_doc_removed = noop_2;
106
- error_func2 before_doc_rolled_back = noop_2;
107
- error_func2 after_doc_removed_pre_retry = noop_2;
108
- error_func2 after_doc_removed_post_retry = noop_2;
109
- error_func2 after_get_complete = noop_2;
110
- error_func2 after_staged_replace_complete_before_cas_saved = noop_2;
111
- error_func2 after_staged_replace_complete = noop_2;
112
- error_func2 after_staged_remove_complete = noop_2;
113
- error_func2 after_staged_insert_complete = noop_2;
114
- error_func2 after_rollback_replace_or_remove = noop_2;
115
- error_func2 after_rollback_delete_inserted = noop_2;
116
- error_func2 before_check_atr_entry_for_blocking_doc = noop_2;
117
- error_func2 before_doc_get = noop_2;
118
- error_func2 before_get_doc_in_exists_during_staged_insert = noop_2;
119
- error_func2 before_query = noop_2;
120
- error_func2 after_query = noop_2;
121
- error_func2 before_remove_staged_insert = noop_2;
122
- error_func2 after_remove_staged_insert = noop_2;
123
-
124
- error_func1 after_docs_committed = noop_1;
125
- error_func1 after_docs_removed = noop_1;
126
- error_func1 after_atr_pending = noop_1;
127
- error_func1 before_atr_pending = noop_1;
128
- error_func1 before_atr_complete = noop_1;
129
- error_func1 before_atr_rolled_back = noop_1;
130
- error_func1 after_atr_complete = noop_1;
131
- error_func1 before_get_atr_for_abort = noop_1;
132
- error_func1 before_atr_aborted = noop_1;
133
- error_func1 after_atr_aborted = noop_1;
134
- error_func1 after_atr_rolled_back = noop_1;
135
-
136
- std::function<std::optional<const std::string>(attempt_context*)> random_atr_id_for_vbucket = noop_3;
137
-
138
- std::function<bool(attempt_context*, const std::string&, std::optional<const std::string>)> has_expired_client_side = noop_4;
67
+ error_func1 before_atr_commit;
68
+ error_func1 before_atr_commit_ambiguity_resolution;
69
+ error_func1 after_atr_commit;
70
+ error_func2 before_doc_committed;
71
+ error_func2 before_removing_doc_during_staged_insert;
72
+ error_func2 before_rollback_delete_inserted;
73
+ error_func2 after_doc_committed_before_saving_cas;
74
+ error_func2 after_doc_committed;
75
+ error_func2 before_staged_insert;
76
+ error_func2 before_staged_remove;
77
+ error_func2 before_staged_replace;
78
+ error_func2 before_doc_removed;
79
+ error_func2 before_doc_rolled_back;
80
+ error_func2 after_doc_removed_pre_retry;
81
+ error_func2 after_doc_removed_post_retry;
82
+ error_func2 after_get_complete;
83
+ error_func2 after_staged_replace_complete_before_cas_saved;
84
+ error_func2 after_staged_replace_complete;
85
+ error_func2 after_staged_remove_complete;
86
+ error_func2 after_staged_insert_complete;
87
+ error_func2 after_rollback_replace_or_remove;
88
+ error_func2 after_rollback_delete_inserted;
89
+ error_func2 before_check_atr_entry_for_blocking_doc;
90
+ error_func2 before_doc_get;
91
+ error_func2 before_get_doc_in_exists_during_staged_insert;
92
+ error_func2 before_query;
93
+ error_func2 after_query;
94
+ error_func2 before_remove_staged_insert;
95
+ error_func2 after_remove_staged_insert;
96
+
97
+ error_func1 after_docs_committed;
98
+ error_func1 after_docs_removed;
99
+ error_func1 after_atr_pending;
100
+ error_func1 before_atr_pending;
101
+ error_func1 before_atr_complete;
102
+ error_func1 before_atr_rolled_back;
103
+ error_func1 after_atr_complete;
104
+ error_func1 before_get_atr_for_abort;
105
+ error_func1 before_atr_aborted;
106
+ error_func1 after_atr_aborted;
107
+ error_func1 after_atr_rolled_back;
108
+
109
+ std::function<std::optional<const std::string>(attempt_context*)> random_atr_id_for_vbucket;
110
+
111
+ std::function<bool(attempt_context*, const std::string&, std::optional<const std::string>)> has_expired_client_side;
112
+
113
+ attempt_context_testing_hooks();
139
114
 
140
115
  // needed for unique_ptr<attempt_context_testing_hooks> in transaction_config, with a forward declaration.
141
- ~attempt_context_testing_hooks()
142
- {
143
- }
116
+ ~attempt_context_testing_hooks() = default;
144
117
  };
145
118
  } // namespace couchbase::core::transactions
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright 2021-Present 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
+ #include "cleanup_testing_hooks.hxx"
18
+
19
+ namespace couchbase::core::transactions
20
+ {
21
+ namespace
22
+ {
23
+ inline std::optional<couchbase::core::transactions::error_class>
24
+ noop1(const std::string&)
25
+ {
26
+ return {};
27
+ }
28
+
29
+ inline std::optional<couchbase::core::transactions::error_class>
30
+ noop2()
31
+ {
32
+ return {};
33
+ }
34
+ } // namespace
35
+
36
+ cleanup_testing_hooks::cleanup_testing_hooks()
37
+ : before_commit_doc{ noop1 }
38
+ , before_doc_get{ noop1 }
39
+ , before_remove_doc_staged_for_removal{ noop1 }
40
+ , before_remove_doc{ noop1 }
41
+ , before_atr_get{ noop1 }
42
+ , before_remove_links{ noop1 }
43
+ , before_atr_remove{ noop2 }
44
+ , on_cleanup_docs_completed{ noop2 }
45
+ , on_cleanup_completed{ noop2 }
46
+ , client_record_before_create{ noop1 }
47
+ , client_record_before_get{ noop1 }
48
+ , client_record_before_update{ noop1 }
49
+ , client_record_before_remove_client{ noop1 }
50
+ {
51
+ }
52
+ } // namespace couchbase::core::transactions
@@ -18,52 +18,38 @@
18
18
  #include "core/transactions/error_class.hxx"
19
19
 
20
20
  #include <functional>
21
+ #include <optional>
21
22
  #include <string>
22
23
 
23
24
  namespace couchbase::core::transactions
24
25
  {
25
26
  using error_func3 = std::function<std::optional<error_class>(const std::string&)>;
26
27
  using error_func4 = std::function<std::optional<error_class>(void)>;
27
- namespace
28
- {
29
- std::optional<couchbase::core::transactions::error_class>
30
- noop1(const std::string&)
31
- {
32
- return {};
33
- }
34
- std::optional<couchbase::core::transactions::error_class>
35
- noop2()
36
- {
37
- return {};
38
- }
39
-
40
- } // namespace
41
28
 
42
29
  /**
43
30
  * Hooks purely for testing purposes. If you're an end-user looking at these for any reason, then please contact us first
44
31
  * about your use-case: we are always open to adding good ideas into the transactions library.
45
32
  */
46
33
  struct cleanup_testing_hooks {
47
- error_func3 before_commit_doc = noop1;
48
- error_func3 before_doc_get = noop1;
49
- error_func3 before_remove_doc_staged_for_removal = noop1;
50
- error_func3 before_remove_doc = noop1;
51
- error_func3 before_atr_get = noop1;
52
- error_func3 before_remove_links = noop1;
34
+ error_func3 before_commit_doc;
35
+ error_func3 before_doc_get;
36
+ error_func3 before_remove_doc_staged_for_removal;
37
+ error_func3 before_remove_doc;
38
+ error_func3 before_atr_get;
39
+ error_func3 before_remove_links;
53
40
 
54
- error_func4 before_atr_remove = noop2;
41
+ error_func4 before_atr_remove;
55
42
 
56
- error_func4 on_cleanup_docs_completed = noop2;
57
- error_func4 on_cleanup_completed = noop2;
43
+ error_func4 on_cleanup_docs_completed;
44
+ error_func4 on_cleanup_completed;
58
45
 
59
- error_func3 client_record_before_create = noop1;
60
- error_func3 client_record_before_get = noop1;
61
- error_func3 client_record_before_update = noop1;
62
- error_func3 client_record_before_remove_client = noop1;
46
+ error_func3 client_record_before_create;
47
+ error_func3 client_record_before_get;
48
+ error_func3 client_record_before_update;
49
+ error_func3 client_record_before_remove_client;
63
50
 
51
+ cleanup_testing_hooks();
64
52
  // needed for unique_ptr<cleanup_testing_hooks> in transaction_config, with a forward declaration.
65
- ~cleanup_testing_hooks()
66
- {
67
- }
53
+ ~cleanup_testing_hooks() = default;
68
54
  };
69
- } // namespace couchbase::core::transactions
55
+ } // namespace couchbase::core::transactions
@@ -16,11 +16,14 @@
16
16
 
17
17
  #pragma once
18
18
 
19
- #include <core/error_context/query.hxx>
19
+ #include "core/error_context/query.hxx"
20
+ #include "error_class.hxx"
21
+
20
22
  #include <couchbase/error_codes.hxx>
21
23
  #include <couchbase/transactions/transaction_result.hxx>
22
- #include <optional>
24
+
23
25
  #include <stdexcept>
26
+ #include <utility>
24
27
 
25
28
  namespace couchbase::core::transactions
26
29
  {
@@ -135,7 +138,7 @@ class op_exception : public std::runtime_error
135
138
  transaction_op_error_context ctx_;
136
139
 
137
140
  public:
138
- op_exception(transaction_op_error_context ctx, external_exception cause = COUCHBASE_EXCEPTION)
141
+ explicit op_exception(transaction_op_error_context ctx, external_exception cause = COUCHBASE_EXCEPTION)
139
142
  : std::runtime_error(ctx.ec().message())
140
143
  , cause_(cause)
141
144
  , ctx_(std::move(ctx))
@@ -157,7 +160,7 @@ class document_not_found : public op_exception
157
160
  {
158
161
  public:
159
162
  explicit document_not_found(transaction_op_error_context ctx)
160
- : op_exception(ctx, DOCUMENT_NOT_FOUND_EXCEPTION)
163
+ : op_exception(std::move(ctx), DOCUMENT_NOT_FOUND_EXCEPTION)
161
164
  {
162
165
  }
163
166
  };
@@ -166,7 +169,7 @@ class document_exists : public op_exception
166
169
  {
167
170
  public:
168
171
  explicit document_exists(transaction_op_error_context ctx)
169
- : op_exception(ctx, DOCUMENT_EXISTS_EXCEPTION)
172
+ : op_exception(std::move(ctx), DOCUMENT_EXISTS_EXCEPTION)
170
173
  {
171
174
  }
172
175
  };
@@ -175,7 +178,7 @@ class query_attempt_not_found : public op_exception
175
178
  {
176
179
  public:
177
180
  query_attempt_not_found(transaction_op_error_context ctx)
178
- : op_exception(ctx)
181
+ : op_exception(std::move(ctx))
179
182
  {
180
183
  }
181
184
  };
@@ -184,7 +187,7 @@ class query_cas_mismatch : public op_exception
184
187
  {
185
188
  public:
186
189
  query_cas_mismatch(transaction_op_error_context ctx)
187
- : op_exception(ctx)
190
+ : op_exception(std::move(ctx))
188
191
  {
189
192
  }
190
193
  };
@@ -193,7 +196,7 @@ class query_attempt_expired : public op_exception
193
196
  {
194
197
  public:
195
198
  query_attempt_expired(transaction_op_error_context ctx)
196
- : op_exception(ctx)
199
+ : op_exception(std::move(ctx))
197
200
  {
198
201
  }
199
202
  };
@@ -202,7 +205,7 @@ class query_parsing_failure : public op_exception
202
205
  {
203
206
  public:
204
207
  query_parsing_failure(transaction_op_error_context ctx)
205
- : op_exception(ctx, PARSING_FAILURE)
208
+ : op_exception(std::move(ctx), PARSING_FAILURE)
206
209
  {
207
210
  }
208
211
  };
@@ -49,30 +49,29 @@ class transaction_context
49
49
 
50
50
  [[nodiscard]] std::size_t num_attempts() const
51
51
  {
52
+ std::lock_guard<std::mutex> lock(mutex_);
52
53
  return attempts_.size();
53
54
  }
54
- [[nodiscard]] const std::vector<transaction_attempt>& attempts() const
55
- {
56
- return attempts_;
57
- }
58
- [[nodiscard]] std::vector<transaction_attempt>& attempts()
59
- {
60
- return const_cast<std::vector<transaction_attempt>&>(const_cast<const transaction_context*>(this)->attempts());
61
- }
62
55
  [[nodiscard]] const transaction_attempt& current_attempt() const
63
56
  {
57
+ std::lock_guard<std::mutex> lock(mutex_);
64
58
  if (attempts_.empty()) {
65
59
  throw std::runtime_error("transaction context has no attempts yet");
66
60
  }
67
61
  return attempts_.back();
68
62
  }
69
- [[nodiscard]] transaction_attempt& current_attempt()
70
- {
71
- return const_cast<transaction_attempt&>(const_cast<const transaction_context*>(this)->current_attempt());
72
- }
73
63
 
74
64
  void add_attempt();
75
65
 
66
+ void current_attempt_state(attempt_state s)
67
+ {
68
+ std::lock_guard<std::mutex> lock(mutex_);
69
+ if (attempts_.empty()) {
70
+ throw std::runtime_error("transaction_context has no attempts yet");
71
+ }
72
+ attempts_.back().state = s;
73
+ }
74
+
76
75
  [[nodiscard]] std::shared_ptr<core::cluster> cluster_ref()
77
76
  {
78
77
  return transactions_.cluster_ref();
@@ -191,6 +190,7 @@ class transaction_context
191
190
  std::string atr_collection_;
192
191
  transactions_cleanup& cleanup_;
193
192
  std::shared_ptr<attempt_context_impl> current_attempt_context_;
193
+ mutable std::mutex mutex_;
194
194
 
195
195
  std::unique_ptr<exp_delay> delay_;
196
196
  };
@@ -145,6 +145,12 @@ class transactions_cleanup
145
145
 
146
146
  void attempts_loop();
147
147
 
148
+ bool is_running()
149
+ {
150
+ std::unique_lock<std::mutex> lock(mutex_);
151
+ return running_;
152
+ }
153
+
148
154
  template<class R, class P>
149
155
  bool interruptable_wait(std::chrono::duration<R, P> time);
150
156
 
@@ -153,7 +159,7 @@ class transactions_cleanup
153
159
  void create_client_record(const couchbase::transactions::transaction_keyspace& keyspace);
154
160
  const atr_cleanup_stats handle_atr_cleanup(const core::document_id& atr_id,
155
161
  std::vector<transactions_cleanup_attempt>* result = nullptr);
156
- std::atomic<bool> running_{ false };
162
+ bool running_{ false };
157
163
  };
158
164
  } // namespace transactions
159
165
  } // namespace couchbase::core
@@ -45,6 +45,7 @@ void
45
45
  transaction_context::add_attempt()
46
46
  {
47
47
  transaction_attempt attempt{};
48
+ std::lock_guard<std::mutex> lock(mutex_);
48
49
  attempts_.push_back(attempt);
49
50
  }
50
51