couchbase 4.4.2 → 4.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CMakeLists.txt +2 -0
  2. package/deps/couchbase-cxx-client/CMakeLists.txt +17 -14
  3. package/deps/couchbase-cxx-client/README.md +2 -2
  4. package/deps/couchbase-cxx-client/cmake/Packaging.cmake +4 -0
  5. package/deps/couchbase-cxx-client/cmake/Testing.cmake +1 -1
  6. package/deps/couchbase-cxx-client/cmake/VersionInfo.cmake +24 -2
  7. package/deps/couchbase-cxx-client/cmake/couchbase-cxx-client.spec.in +43 -4
  8. package/deps/couchbase-cxx-client/core/agent_group.cxx +8 -0
  9. package/deps/couchbase-cxx-client/core/agent_group.hxx +4 -0
  10. package/deps/couchbase-cxx-client/core/bucket.cxx +16 -20
  11. package/deps/couchbase-cxx-client/core/bucket.hxx +12 -12
  12. package/deps/couchbase-cxx-client/core/cluster.cxx +44 -52
  13. package/deps/couchbase-cxx-client/core/cluster_agent.cxx +8 -0
  14. package/deps/couchbase-cxx-client/core/cluster_agent.hxx +4 -0
  15. package/deps/couchbase-cxx-client/core/collections_component.cxx +2 -2
  16. package/deps/couchbase-cxx-client/core/columnar/agent.cxx +2 -2
  17. package/deps/couchbase-cxx-client/core/columnar/agent.hxx +1 -1
  18. package/deps/couchbase-cxx-client/core/columnar/management_component.cxx +3 -3
  19. package/deps/couchbase-cxx-client/core/columnar/query_component.cxx +103 -45
  20. package/deps/couchbase-cxx-client/core/columnar/query_component.hxx +1 -0
  21. package/deps/couchbase-cxx-client/core/free_form_http_request.hxx +8 -0
  22. package/deps/couchbase-cxx-client/core/http_component.cxx +55 -24
  23. package/deps/couchbase-cxx-client/core/http_component.hxx +4 -0
  24. package/deps/couchbase-cxx-client/core/impl/analytics_index_manager.cxx +15 -15
  25. package/deps/couchbase-cxx-client/core/impl/bootstrap_error.hxx +10 -2
  26. package/deps/couchbase-cxx-client/core/impl/bucket.cxx +1 -1
  27. package/deps/couchbase-cxx-client/core/impl/bucket_manager.cxx +6 -6
  28. package/deps/couchbase-cxx-client/core/impl/cluster.cxx +36 -40
  29. package/deps/couchbase-cxx-client/core/impl/collection.cxx +2 -2
  30. package/deps/couchbase-cxx-client/core/impl/collection_manager.cxx +5 -5
  31. package/deps/couchbase-cxx-client/core/impl/observe_poll.cxx +13 -5
  32. package/deps/couchbase-cxx-client/core/impl/observe_poll.hxx +1 -3
  33. package/deps/couchbase-cxx-client/core/impl/query_index_manager.cxx +6 -6
  34. package/deps/couchbase-cxx-client/core/impl/scan_result.cxx +1 -1
  35. package/deps/couchbase-cxx-client/core/impl/search_index_manager.cxx +12 -12
  36. package/deps/couchbase-cxx-client/core/io/http_command.hxx +31 -20
  37. package/deps/couchbase-cxx-client/core/io/http_session.cxx +5 -0
  38. package/deps/couchbase-cxx-client/core/io/http_session.hxx +17 -4
  39. package/deps/couchbase-cxx-client/core/io/http_session_manager.hxx +97 -49
  40. package/deps/couchbase-cxx-client/core/io/mcbp_command.hxx +15 -14
  41. package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +48 -33
  42. package/deps/couchbase-cxx-client/core/io/streams.cxx +256 -0
  43. package/deps/couchbase-cxx-client/core/io/streams.hxx +31 -155
  44. package/deps/couchbase-cxx-client/core/logger/configuration.hxx +5 -0
  45. package/deps/couchbase-cxx-client/core/logger/custom_rotating_file_sink.cxx +2 -3
  46. package/deps/couchbase-cxx-client/core/logger/logger.cxx +39 -7
  47. package/deps/couchbase-cxx-client/core/logger/logger.hxx +7 -0
  48. package/deps/couchbase-cxx-client/core/metrics/meter_wrapper.cxx +188 -0
  49. package/deps/couchbase-cxx-client/core/metrics/meter_wrapper.hxx +73 -0
  50. package/deps/couchbase-cxx-client/core/operations/management/bucket_describe.cxx +2 -1
  51. package/deps/couchbase-cxx-client/core/operations/management/bucket_drop.cxx +3 -1
  52. package/deps/couchbase-cxx-client/core/operations/management/bucket_flush.cxx +3 -1
  53. package/deps/couchbase-cxx-client/core/operations/management/bucket_get.cxx +3 -1
  54. package/deps/couchbase-cxx-client/core/operations/management/bucket_update.cxx +3 -1
  55. package/deps/couchbase-cxx-client/core/operations/management/collection_create.cxx +3 -2
  56. package/deps/couchbase-cxx-client/core/operations/management/collection_drop.cxx +5 -2
  57. package/deps/couchbase-cxx-client/core/operations/management/collection_update.cxx +4 -2
  58. package/deps/couchbase-cxx-client/core/operations/management/group_upsert.cxx +3 -3
  59. package/deps/couchbase-cxx-client/core/operations/management/scope_create.cxx +2 -1
  60. package/deps/couchbase-cxx-client/core/operations/management/scope_drop.cxx +4 -1
  61. package/deps/couchbase-cxx-client/core/operations/management/scope_get_all.cxx +3 -1
  62. package/deps/couchbase-cxx-client/core/operations/management/search_index_analyze_document.cxx +3 -2
  63. package/deps/couchbase-cxx-client/core/operations/management/search_index_control_ingest.cxx +3 -2
  64. package/deps/couchbase-cxx-client/core/operations/management/search_index_control_plan_freeze.cxx +3 -2
  65. package/deps/couchbase-cxx-client/core/operations/management/search_index_control_query.cxx +3 -2
  66. package/deps/couchbase-cxx-client/core/operations/management/search_index_drop.cxx +5 -2
  67. package/deps/couchbase-cxx-client/core/operations/management/search_index_get.cxx +5 -2
  68. package/deps/couchbase-cxx-client/core/operations/management/search_index_get_all.cxx +4 -2
  69. package/deps/couchbase-cxx-client/core/operations/management/search_index_get_documents_count.cxx +3 -2
  70. package/deps/couchbase-cxx-client/core/operations/management/search_index_upsert.cxx +5 -2
  71. package/deps/couchbase-cxx-client/core/operations/management/view_index_drop.cxx +2 -1
  72. package/deps/couchbase-cxx-client/core/operations/management/view_index_get.cxx +2 -1
  73. package/deps/couchbase-cxx-client/core/operations/management/view_index_get_all.cxx +3 -1
  74. package/deps/couchbase-cxx-client/core/operations/management/view_index_upsert.cxx +2 -1
  75. package/deps/couchbase-cxx-client/core/origin.cxx +37 -17
  76. package/deps/couchbase-cxx-client/core/platform/base64.cc +1 -1
  77. package/deps/couchbase-cxx-client/core/platform/random.cc +2 -0
  78. package/deps/couchbase-cxx-client/core/platform/uuid.h +6 -6
  79. package/deps/couchbase-cxx-client/core/row_streamer.cxx +1 -1
  80. package/deps/couchbase-cxx-client/core/sasl/scram-sha/stringutils.cc +1 -1
  81. package/deps/couchbase-cxx-client/core/sasl/scram-sha/stringutils.h +4 -4
  82. package/deps/couchbase-cxx-client/core/topology/configuration.hxx +2 -0
  83. package/deps/couchbase-cxx-client/core/topology/configuration_json.hxx +8 -0
  84. package/deps/couchbase-cxx-client/core/tracing/constants.hxx +3 -0
  85. package/deps/couchbase-cxx-client/core/tracing/tracer_wrapper.cxx +87 -0
  86. package/deps/couchbase-cxx-client/core/tracing/tracer_wrapper.hxx +57 -0
  87. package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.cxx +16 -15
  88. package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.hxx +2 -2
  89. package/deps/couchbase-cxx-client/core/transactions/staged_mutation.cxx +2 -2
  90. package/deps/couchbase-cxx-client/core/transactions/transactions.cxx +2 -2
  91. package/deps/couchbase-cxx-client/core/utils/connection_string.cxx +128 -52
  92. package/deps/couchbase-cxx-client/couchbase/analytics_options.hxx +4 -3
  93. package/deps/couchbase-cxx-client/couchbase/codec/tao_json_serializer.hxx +1 -1
  94. package/deps/couchbase-cxx-client/couchbase/mutate_in_specs.hxx +2 -2
  95. package/deps/couchbase-cxx-client/couchbase/query_options.hxx +4 -3
  96. package/deps/couchbase-cxx-client/couchbase/search_options.hxx +1 -1
  97. package/package.json +8 -8
  98. package/src/binding.cpp +13 -13
