couchbase 4.2.1 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. package/CMakeLists.txt +1 -0
  2. package/deps/couchbase-cxx-client/.gitmodules +3 -0
  3. package/deps/couchbase-cxx-client/.idea/misc.xml +1 -0
  4. package/deps/couchbase-cxx-client/.idea/vcs.xml +1 -0
  5. package/deps/couchbase-cxx-client/CMakeLists.txt +11 -1
  6. package/deps/couchbase-cxx-client/README.md +3 -3
  7. package/deps/couchbase-cxx-client/cmake/CompilerWarnings.cmake +4 -1
  8. package/deps/couchbase-cxx-client/cmake/VersionInfo.cmake +13 -1
  9. package/deps/couchbase-cxx-client/cmake/build_version.hxx.in +1 -0
  10. package/deps/couchbase-cxx-client/core/cluster.hxx +15 -5
  11. package/deps/couchbase-cxx-client/core/impl/build_deferred_query_indexes.cxx +17 -6
  12. package/deps/couchbase-cxx-client/core/impl/cluster.cxx +1 -1
  13. package/deps/couchbase-cxx-client/core/impl/collection_query_index_manager.cxx +93 -0
  14. package/deps/couchbase-cxx-client/core/impl/configuration_profiles_registry.cxx +11 -0
  15. package/deps/couchbase-cxx-client/core/impl/create_query_index.cxx +119 -0
  16. package/deps/couchbase-cxx-client/core/impl/drop_query_index.cxx +108 -0
  17. package/deps/couchbase-cxx-client/core/impl/get.cxx +1 -1
  18. package/deps/couchbase-cxx-client/core/impl/get_all_query_indexes.cxx +76 -0
  19. package/deps/couchbase-cxx-client/core/impl/query.cxx +5 -7
  20. package/deps/couchbase-cxx-client/core/impl/watch_query_indexes.cxx +168 -0
  21. package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +15 -1
  22. package/deps/couchbase-cxx-client/core/logger/configuration.hxx +3 -0
  23. package/deps/couchbase-cxx-client/core/logger/level.hxx +21 -0
  24. package/deps/couchbase-cxx-client/core/logger/logger.hxx +4 -6
  25. package/deps/couchbase-cxx-client/core/meta/CMakeLists.txt +4 -2
  26. package/deps/couchbase-cxx-client/core/meta/features.hxx +31 -0
  27. package/deps/couchbase-cxx-client/core/meta/version.cxx +67 -5
  28. package/deps/couchbase-cxx-client/core/meta/version.hxx +12 -1
  29. package/deps/couchbase-cxx-client/core/metrics/CMakeLists.txt +4 -1
  30. package/deps/couchbase-cxx-client/core/metrics/logging_meter.cxx +46 -5
  31. package/deps/couchbase-cxx-client/core/metrics/logging_meter.hxx +10 -26
  32. package/deps/couchbase-cxx-client/core/operations/document_get_projected.cxx +3 -2
  33. package/deps/couchbase-cxx-client/core/operations/document_query.cxx +10 -12
  34. package/deps/couchbase-cxx-client/core/operations/document_query.hxx +1 -3
  35. package/deps/couchbase-cxx-client/core/operations/management/query_index_build.cxx +8 -14
  36. package/deps/couchbase-cxx-client/core/operations/management/query_index_build.hxx +2 -1
  37. package/deps/couchbase-cxx-client/core/operations/management/query_index_build_deferred.hxx +15 -8
  38. package/deps/couchbase-cxx-client/core/operations/management/query_index_create.cxx +7 -14
  39. package/deps/couchbase-cxx-client/core/operations/management/query_index_create.hxx +2 -0
  40. package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.cxx +11 -16
  41. package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.hxx +2 -0
  42. package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all.cxx +8 -12
  43. package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all.hxx +4 -3
  44. package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all_deferred.cxx +21 -12
  45. package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all_deferred.hxx +3 -2
  46. package/deps/couchbase-cxx-client/core/origin.hxx +1 -1
  47. package/deps/couchbase-cxx-client/core/platform/uuid.cc +1 -2
  48. package/deps/couchbase-cxx-client/core/protocol/cmd_hello.hxx +5 -1
  49. package/deps/couchbase-cxx-client/core/query_context.hxx +79 -0
  50. package/deps/couchbase-cxx-client/core/tracing/CMakeLists.txt +3 -1
  51. package/deps/couchbase-cxx-client/core/tracing/threshold_logging_tracer.cxx +19 -4
  52. package/deps/couchbase-cxx-client/core/tracing/threshold_logging_tracer.hxx +2 -2
  53. package/deps/couchbase-cxx-client/core/transactions/async_attempt_context.hxx +10 -4
  54. package/deps/couchbase-cxx-client/core/transactions/atr_cleanup_entry.cxx +52 -63
  55. package/deps/couchbase-cxx-client/core/transactions/attempt_context.hxx +8 -3
  56. package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.cxx +163 -126
  57. package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.hxx +24 -37
  58. package/deps/couchbase-cxx-client/core/transactions/forward_compat.hxx +4 -4
  59. package/deps/couchbase-cxx-client/core/transactions/internal/atr_cleanup_entry.hxx +51 -13
  60. package/deps/couchbase-cxx-client/core/transactions/internal/client_record.hxx +26 -1
  61. package/deps/couchbase-cxx-client/core/transactions/internal/doc_record.hxx +21 -0
  62. package/deps/couchbase-cxx-client/core/transactions/internal/logging.hxx +40 -18
  63. package/deps/couchbase-cxx-client/core/transactions/internal/transaction_context.hxx +5 -0
  64. package/deps/couchbase-cxx-client/core/transactions/result.hxx +26 -0
  65. package/deps/couchbase-cxx-client/core/transactions/staged_mutation.cxx +48 -47
  66. package/deps/couchbase-cxx-client/core/transactions/staged_mutation.hxx +6 -6
  67. package/deps/couchbase-cxx-client/core/transactions/transaction_context.cxx +33 -19
  68. package/deps/couchbase-cxx-client/core/transactions/transaction_get_result.hxx +18 -2
  69. package/deps/couchbase-cxx-client/core/transactions/transaction_links.hxx +25 -2
  70. package/deps/couchbase-cxx-client/core/transactions/transactions.cxx +4 -4
  71. package/deps/couchbase-cxx-client/core/transactions/transactions_cleanup.cxx +49 -56
  72. package/deps/couchbase-cxx-client/core/transactions/waitable_op_list.hxx +7 -7
  73. package/deps/couchbase-cxx-client/core/transactions.hxx +0 -12
  74. package/deps/couchbase-cxx-client/core/utils/binary.hxx +1 -1
  75. package/deps/couchbase-cxx-client/core/utils/keyspace.hxx +55 -0
  76. package/deps/couchbase-cxx-client/couchbase/build_query_index_options.hxx +12 -45
  77. package/deps/couchbase-cxx-client/couchbase/cluster.hxx +1 -1
  78. package/deps/couchbase-cxx-client/couchbase/cluster_options.hxx +6 -7
  79. package/deps/couchbase-cxx-client/couchbase/collection.hxx +8 -0
  80. package/deps/couchbase-cxx-client/couchbase/collection_query_index_manager.hxx +218 -0
  81. package/deps/couchbase-cxx-client/couchbase/configuration_profiles_registry.hxx +3 -0
  82. package/deps/couchbase-cxx-client/couchbase/create_primary_query_index_options.hxx +166 -0
  83. package/deps/couchbase-cxx-client/couchbase/create_query_index_options.hxx +172 -0
  84. package/deps/couchbase-cxx-client/couchbase/drop_primary_query_index_options.hxx +129 -0
  85. package/deps/couchbase-cxx-client/couchbase/drop_query_index_options.hxx +116 -0
  86. package/deps/couchbase-cxx-client/couchbase/fmt/cas.hxx +1 -1
  87. package/deps/couchbase-cxx-client/couchbase/fmt/query_scan_consistency.hxx +46 -0
  88. package/deps/couchbase-cxx-client/couchbase/fmt/query_status.hxx +70 -0
  89. package/deps/couchbase-cxx-client/couchbase/fmt/tls_verify_mode.hxx +46 -0
  90. package/deps/couchbase-cxx-client/couchbase/get_all_query_indexes_options.hxx +100 -0
  91. package/deps/couchbase-cxx-client/{core → couchbase}/management/query_index.hxx +2 -2
  92. package/deps/couchbase-cxx-client/couchbase/metrics/meter.hxx +16 -0
  93. package/deps/couchbase-cxx-client/couchbase/query_index_manager.hxx +178 -6
  94. package/deps/couchbase-cxx-client/couchbase/query_options.hxx +1 -18
  95. package/deps/couchbase-cxx-client/couchbase/scope.hxx +5 -2
  96. package/deps/couchbase-cxx-client/couchbase/tracing/request_tracer.hxx +16 -0
  97. package/deps/couchbase-cxx-client/couchbase/transactions/async_attempt_context.hxx +11 -4
  98. package/deps/couchbase-cxx-client/couchbase/transactions/attempt_context.hxx +5 -3
  99. package/deps/couchbase-cxx-client/couchbase/transactions/transaction_keyspace.hxx +16 -0
  100. package/deps/couchbase-cxx-client/couchbase/transactions/transaction_query_options.hxx +0 -6
  101. package/deps/couchbase-cxx-client/couchbase/watch_query_indexes_options.hxx +115 -0
  102. package/deps/couchbase-cxx-client/examples/minimal.cxx +3 -1
  103. package/deps/couchbase-cxx-client/test/test_integration_crud.cxx +72 -0
  104. package/deps/couchbase-cxx-client/test/test_integration_management.cxx +727 -310
  105. package/deps/couchbase-cxx-client/test/test_integration_query.cxx +4 -8
  106. package/deps/couchbase-cxx-client/test/test_integration_transcoders.cxx +14 -0
  107. package/deps/couchbase-cxx-client/test/test_transaction_transaction_public_blocking_api.cxx +34 -19
  108. package/deps/couchbase-cxx-client/test/test_unit_transaction_logging.cxx +66 -22
  109. package/deps/couchbase-cxx-client/test/test_unit_utils.cxx +51 -0
  110. package/deps/couchbase-cxx-client/test/tools/tool_kv_loader.cxx +2 -2
  111. package/deps/couchbase-cxx-client/test/utils/integration_test_guard.cxx +2 -0
  112. package/deps/couchbase-cxx-client/test/utils/wait_until.cxx +4 -4
  113. package/deps/couchbase-cxx-client/third_party/docopt/.travis.yml +103 -0
  114. package/deps/couchbase-cxx-client/third_party/docopt/CMakeLists.txt +129 -0
  115. package/deps/couchbase-cxx-client/third_party/docopt/LICENSE-Boost-1.0 +23 -0
  116. package/deps/couchbase-cxx-client/third_party/docopt/LICENSE-MIT +23 -0
  117. package/deps/couchbase-cxx-client/third_party/docopt/README.rst +479 -0
  118. package/deps/couchbase-cxx-client/third_party/docopt/docopt-config.cmake +1 -0
  119. package/deps/couchbase-cxx-client/third_party/docopt/docopt.cpp +687 -0
  120. package/deps/couchbase-cxx-client/third_party/docopt/docopt.h +98 -0
  121. package/deps/couchbase-cxx-client/third_party/docopt/docopt.pc.in +9 -0
  122. package/deps/couchbase-cxx-client/third_party/docopt/docopt_private.h +676 -0
  123. package/deps/couchbase-cxx-client/third_party/docopt/docopt_util.h +122 -0
  124. package/deps/couchbase-cxx-client/third_party/docopt/docopt_value.h +341 -0
  125. package/deps/couchbase-cxx-client/third_party/docopt/examples/naval_fate.cpp +36 -0
  126. package/deps/couchbase-cxx-client/third_party/docopt/main.cpp +16 -0
  127. package/deps/couchbase-cxx-client/third_party/docopt/run_testcase.cpp +40 -0
  128. package/deps/couchbase-cxx-client/third_party/docopt/run_tests.py +72 -0
  129. package/deps/couchbase-cxx-client/third_party/docopt/testcases.docopt +957 -0
  130. package/deps/couchbase-cxx-client/tools/CMakeLists.txt +14 -0
  131. package/deps/couchbase-cxx-client/tools/cbc.cxx +65 -0
  132. package/deps/couchbase-cxx-client/tools/command.hxx +31 -0
  133. package/deps/couchbase-cxx-client/tools/command_registry.cxx +43 -0
  134. package/deps/couchbase-cxx-client/tools/command_registry.hxx +39 -0
  135. package/deps/couchbase-cxx-client/tools/get.cxx +267 -0
  136. package/deps/couchbase-cxx-client/tools/get.hxx +26 -0
  137. package/deps/couchbase-cxx-client/tools/query.cxx +441 -0
  138. package/deps/couchbase-cxx-client/tools/query.hxx +26 -0
  139. package/deps/couchbase-cxx-client/tools/utils.cxx +418 -0
  140. package/deps/couchbase-cxx-client/tools/utils.hxx +150 -0
  141. package/deps/couchbase-cxx-client/tools/version.cxx +82 -0
  142. package/deps/couchbase-cxx-client/tools/version.hxx +26 -0
  143. package/dist/authenticators.d.ts +2 -2
  144. package/dist/authenticators.js +1 -2
  145. package/dist/binding.d.ts +32 -16
  146. package/dist/cluster.js +14 -7
  147. package/dist/collection.d.ts +6 -0
  148. package/dist/collection.js +8 -0
  149. package/dist/queryexecutor.js +1 -1
  150. package/dist/queryindexmanager.d.ts +100 -4
  151. package/dist/queryindexmanager.js +344 -118
  152. package/dist/transactions.js +0 -2
  153. package/package.json +1 -1
  154. package/src/connection.cpp +2 -0
  155. package/src/connection.hpp +1 -0
  156. package/src/connection_autogen.cpp +16 -0
  157. package/src/jstocbpp_autogen.hpp +93 -23
  158. package/src/jstocbpp_basic.hpp +24 -0
  159. package/src/jstocbpp_transactions.hpp +0 -8
  160. package/tools/gen-bindings-js.js +1 -0
  161. package/tools/gen-bindings-json.py +4 -2
  162. package/deps/couchbase-cxx-client/core/transactions/logging.cxx +0 -107