@@ -17,6 +17,7 @@
17
17
 
18
18
  #include "view_index_drop.hxx"
19
19
 
20
+ #include "core/utils/url_codec.hxx"
20
21
  #include "error_utils.hxx"
21
22
 
22
23
  #include <fmt/core.h>
@@ -30,7 +31,7 @@ view_index_drop_request::encode_to(encoded_request_type& encoded,
30
31
  {
31
32
  encoded.method = "DELETE";
32
33
  encoded.path = fmt::format("/{}/_design/{}{}",
33
- bucket_name,
34
+ utils::string_codec::v2::path_escape(bucket_name),
34
35
  ns == design_document_namespace::development ? "dev_" : "",
35
36
  document_name);
36
37
  return {};
@@ -18,6 +18,7 @@
18
18
  #include "view_index_get.hxx"
19
19
 
20
20
  #include "core/utils/json.hxx"
21
+ #include "core/utils/url_codec.hxx"
21
22
  #include "error_utils.hxx"
22
23
 
23
24
  #include <fmt/core.h>
@@ -31,7 +32,7 @@ view_index_get_request::encode_to(encoded_request_type& encoded,
31
32
  {
32
33
  encoded.method = "GET";
33
34
  encoded.path = fmt::format("/{}/_design/{}{}",
34
- bucket_name,
35
+ utils::string_codec::v2::path_escape(bucket_name),
35
36
  ns == design_document_namespace::development ? "dev_" : "",
36
37
  document_name);
37
38
  return {};
@@ -18,6 +18,7 @@
18
18
  #include "view_index_get_all.hxx"
19
19
 
20
20
  #include "core/utils/json.hxx"
21
+ #include "core/utils/url_codec.hxx"
21
22
  #include "error_utils.hxx"
22
23
 
23
24
  #include <fmt/core.h>
@@ -30,7 +31,8 @@ view_index_get_all_request::encode_to(encoded_request_type& encoded,
30
31
  http_context& /* context */) const -> std::error_code
31
32
  {
32
33
  encoded.method = "GET";
33
- encoded.path = fmt::format("/pools/default/buckets/{}/ddocs", bucket_name);
34
+ encoded.path = fmt::format("/pools/default/buckets/{}/ddocs",
35
+ utils::string_codec::v2::path_escape(bucket_name));
34
36
  return {};
35
37
  }
36
38
 
@@ -18,6 +18,7 @@
18
18
  #include "view_index_upsert.hxx"
19
19
 
20
20
  #include "core/utils/json.hxx"
21
+ #include "core/utils/url_codec.hxx"
21
22
  #include "error_utils.hxx"
22
23
 
23
24
  #include <fmt/core.h>
@@ -45,7 +46,7 @@ view_index_upsert_request::encode_to(encoded_request_type& encoded,
45
46
  encoded.headers["content-type"] = "application/json";
46
47
  encoded.method = "PUT";
47
48
  encoded.path = fmt::format("/{}/_design/{}{}",
48
- bucket_name,
49
+ utils::string_codec::v2::path_escape(bucket_name),
49
50
  document.ns == design_document_namespace::development ? "dev_" : "",
50
51
  document.name);
51
52
  encoded.body = utils::json::generate(body);
@@ -210,6 +210,24 @@ struct traits<couchbase::transactions::transactions_config::built> {
210
210
  }
211
211
  };
212
212
 
213
+ template<>
214
+ struct traits<couchbase::core::columnar::security_options> {
215
+ template<template<typename...> class Traits>
216
+ static void assign(tao::json::basic_value<Traits>& v,
217
+ const couchbase::core::columnar::security_options& o)
218
+ {
219
+ v = {
220
+ { "trust_only_capella", o.trust_only_capella },
221
+ { "trust_only_pem_file", o.trust_only_pem_file },
222
+ { "trust_only_pem_string", o.trust_only_pem_string },
223
+ { "trust_only_platform", o.trust_only_platform },
224
+ { "trust_only_certificates", o.trust_only_certificates.size() },
225
+ // TODO(JC): add if/when we support the cipher_suites option
226
+ // { "cipher_suites", utils::join_strings(o.cipher_suites, ":") },
227
+ };
228
+ }
229
+ };
230
+
213
231
  } // namespace tao::json
214
232
 
215
233
  namespace couchbase::core
@@ -222,45 +240,47 @@ origin::to_json() const -> std::string
222
240
  "options",
223
241
  {
224
242
  { "bootstrap_timeout", options_.bootstrap_timeout },
225
- #ifdef COUCHBASE_CXX_CLIENT_COLUMNAR
226
- { "dispatch_timeout", options_.dispatch_timeout },
227
- #endif
228
243
  { "resolve_timeout", options_.resolve_timeout },
229
244
  { "connect_timeout", options_.connect_timeout },
245
+ { "query_timeout", options_.query_timeout },
246
+ { "management_timeout", options_.management_timeout },
247
+ { "trust_certificate", options_.trust_certificate },
248
+ { "use_ip_protocol", options_.use_ip_protocol },
249
+ { "enable_dns_srv", options_.enable_dns_srv },
250
+ { "dns_config", options_.dns_config },
251
+ { "enable_clustermap_notification", options_.enable_clustermap_notification },
252
+ { "config_poll_interval", options_.config_poll_interval },
253
+ { "config_poll_floor", options_.config_poll_floor },
254
+ { "user_agent_extra", options_.user_agent_extra },
255
+ { "dump_configuration", options_.dump_configuration },
256
+ { "disable_mozilla_ca_certificates", options_.disable_mozilla_ca_certificates },
257
+ { "network", options_.network },
258
+ { "tls_verify", options_.tls_verify },
259
+ #ifdef COUCHBASE_CXX_CLIENT_COLUMNAR
260
+ { "dispatch_timeout", options_.dispatch_timeout },
261
+ { "security_options", options_.security_options },
262
+ #else
230
263
  { "key_value_timeout", options_.key_value_timeout },
231
264
  { "key_value_durable_timeout", options_.key_value_durable_timeout },
232
265
  { "view_timeout", options_.view_timeout },
233
- { "query_timeout", options_.query_timeout },
234
266
  { "analytics_timeout", options_.analytics_timeout },
235
267
  { "search_timeout", options_.search_timeout },
236
- { "management_timeout", options_.management_timeout },
237
268
  { "enable_tls", options_.enable_tls },
238
- { "trust_certificate", options_.trust_certificate },
239
269
  { "enable_mutation_tokens", options_.enable_mutation_tokens },
240
270
  { "enable_tcp_keep_alive", options_.enable_tcp_keep_alive },
241
- { "use_ip_protocol", options_.use_ip_protocol },
242
- { "enable_dns_srv", options_.enable_dns_srv },
243
- { "dns_config", options_.dns_config },
244
271
  { "show_queries", options_.show_queries },
245
272
  { "enable_unordered_execution", options_.enable_unordered_execution },
246
- { "enable_clustermap_notification", options_.enable_clustermap_notification },
247
273
  { "enable_compression", options_.enable_compression },
248
274
  { "enable_tracing", options_.enable_tracing },
249
275
  { "enable_metrics", options_.enable_metrics },
250
276
  { "tcp_keep_alive_interval", options_.tcp_keep_alive_interval },
251
- { "config_poll_interval", options_.config_poll_interval },
252
- { "config_poll_floor", options_.config_poll_floor },
253
277
  { "config_idle_redial_timeout", options_.config_idle_redial_timeout },
254
278
  { "max_http_connections", options_.max_http_connections },
255
279
  { "idle_http_connection_timeout", options_.idle_http_connection_timeout },
256
- { "user_agent_extra", options_.user_agent_extra },
257
- { "dump_configuration", options_.dump_configuration },
258
- { "disable_mozilla_ca_certificates", options_.disable_mozilla_ca_certificates },
259
280
  { "metrics_options", options_.metrics_options },
260
- { "network", options_.network },
261
- { "tls_verify", options_.tls_verify },
262
281
  { "tracing_options", options_.tracing_options },
263
282
  { "transactions_options", options_.transactions },
283
+ #endif
264
284
  },
265
285
  },
266
286
  };
@@ -182,7 +182,7 @@ encode(gsl::span<const std::byte> blob, bool pretty_print) -> std::string
182
182
  if (pretty_print) {
183
183
  // In pretty-print mode we insert a newline after adding
184
184
  // 16 chunks (four characters).
185
- result.reserve(chunks * 4 + chunks / 16);
185
+ result.reserve((chunks * 4) + (chunks / 16));
186
186
  } else {
187
187
  result.reserve(chunks * 4);
188
188
  }
@@ -82,6 +82,8 @@ public:
82
82
  #ifdef WIN32
83
83
  return CryptGenRandom(handle, (DWORD)size, static_cast<BYTE*>(dest));
84
84
  #else
85
+ // TODO(CXXCBC-549)
86
+ // NOLINTNEXTLINE(clang-analyzer-unix.BlockInCriticalSection)
85
87
  return static_cast<std::size_t>(read(handle, dest, size)) == size;
86
88
  #endif
87
89
  }
@@ -34,23 +34,23 @@ random(uuid_t& uuid);
34
34
  /**
35
35
  * Generate a new random uuid and return it
36
36
  */
37
- uuid_t
38
- random();
37
+ auto
38
+ random() -> uuid_t;
39
39
 
40
40
  /**
41
41
  * Convert a textual version of a UUID to a uuid type
42
42
  * @throw std::invalid_argument if the textual uuid is not
43
43
  * formatted correctly
44
44
  */
45
- uuid_t
46
- from_string(std::string_view str);
45
+ auto
46
+ from_string(std::string_view str) -> uuid_t;
47
47
 
48
48
  /**
49
49
  * Print a textual version of the UUID in the form:
50
50
  *
51
51
  * 00000000-0000-0000-0000-000000000000
52
52
  */
53
- std::string
54
- to_string(const couchbase::core::uuid::uuid_t& uuid);
53
+ auto
54
+ to_string(const couchbase::core::uuid::uuid_t& uuid) -> std::string;
55
55
 
56
56
  } // namespace couchbase::core::uuid
@@ -162,7 +162,7 @@ private:
162
162
 
163
163
  feeding_ = true;
164
164
 
165
- body_.next([self = shared_from_this()](auto data, auto ec) mutable {
165
+ body_.next([self = shared_from_this()](const auto& data, auto ec) mutable {
166
166
  if (ec) {
167
167
  self->received_all_data_ = true;
168
168
  auto signal = row_stream_end_signal{ ec };
@@ -44,7 +44,7 @@ namespace couchbase::core::sasl::mechanism::scram
44
44
  * - Tagging characters [StringPrep, C.9]
45
45
  */
46
46
  auto
47
- sasl_prep(const std::string& string) -> const std::string&
47
+ sasl_prep(const std::string& string) -> std::string
48
48
  {
49
49
  for (const auto& c : string) {
50
50
  if ((static_cast<unsigned int>(c) & 0x80U) != 0) {
@@ -32,8 +32,8 @@ namespace couchbase::core::sasl::mechanism::scram
32
32
  * @return a sasl_prep'd string
33
33
  * @throws std::runtime_error if we encounter a multibyte character
34
34
  */
35
- const std::string&
36
- sasl_prep(const std::string& string);
35
+ auto
36
+ sasl_prep(const std::string& string) -> std::string;
37
37
 
38
38
  /**
39
39
  * According to https://www.ietf.org/rfc/rfc5802.txt all occurrences
@@ -42,7 +42,7 @@ sasl_prep(const std::string& string);
42
42
  * @param username the username to encode
43
43
  * @return the escaped string
44
44
  */
45
- std::string
46
- encode_username(const std::string& username);
45
+ auto
46
+ encode_username(const std::string& username) -> std::string;
47
47
 
48
48
  } // namespace couchbase::core::sasl::mechanism::scram
@@ -100,6 +100,8 @@ struct configuration {
100
100
  std::optional<std::uint64_t> collections_manifest_uid{};
101
101
  configuration_capabilities capabilities{};
102
102
  node_locator_type node_locator{ node_locator_type::unknown };
103
+ std::optional<std::string> cluster_name{};
104
+ std::optional<std::string> cluster_uuid{};
103
105
  bool force{ false };
104
106
 
105
107
  auto operator==(const configuration& other) const -> bool
@@ -319,6 +319,14 @@ struct traits<couchbase::core::topology::configuration> {
319
319
  }
320
320
  }
321
321
  }
322
+
323
+ if (const auto n = v.find("clusterName"); n != nullptr) {
324
+ result.cluster_name = n->get_string();
325
+ }
326
+ if (const auto u = v.find("clusterUUID"); u != nullptr) {
327
+ result.cluster_uuid = u->get_string();
328
+ }
329
+
322
330
  return result;
323
331
  }
324
332
  };
@@ -78,6 +78,9 @@ constexpr auto mcbp_internal = "cb.internal";
78
78
  namespace attributes
79
79
  {
80
80
  constexpr auto system = "db.system";
81
+ constexpr auto cluster_name = "db.couchbase.cluster_name";
82
+ constexpr auto cluster_uuid = "db.couchbase.cluster_uuid";
83
+
81
84
  constexpr auto span_kind = "span.kind";
82
85
  constexpr auto component = "db.couchbase.component";
83
86
  constexpr auto instance = "db.instance";
@@ -0,0 +1,87 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2024. Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #include "tracer_wrapper.hxx"
19
+
20
+ #include "constants.hxx"
21
+
22
+ #include <mutex>
23
+
24
+ namespace couchbase::core::tracing
25
+ {
26
+ tracer_wrapper::tracer_wrapper(std::shared_ptr<couchbase::tracing::request_tracer> tracer)
27
+ : tracer_{ std::move(tracer) }
28
+ {
29
+ }
30
+
31
+ void
32
+ tracer_wrapper::start()
33
+ {
34
+ tracer_->start();
35
+ }
36
+
37
+ void
38
+ tracer_wrapper::stop()
39
+ {
40
+ tracer_->stop();
41
+ }
42
+
43
+ auto
44
+ tracer_wrapper::create_span(std::string span_name,
45
+ std::shared_ptr<couchbase::tracing::request_span> parent_span)
46
+ -> std::shared_ptr<couchbase::tracing::request_span>
47
+ {
48
+ auto span = tracer_->start_span(std::move(span_name), std::move(parent_span));
49
+ span->add_tag(attributes::system, "couchbase");
50
+
51
+ std::optional<std::string> cluster_name;
52
+ std::optional<std::string> cluster_uuid;
53
+ {
54
+ const std::shared_lock lock{ cluster_labels_mutex_ };
55
+ cluster_name = cluster_name_;
56
+ cluster_uuid = cluster_uuid_;
57
+ }
58
+
59
+ if (cluster_name) {
60
+ span->add_tag(attributes::cluster_name, cluster_name.value());
61
+ }
62
+ if (cluster_uuid) {
63
+ span->add_tag(attributes::cluster_uuid, cluster_uuid.value());
64
+ }
65
+
66
+ return span;
67
+ }
68
+
69
+ void
70
+ tracer_wrapper::update_config(topology::configuration config)
71
+ {
72
+ const std::scoped_lock<std::shared_mutex> lock{ cluster_labels_mutex_ };
73
+ if (config.cluster_uuid.has_value()) {
74
+ cluster_uuid_ = config.cluster_uuid;
75
+ }
76
+ if (config.cluster_name.has_value()) {
77
+ cluster_name_ = config.cluster_name;
78
+ }
79
+ }
80
+
81
+ auto
82
+ tracer_wrapper::create(std::shared_ptr<couchbase::tracing::request_tracer> tracer)
83
+ -> std::shared_ptr<tracer_wrapper>
84
+ {
85
+ return std::make_shared<tracer_wrapper>(std::move(tracer));
86
+ }
87
+ } // namespace couchbase::core::tracing
@@ -0,0 +1,57 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2024. 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
+ #pragma once
19
+
20
+ #include "core/config_listener.hxx"
21
+ #include "core/topology/configuration.hxx"
22
+
23
+ #include <couchbase/tracing/request_span.hxx>
24
+ #include <couchbase/tracing/request_tracer.hxx>
25
+
26
+ #include <memory>
27
+ #include <optional>
28
+ #include <shared_mutex>
29
+ #include <string>
30
+
31
+ namespace couchbase::core::tracing
32
+ {
33
+ class tracer_wrapper : public config_listener
34
+ {
35
+ public:
36
+ explicit tracer_wrapper(std::shared_ptr<couchbase::tracing::request_tracer> tracer);
37
+
38
+ void start();
39
+ void stop();
40
+
41
+ auto create_span(std::string span_name,
42
+ std::shared_ptr<couchbase::tracing::request_span> parent_span)
43
+ -> std::shared_ptr<couchbase::tracing::request_span>;
44
+
45
+ void update_config(topology::configuration config) override;
46
+
47
+ [[nodiscard]] static auto create(std::shared_ptr<couchbase::tracing::request_tracer> tracer)
48
+ -> std::shared_ptr<tracer_wrapper>;
49
+
50
+ private:
51
+ std::shared_ptr<couchbase::tracing::request_tracer> tracer_;
52
+
53
+ std::optional<std::string> cluster_name_{};
54
+ std::optional<std::string> cluster_uuid_{};
55
+ std::shared_mutex cluster_labels_mutex_{};
56
+ };
57
+ } // namespace couchbase::core::tracing
@@ -2975,7 +2975,7 @@ attempt_context_impl::do_get(const core::document_id& id,
2975
2975
  allow_replica,
2976
2976
  resolving_missing_atr_entry = std::move(resolving_missing_atr_entry),
2977
2977
  cb = std::move(cb)](std::optional<error_class> ec,
2978
- std::optional<std::string> err_message,
2978
+ const std::optional<std::string>& err_message,
2979
2979
  std::optional<transaction_get_result> doc) mutable {
2980
2980
  if (!ec && !doc) {
2981
2981
  // it just isn't there.
@@ -3101,20 +3101,21 @@ template<typename LookupInRequest, typename Callback>
3101
3101
  void
3102
3102
  execute_lookup(attempt_context_impl* ctx, LookupInRequest& req, Callback&& cb)
3103
3103
  {
3104
- ctx->overall()->cluster_ref().execute(req, [ctx, cb = std::forward<Callback>(cb)](auto resp) {
3105
- auto ec = error_class_from_response(resp);
3106
- if (ec) {
3107
- CB_ATTEMPT_CTX_LOG_TRACE(ctx, "get_doc got error {} : {}", resp.ctx.ec().message(), *ec);
3108
- switch (*ec) {
3109
- case FAIL_PATH_NOT_FOUND:
3110
- return cb(ec, resp.ctx.ec().message(), transaction_get_result::create_from(resp));
3111
- default:
3112
- return cb(ec, resp.ctx.ec().message(), std::nullopt);
3104
+ ctx->overall()->cluster_ref().execute(
3105
+ req, [ctx, cb = std::forward<Callback>(cb)](const auto& resp) {
3106
+ auto ec = error_class_from_response(resp);
3107
+ if (ec) {
3108
+ CB_ATTEMPT_CTX_LOG_TRACE(ctx, "get_doc got error {} : {}", resp.ctx.ec().message(), *ec);
3109
+ switch (*ec) {
3110
+ case FAIL_PATH_NOT_FOUND:
3111
+ return cb(ec, resp.ctx.ec().message(), transaction_get_result::create_from(resp));
3112
+ default:
3113
+ return cb(ec, resp.ctx.ec().message(), std::nullopt);
3114
+ }
3115
+ } else {
3116
+ return cb({}, {}, transaction_get_result::create_from(resp));
3113
3117
  }
3114
- } else {
3115
- return cb({}, {}, transaction_get_result::create_from(resp));
3116
- }
3117
- });
3118
+ });
3118
3119
  }
3119
3120
  } // namespace
3120
3121
 
@@ -3161,7 +3162,7 @@ attempt_context_impl::get_doc(const core::document_id& id,
3161
3162
  template<typename Handler, typename Delay>
3162
3163
  void
3163
3164
  attempt_context_impl::create_staged_insert_error_handler(const core::document_id& id,
3164
- codec::encoded_value content,
3165
+ const codec::encoded_value& content,
3165
3166
  std::uint64_t cas,
3166
3167
  Delay&& delay,
3167
3168
  const std::string& op_id,
@@ -463,8 +463,8 @@ private:
463
463
 
464
464
  template<typename Handler, typename Delay>
465
465
  void create_staged_insert_error_handler(const core::document_id& id,
466
- codec::encoded_value content,
467
- uint64_t cas,
466
+ const codec::encoded_value& content,
467
+ std::uint64_t cas,
468
468
  Delay&& delay,
469
469
  const std::string& op_id,
470
470
  Handler&& cb,
@@ -568,7 +568,7 @@ staged_mutation_queue::commit_doc(const std::shared_ptr<attempt_context_impl>& c
568
568
  res,
569
569
  item,
570
570
  [ambiguity_resolution_mode, cas_zero_mode, handler = std::move(handler)](
571
- auto e) mutable {
571
+ const auto& e) mutable {
572
572
  if (e) {
573
573
  return handler(e, ambiguity_resolution_mode, cas_zero_mode);
574
574
  }
@@ -610,7 +610,7 @@ staged_mutation_queue::commit_doc(const std::shared_ptr<attempt_context_impl>& c
610
610
  res,
611
611
  item,
612
612
  [ambiguity_resolution_mode, cas_zero_mode, handler = std::move(handler)](
613
- auto e) mutable {
613
+ const auto& e) mutable {
614
614
  if (e) {
615
615
  return handler(e, ambiguity_resolution_mode, cas_zero_mode);
616
616
  }
@@ -99,7 +99,7 @@ transactions::create(core::cluster cluster,
99
99
  {
100
100
  auto barrier =
101
101
  std::make_shared<std::promise<std::pair<std::error_code, std::shared_ptr<transactions>>>>();
102
- create(std::move(cluster), config, [barrier](auto ec, auto txns) mutable {
102
+ create(std::move(cluster), config, [barrier](auto ec, const auto& txns) mutable {
103
103
  barrier->set_value({ ec, txns });
104
104
  });
105
105
  return barrier->get_future();
@@ -171,7 +171,7 @@ wrap_public_api_run(transactions& txns,
171
171
  std::size_t max_attempts,
172
172
  Handler&& fn) -> ::couchbase::transactions::transaction_result
173
173
  {
174
- return wrap_run(txns, config, max_attempts, [fn = std::forward<Handler>(fn)](auto ctx) {
174
+ return wrap_run(txns, config, max_attempts, [fn = std::forward<Handler>(fn)](const auto& ctx) {
175
175
  const couchbase::error err = fn(ctx);
176
176
  if (err && err.ec() != errc::transaction_op::transaction_op_failed) {
177
177
  if (err.ec().category() == core::impl::transaction_op_category()) {