@@ -17,6 +17,8 @@
17
17
 
18
18
  #include "threshold_logging_tracer.hxx"
19
19
 
20
+ #include "couchbase/build_info.hxx"
21
+
20
22
  #include "constants.hxx"
21
23
  #include "core/logger/logger.hxx"
22
24
  #include "core/meta/version.hxx"
@@ -25,10 +27,11 @@
25
27
  #include "core/utils/json.hxx"
26
28
 
27
29
  #include <asio/steady_timer.hpp>
30
+ #include <tao/json/value.hpp>
31
+
28
32
  #include <chrono>
29
33
  #include <mutex>
30
34
  #include <queue>
31
- #include <tao/json/value.hpp>
32
35
 
33
36
  namespace couchbase::core::tracing
34
37
  {
@@ -285,6 +288,12 @@ class threshold_logging_tracer_impl
285
288
  rearm_threshold_reporter();
286
289
  }
287
290
 
291
+ void stop()
292
+ {
293
+ emit_orphan_report_.cancel();
294
+ emit_threshold_report_.cancel();
295
+ }
296
+
288
297
  void add_orphan(std::shared_ptr<threshold_logging_span> span)
289
298
  {
290
299
  orphan_queue_.emplace(convert(std::move(span)));
@@ -338,7 +347,7 @@ class threshold_logging_tracer_impl
338
347
  tao::json::value report
339
348
  {
340
349
  { "count", queue.size() },
341
- #if BACKEND_DEBUG_BUILD
350
+ #if COUCHBASE_CXX_CLIENT_DEBUG_BUILD
342
351
  { "emit_interval_ms", options_.orphaned_emit_interval.count() }, { "sample_size", options_.orphaned_sample_size },
343
352
  #endif
344
353
  };
@@ -361,7 +370,7 @@ class threshold_logging_tracer_impl
361
370
  tao::json::value report
362
371
  {
363
372
  { "count", queue.size() }, { "service", fmt::format("{}", service) },
364
- #if BACKEND_DEBUG_BUILD
373
+ #if COUCHBASE_CXX_CLIENT_DEBUG_BUILD
365
374
  { "emit_interval_ms", options_.threshold_emit_interval.count() }, { "sample_size", options_.threshold_sample_size },
366
375
  { "threshold_ms",
367
376
  std::chrono::duration_cast<std::chrono::microseconds>(options_.threshold_for_service(service)).count() },
@@ -403,8 +412,8 @@ threshold_logging_tracer::report(std::shared_ptr<threshold_logging_span> span)
403
412
 
404
413
  threshold_logging_tracer::threshold_logging_tracer(asio::io_context& ctx, threshold_logging_options options)
405
414
  : options_{ options }
415
+ , impl_(std::make_shared<threshold_logging_tracer_impl>(options_, ctx))
406
416
  {
407
- impl_ = std::make_shared<threshold_logging_tracer_impl>(options_, ctx);
408
417
  }
409
418
 
410
419
  void
@@ -413,6 +422,12 @@ threshold_logging_tracer::start()
413
422
  impl_->start();
414
423
  }
415
424
 
425
+ void
426
+ threshold_logging_tracer::stop()
427
+ {
428
+ impl_->stop();
429
+ }
430
+
416
431
  void
417
432
  threshold_logging_span::end()
418
433
  {
@@ -38,11 +38,11 @@ class threshold_logging_tracer
38
38
  public:
39
39
  threshold_logging_tracer(asio::io_context& ctx, threshold_logging_options options);
40
40
 
41
- void start();
42
-
43
41
  std::shared_ptr<couchbase::tracing::request_span> start_span(std::string name,
44
42
  std::shared_ptr<couchbase::tracing::request_span> parent) override;
45
43
  void report(std::shared_ptr<threshold_logging_span> span);
44
+ void start() override;
45
+ void stop() override;
46
46
 
47
47
  private:
48
48
  threshold_logging_options options_;
@@ -113,6 +113,11 @@ class async_attempt_context
113
113
  */
114
114
  virtual void remove(const transaction_get_result& document, VoidCallback&& cb) = 0;
115
115
 
116
+ virtual void query(const std::string& statement,
117
+ const couchbase::transactions::transaction_query_options& options,
118
+ std::optional<std::string> query_context,
119
+ QueryCallback&& cb) = 0;
120
+
116
121
  /**
117
122
  * Performs a Query, within the current transaction.
118
123
  *
@@ -120,9 +125,10 @@ class async_attempt_context
120
125
  * @param options options to apply to the query.
121
126
  * @param cb callback which is called when the query completes.
122
127
  */
123
- virtual void query(const std::string& statement,
124
- const couchbase::transactions::transaction_query_options& options,
125
- QueryCallback&& cb) = 0;
128
+ void query(const std::string& statement, const couchbase::transactions::transaction_query_options& options, QueryCallback&& cb)
129
+ {
130
+ return query(statement, options, {}, std::move(cb));
131
+ }
126
132
 
127
133
  /**
128
134
  * Performs a Query, within the current transaction.
@@ -133,7 +139,7 @@ class async_attempt_context
133
139
  void query(const std::string& statement, QueryCallback&& cb)
134
140
  {
135
141
  couchbase::transactions::transaction_query_options opts;
136
- return query(statement, opts, std::move(cb));
142
+ return query(statement, opts, {}, std::move(cb));
137
143
  }
138
144
 
139
145
  /**
@@ -16,13 +16,11 @@
16
16
 
17
17
  #include "active_transaction_record.hxx"
18
18
  #include "attempt_context_impl.hxx"
19
- #include "attempt_context_testing_hooks.hxx"
20
19
  #include "cleanup_testing_hooks.hxx"
21
20
  #include "durability_level.hxx"
22
21
  #include "forward_compat.hxx"
23
22
 
24
23
  #include "core/transactions.hxx"
25
- #include "exceptions.hxx"
26
24
  #include "internal/atr_cleanup_entry.hxx"
27
25
  #include "internal/logging.hxx"
28
26
  #include "internal/transactions_cleanup.hxx"
@@ -83,9 +81,9 @@ atr_cleanup_entry::atr_cleanup_entry(attempt_context& ctx)
83
81
  }
84
82
 
85
83
  void
86
- atr_cleanup_entry::clean(std::shared_ptr<spdlog::logger> logger, transactions_cleanup_attempt* result)
84
+ atr_cleanup_entry::clean(transactions_cleanup_attempt* result)
87
85
  {
88
- logger->trace("cleaning {}", *this);
86
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("cleaning {}", *this);
89
87
  // get atr entry if needed
90
88
  atr_entry entry;
91
89
  if (nullptr == atr_entry_) {
@@ -96,21 +94,21 @@ atr_cleanup_entry::clean(std::shared_ptr<spdlog::logger> logger, transactions_cl
96
94
  std::find_if(atr->entries().begin(), atr->entries().end(), [&](const atr_entry& e) { return e.attempt_id() == attempt_id_; });
97
95
  if (it != atr->entries().end()) {
98
96
  atr_entry_ = &(*it);
99
- return check_atr_and_cleanup(logger, result);
97
+ return check_atr_and_cleanup(result);
100
98
  } else {
101
- logger->trace("could not find attempt {}, nothing to clean", attempt_id_);
99
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("could not find attempt {}, nothing to clean", attempt_id_);
102
100
  return;
103
101
  }
104
102
  } else {
105
- logger->trace("could not find atr {}, nothing to clean", atr_id_);
103
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("could not find atr {}, nothing to clean", atr_id_);
106
104
  return;
107
105
  }
108
106
  }
109
- check_atr_and_cleanup(logger, result);
107
+ check_atr_and_cleanup(result);
110
108
  }
111
109
 
112
110
  void
113
- atr_cleanup_entry::check_atr_and_cleanup(std::shared_ptr<spdlog::logger> logger, transactions_cleanup_attempt* result)
111
+ atr_cleanup_entry::check_atr_and_cleanup(transactions_cleanup_attempt* result)
114
112
  {
115
113
  // ExtStoreDurability: this is the first point where we're guaranteed to have the ATR entry
116
114
  auto durability_level_raw = atr_entry_->durability_level();
@@ -118,12 +116,8 @@ atr_cleanup_entry::check_atr_and_cleanup(std::shared_ptr<spdlog::logger> logger,
118
116
  if (durability_level_raw.has_value()) {
119
117
  durability_level = store_string_to_durability_level(durability_level_raw.value());
120
118
  }
121
- // Too verbose to log, but leaving here commented as it may be useful later for internal debugging
122
- // logger->trace("found attempt {}/{} check_if_expired_={} has_expired={} safety_margin_ms_={}", atr_entry_->atr_id(),
123
- // atr_entry_->attempt_id(),
124
- // check_if_expired_, atr_entry_->has_expired(safety_margin_ms_),safety_margin_ms_);
125
119
  if (check_if_expired_ && !atr_entry_->has_expired(safety_margin_ms_)) {
126
- logger->trace("{} not expired, nothing to clean", *this);
120
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("not expired, nothing to clean");
127
121
  return;
128
122
  }
129
123
  if (result) {
@@ -133,12 +127,12 @@ atr_cleanup_entry::check_atr_and_cleanup(std::shared_ptr<spdlog::logger> logger,
133
127
  if (err) {
134
128
  throw *err;
135
129
  }
136
- cleanup_docs(logger, durability_level);
130
+ cleanup_docs(durability_level);
137
131
  auto ec = cleanup_->config().cleanup_hooks->on_cleanup_docs_completed();
138
132
  if (ec) {
139
133
  throw client_error(*ec, "on_cleanup_docs_completed hook threw error");
140
134
  }
141
- cleanup_entry(logger, durability_level);
135
+ cleanup_entry(durability_level);
142
136
  ec = cleanup_->config().cleanup_hooks->on_cleanup_completed();
143
137
  if (ec) {
144
138
  throw client_error(*ec, "on_cleanup_completed hook threw error");
@@ -147,31 +141,30 @@ atr_cleanup_entry::check_atr_and_cleanup(std::shared_ptr<spdlog::logger> logger,
147
141
  }
148
142
 
149
143
  void
150
- atr_cleanup_entry::cleanup_docs(std::shared_ptr<spdlog::logger> logger, durability_level dl)
144
+ atr_cleanup_entry::cleanup_docs(durability_level dl)
151
145
  {
152
146
  switch (atr_entry_->state()) {
153
147
  case attempt_state::COMMITTED:
154
- commit_docs(logger, atr_entry_->inserted_ids(), dl);
155
- commit_docs(logger, atr_entry_->replaced_ids(), dl);
156
- remove_docs_staged_for_removal(logger, atr_entry_->removed_ids(), dl);
148
+ commit_docs(atr_entry_->inserted_ids(), dl);
149
+ commit_docs(atr_entry_->replaced_ids(), dl);
150
+ remove_docs_staged_for_removal(atr_entry_->removed_ids(), dl);
157
151
  break;
158
152
  // half-finished commit
159
153
  case attempt_state::ABORTED:
160
154
  // half finished rollback
161
- remove_docs(logger, atr_entry_->inserted_ids(), dl);
162
- remove_txn_links(logger, atr_entry_->replaced_ids(), dl);
163
- remove_txn_links(logger, atr_entry_->removed_ids(), dl);
155
+ remove_docs(atr_entry_->inserted_ids(), dl);
156
+ remove_txn_links(atr_entry_->replaced_ids(), dl);
157
+ remove_txn_links(atr_entry_->removed_ids(), dl);
164
158
  break;
165
159
  default:
166
- logger->trace("attempt in {}, nothing to do in cleanup_docs", attempt_state_name(atr_entry_->state()));
160
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("attempt in {}, nothing to do in cleanup_docs", attempt_state_name(atr_entry_->state()));
167
161
  }
168
162
  }
169
163
 
170
164
  void
171
- atr_cleanup_entry::do_per_doc(std::shared_ptr<spdlog::logger> logger,
172
- std::vector<doc_record> docs,
165
+ atr_cleanup_entry::do_per_doc(std::vector<doc_record> docs,
173
166
  bool require_crc_to_match,
174
- const std::function<void(std::shared_ptr<spdlog::logger>, transaction_get_result&, bool)>& call)
167
+ const std::function<void(transaction_get_result&, bool)>& call)
175
168
  {
176
169
  for (const auto& dr : docs) {
177
170
  try {
@@ -203,40 +196,40 @@ atr_cleanup_entry::do_per_doc(std::shared_ptr<spdlog::logger> logger,
203
196
  auto res = wrap_operation_future(f);
204
197
 
205
198
  if (res.values.empty()) {
206
- logger->trace("cannot create a transaction document from {}, ignoring", res);
199
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("cannot create a transaction document from {}, ignoring", res);
207
200
  continue;
208
201
  }
209
202
  auto doc = transaction_get_result::create_from(dr.document_id(), res);
210
203
  // now let's decide if we call the function or not
211
204
  if (!(doc.links().has_staged_content() || doc.links().is_document_being_removed()) || !doc.links().has_staged_write()) {
212
- logger->trace("document {} has no staged content - assuming it was "
213
- "committed and skipping",
214
- dr.id());
205
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("document {} has no staged content - assuming it was "
206
+ "committed and skipping",
207
+ dr.id());
215
208
  continue;
216
209
  } else if (doc.links().staged_attempt_id() != attempt_id_) {
217
- logger->trace(
210
+ CB_ATTEMPT_CLEANUP_LOG_TRACE(
218
211
  "document {} staged for different attempt {}, skipping", dr.id(), doc.links().staged_attempt_id().value_or("<none>)"));
219
212
  continue;
220
213
  }
221
214
  if (require_crc_to_match) {
222
215
  if (!doc.metadata()->crc32() || !doc.links().crc32_of_staging() ||
223
216
  doc.links().crc32_of_staging() != doc.metadata()->crc32()) {
224
- logger->trace("document {} crc32 {} doesn't match staged value {}, skipping",
225
- dr.id(),
226
- doc.metadata()->crc32().value_or("<none>"),
227
- doc.links().crc32_of_staging().value_or("<none>"));
217
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("document {} crc32 {} doesn't match staged value {}, skipping",
218
+ dr.id(),
219
+ doc.metadata()->crc32().value_or("<none>"),
220
+ doc.links().crc32_of_staging().value_or("<none>"));
228
221
  continue;
229
222
  }
230
223
  }
231
- call(logger, doc, res.is_deleted);
224
+ call(doc, res.is_deleted);
232
225
  } catch (const client_error& e) {
233
226
  error_class ec = e.ec();
234
227
  switch (ec) {
235
228
  case FAIL_DOC_NOT_FOUND:
236
- logger->error("document {} not found - ignoring ", dr);
229
+ CB_ATTEMPT_CLEANUP_LOG_ERROR("document {} not found - ignoring ", dr);
237
230
  break;
238
231
  default:
239
- logger->error("got error \"{}\", not ignoring this", e.what());
232
+ CB_ATTEMPT_CLEANUP_LOG_ERROR("got error \"{}\", not ignoring this", e.what());
240
233
  throw;
241
234
  }
242
235
  }
@@ -244,10 +237,10 @@ atr_cleanup_entry::do_per_doc(std::shared_ptr<spdlog::logger> logger,
244
237
  }
245
238
 
246
239
  void
247
- atr_cleanup_entry::commit_docs(std::shared_ptr<spdlog::logger> logger, std::optional<std::vector<doc_record>> docs, durability_level dl)
240
+ atr_cleanup_entry::commit_docs(std::optional<std::vector<doc_record>> docs, durability_level dl)
248
241
  {
249
242
  if (docs) {
250
- do_per_doc(logger, *docs, true, [&](std::shared_ptr<spdlog::logger> log, transaction_get_result& doc, bool) {
243
+ do_per_doc(*docs, true, [&](transaction_get_result& doc, bool) {
251
244
  if (doc.links().has_staged_content()) {
252
245
  auto content = doc.links().staged_content();
253
246
  auto ec = cleanup_->config().cleanup_hooks->before_commit_doc(doc.id().key());
@@ -281,18 +274,18 @@ atr_cleanup_entry::commit_docs(std::shared_ptr<spdlog::logger> logger, std::opti
281
274
  });
282
275
  wrap_operation_future(f);
283
276
  }
284
- log->trace("commit_docs replaced content of doc {} with {}", doc.id(), to_string(content));
277
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("commit_docs replaced content of doc {} with {}", doc.id(), to_string(content));
285
278
  } else {
286
- log->trace("commit_docs skipping document {}, no staged content", doc.id());
279
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("commit_docs skipping document {}, no staged content", doc.id());
287
280
  }
288
281
  });
289
282
  }
290
283
  }
291
284
  void
292
- atr_cleanup_entry::remove_docs(std::shared_ptr<spdlog::logger> logger, std::optional<std::vector<doc_record>> docs, durability_level dl)
285
+ atr_cleanup_entry::remove_docs(std::optional<std::vector<doc_record>> docs, durability_level dl)
293
286
  {
294
287
  if (docs) {
295
- do_per_doc(logger, *docs, true, [&](std::shared_ptr<spdlog::logger> log, transaction_get_result& doc, bool is_deleted) {
288
+ do_per_doc(*docs, true, [&](transaction_get_result& doc, bool is_deleted) {
296
289
  auto ec = cleanup_->config().cleanup_hooks->before_remove_doc(doc.id().key());
297
290
  if (ec) {
298
291
  throw client_error(*ec, "before_remove_doc hook threw error");
@@ -324,18 +317,16 @@ atr_cleanup_entry::remove_docs(std::shared_ptr<spdlog::logger> logger, std::opti
324
317
  });
325
318
  wrap_operation_future(f);
326
319
  }
327
- log->trace("remove_docs removed doc {}", doc.id());
320
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("remove_docs removed doc {}", doc.id());
328
321
  });
329
322
  }
330
323
  }
331
324
 
332
325
  void
333
- atr_cleanup_entry::remove_docs_staged_for_removal(std::shared_ptr<spdlog::logger> logger,
334
- std::optional<std::vector<doc_record>> docs,
335
- durability_level dl)
326
+ atr_cleanup_entry::remove_docs_staged_for_removal(std::optional<std::vector<doc_record>> docs, durability_level dl)
336
327
  {
337
328
  if (docs) {
338
- do_per_doc(logger, *docs, true, [&](std::shared_ptr<spdlog::logger> log, transaction_get_result& doc, bool) {
329
+ do_per_doc(*docs, true, [&](transaction_get_result& doc, bool) {
339
330
  if (doc.links().is_document_being_removed()) {
340
331
  auto ec = cleanup_->config().cleanup_hooks->before_remove_doc_staged_for_removal(doc.id().key());
341
332
  if (ec) {
@@ -350,23 +341,21 @@ atr_cleanup_entry::remove_docs_staged_for_removal(std::shared_ptr<spdlog::logger
350
341
  barrier->set_value(result::create_from_mutation_response(resp));
351
342
  });
352
343
  wrap_operation_future(f);
353
- log->trace("remove_docs_staged_for_removal removed doc {}", doc.id());
344
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("remove_docs_staged_for_removal removed doc {}", doc.id());
354
345
  } else {
355
- log->trace("remove_docs_staged_for_removal found document {} not "
356
- "marked for removal, skipping",
357
- doc.id());
346
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("remove_docs_staged_for_removal found document {} not "
347
+ "marked for removal, skipping",
348
+ doc.id());
358
349
  }
359
350
  });
360
351
  }
361
352
  }
362
353
 
363
354
  void
364
- atr_cleanup_entry::remove_txn_links(std::shared_ptr<spdlog::logger> logger,
365
- std::optional<std::vector<doc_record>> docs,
366
- durability_level dl)
355
+ atr_cleanup_entry::remove_txn_links(std::optional<std::vector<doc_record>> docs, durability_level dl)
367
356
  {
368
357
  if (docs) {
369
- do_per_doc(logger, *docs, false, [&](std::shared_ptr<spdlog::logger> log, transaction_get_result& doc, bool) {
358
+ do_per_doc(*docs, false, [&](transaction_get_result& doc, bool) {
370
359
  auto ec = cleanup_->config().cleanup_hooks->before_remove_links(doc.id().key());
371
360
  if (ec) {
372
361
  throw client_error(*ec, "before_remove_links hook threw error");
@@ -385,13 +374,13 @@ atr_cleanup_entry::remove_txn_links(std::shared_ptr<spdlog::logger> logger,
385
374
  cleanup_->cluster_ref()->execute(
386
375
  req, [barrier](core::operations::mutate_in_response resp) { barrier->set_value(result::create_from_subdoc_response(resp)); });
387
376
  wrap_operation_future(f);
388
- log->trace("remove_txn_links removed links for doc {}", doc.id());
377
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("remove_txn_links removed links for doc {}", doc.id());
389
378
  });
390
379
  }
391
380
  }
392
381
 
393
382
  void
394
- atr_cleanup_entry::cleanup_entry(std::shared_ptr<spdlog::logger> logger, durability_level dl)
383
+ atr_cleanup_entry::cleanup_entry(durability_level dl)
395
384
  {
396
385
  try {
397
386
  auto ec = cleanup_->config().cleanup_hooks->before_atr_remove();
@@ -412,15 +401,15 @@ atr_cleanup_entry::cleanup_entry(std::shared_ptr<spdlog::logger> logger, durabil
412
401
  cleanup_->cluster_ref()->execute(
413
402
  req, [barrier](core::operations::mutate_in_response resp) { barrier->set_value(result::create_from_subdoc_response(resp)); });
414
403
  wrap_operation_future(f);
415
- logger->trace("successfully removed attempt {}", attempt_id_);
404
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("successfully removed attempt {}", attempt_id_);
416
405
  } catch (const client_error& e) {
417
406
  error_class ec = e.ec();
418
407
  switch (ec) {
419
408
  case FAIL_PATH_NOT_FOUND:
420
- logger->trace("found attempt {} has also inserted 'p' field indicating collision with main algo");
409
+ CB_ATTEMPT_CLEANUP_LOG_TRACE("found attempt {} has also inserted 'p' field indicating collision with main algo");
421
410
  return;
422
411
  default:
423
- logger->error("cleanup couldn't remove attempt {} due to {} {}", attempt_id_, ec, e.what());
412
+ CB_ATTEMPT_CLEANUP_LOG_ERROR("cleanup couldn't remove attempt {} due to {} {}", attempt_id_, ec, e.what());
424
413
  throw;
425
414
  }
426
415
  }
@@ -129,16 +129,20 @@ class attempt_context
129
129
  * rethrown if it is caught.
130
130
  */
131
131
  virtual void remove(const transaction_get_result& document) = 0;
132
+
132
133
  /**
133
134
  * Performs a Query, within the current transaction.
134
135
  *
135
136
  * @param statement query statement to execute.
136
137
  * @param options options to apply to the query.
138
+ * @param query_context query context, if any.
137
139
  * @returns result of the query.
138
140
  */
139
- core::operations::query_response query(const std::string& statement, const couchbase::transactions::transaction_query_options& opts)
141
+ core::operations::query_response query(const std::string& statement,
142
+ const couchbase::transactions::transaction_query_options& opts,
143
+ std::optional<std::string> query_context = {})
140
144
  {
141
- return do_core_query(statement, opts);
145
+ return do_core_query(statement, opts, query_context);
142
146
  };
143
147
  /**
144
148
  * Performs a Query, within the current transaction.
@@ -184,7 +188,8 @@ class attempt_context
184
188
  virtual transaction_get_result replace_raw(const transaction_get_result& document, const std::vector<std::byte>& content) = 0;
185
189
 
186
190
  virtual core::operations::query_response do_core_query(const std::string&,
187
- const couchbase::transactions::transaction_query_options& opts) = 0;
191
+ const couchbase::transactions::transaction_query_options& opts,
192
+ std::optional<std::string> query_context) = 0;
188
193
  };
189
194
 
190
195
  } // namespace couchbase::core::transactions