couchbase 3.4.0 → 3.4.2

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 (130) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/couchbase/CMakeLists.txt +10 -3
  4. data/ext/couchbase/cmake/CompilerWarnings.cmake +12 -4
  5. data/ext/couchbase/cmake/Documentation.cmake +4 -3
  6. data/ext/couchbase/cmake/OpenSSL.cmake +52 -7
  7. data/ext/couchbase/cmake/ThirdPartyDependencies.cmake +4 -0
  8. data/ext/couchbase/cmake/VersionInfo.cmake +39 -3
  9. data/ext/couchbase/cmake/test_openssl.cxx +7 -0
  10. data/ext/couchbase/core/cluster_options.hxx +0 -1
  11. data/ext/couchbase/core/config_profile.cxx +23 -1
  12. data/ext/couchbase/core/config_profile.hxx +2 -12
  13. data/ext/couchbase/core/crypto/CMakeLists.txt +5 -1
  14. data/ext/couchbase/core/impl/analytics.cxx +236 -0
  15. data/ext/couchbase/core/impl/cluster.cxx +0 -1
  16. data/ext/couchbase/core/impl/collection_query_index_manager.cxx +3 -3
  17. data/ext/couchbase/core/impl/dns_srv_tracker.cxx +5 -3
  18. data/ext/couchbase/core/impl/get_all_query_indexes.cxx +3 -3
  19. data/ext/couchbase/core/impl/query.cxx +5 -5
  20. data/ext/couchbase/core/impl/transaction_get_result.cxx +54 -0
  21. data/ext/couchbase/core/io/dns_client.cxx +225 -0
  22. data/ext/couchbase/core/io/dns_client.hxx +19 -188
  23. data/ext/couchbase/core/meta/CMakeLists.txt +7 -5
  24. data/ext/couchbase/core/meta/version.cxx +19 -0
  25. data/ext/couchbase/core/operations/document_search.cxx +5 -2
  26. data/ext/couchbase/core/operations/document_search.hxx +0 -1
  27. data/ext/couchbase/core/transactions/active_transaction_record.hxx +2 -2
  28. data/ext/couchbase/core/transactions/atr_cleanup_entry.cxx +1 -0
  29. data/ext/couchbase/core/transactions/attempt_context_impl.cxx +65 -31
  30. data/ext/couchbase/core/transactions/attempt_context_impl.hxx +44 -23
  31. data/ext/couchbase/core/transactions/forward_compat.hxx +2 -2
  32. data/ext/couchbase/core/transactions/internal/transaction_context.hxx +13 -13
  33. data/ext/couchbase/core/transactions/internal/transaction_fields.hxx +1 -0
  34. data/ext/couchbase/core/transactions/internal/transactions_cleanup.hxx +7 -1
  35. data/ext/couchbase/core/transactions/staged_mutation.cxx +1 -1
  36. data/ext/couchbase/core/transactions/staged_mutation.hxx +12 -2
  37. data/ext/couchbase/core/transactions/transaction_context.cxx +9 -11
  38. data/ext/couchbase/core/transactions/transaction_get_result.cxx +41 -31
  39. data/ext/couchbase/core/transactions/transaction_get_result.hxx +7 -3
  40. data/ext/couchbase/core/transactions/transaction_links.hxx +13 -1
  41. data/ext/couchbase/core/transactions/transactions_cleanup.cxx +144 -155
  42. data/ext/couchbase/core/transactions/waitable_op_list.hxx +1 -0
  43. data/ext/couchbase/core/utils/connection_string.cxx +10 -3
  44. data/ext/couchbase/core/utils/connection_string.hxx +3 -3
  45. data/ext/couchbase/couchbase/analytics_error_context.hxx +143 -0
  46. data/ext/couchbase/couchbase/analytics_meta_data.hxx +155 -0
  47. data/ext/couchbase/couchbase/analytics_metrics.hxx +163 -0
  48. data/ext/couchbase/couchbase/analytics_options.hxx +359 -0
  49. data/ext/couchbase/couchbase/analytics_result.hxx +102 -0
  50. data/ext/couchbase/couchbase/analytics_scan_consistency.hxx +46 -0
  51. data/ext/couchbase/couchbase/analytics_status.hxx +41 -0
  52. data/ext/couchbase/couchbase/analytics_warning.hxx +85 -0
  53. data/ext/couchbase/couchbase/cluster.hxx +35 -2
  54. data/ext/couchbase/couchbase/cluster_options.hxx +10 -10
  55. data/ext/couchbase/couchbase/collection.hxx +22 -17
  56. data/ext/couchbase/couchbase/collection_query_index_manager.hxx +1 -1
  57. data/ext/couchbase/couchbase/common_options.hxx +1 -1
  58. data/ext/couchbase/couchbase/configuration_profile.hxx +1 -1
  59. data/ext/couchbase/couchbase/configuration_profiles_registry.hxx +0 -1
  60. data/ext/couchbase/couchbase/create_primary_query_index_options.hxx +1 -1
  61. data/ext/couchbase/couchbase/drop_primary_query_index_options.hxx +1 -1
  62. data/ext/couchbase/couchbase/drop_query_index_options.hxx +1 -1
  63. data/ext/couchbase/couchbase/fmt/analytics_status.hxx +76 -0
  64. data/ext/couchbase/couchbase/fmt/cas.hxx +12 -0
  65. data/ext/couchbase/couchbase/fmt/durability_level.hxx +6 -0
  66. data/ext/couchbase/couchbase/fmt/key_value_extended_error_info.hxx +6 -0
  67. data/ext/couchbase/couchbase/fmt/key_value_status_code.hxx +6 -0
  68. data/ext/couchbase/couchbase/fmt/mutation_token.hxx +6 -0
  69. data/ext/couchbase/couchbase/fmt/query_scan_consistency.hxx +6 -0
  70. data/ext/couchbase/couchbase/fmt/query_status.hxx +6 -0
  71. data/ext/couchbase/couchbase/fmt/retry_reason.hxx +6 -0
  72. data/ext/couchbase/couchbase/fmt/tls_verify_mode.hxx +6 -0
  73. data/ext/couchbase/couchbase/get_all_query_indexes_options.hxx +5 -4
  74. data/ext/couchbase/couchbase/query_index_manager.hxx +4 -2
  75. data/ext/couchbase/couchbase/query_options.hxx +0 -1
  76. data/ext/couchbase/couchbase/scope.hxx +34 -1
  77. data/ext/couchbase/couchbase/subdoc/array_add_unique.hxx +2 -0
  78. data/ext/couchbase/couchbase/subdoc/array_append.hxx +2 -0
  79. data/ext/couchbase/couchbase/subdoc/array_insert.hxx +2 -0
  80. data/ext/couchbase/couchbase/subdoc/array_prepend.hxx +2 -0
  81. data/ext/couchbase/couchbase/subdoc/count.hxx +2 -0
  82. data/ext/couchbase/couchbase/subdoc/counter.hxx +2 -0
  83. data/ext/couchbase/couchbase/subdoc/exists.hxx +2 -0
  84. data/ext/couchbase/couchbase/subdoc/get.hxx +2 -0
  85. data/ext/couchbase/couchbase/subdoc/insert.hxx +2 -0
  86. data/ext/couchbase/couchbase/subdoc/remove.hxx +2 -0
  87. data/ext/couchbase/couchbase/subdoc/replace.hxx +3 -1
  88. data/ext/couchbase/couchbase/subdoc/upsert.hxx +2 -0
  89. data/ext/couchbase/couchbase/transaction_op_error_context.hxx +4 -4
  90. data/ext/couchbase/couchbase/transactions/attempt_context.hxx +1 -1
  91. data/ext/couchbase/couchbase/transactions/transaction_get_result.hxx +36 -51
  92. data/ext/couchbase/couchbase/transactions/transactions_config.hxx +1 -1
  93. data/ext/couchbase/test/CMakeLists.txt +3 -2
  94. data/ext/couchbase/test/test_helper.hxx +1 -1
  95. data/ext/couchbase/test/test_integration_analytics.cxx +289 -13
  96. data/ext/couchbase/test/test_integration_crud.cxx +8 -1
  97. data/ext/couchbase/test/test_integration_examples.cxx +182 -0
  98. data/ext/couchbase/test/test_integration_management.cxx +15 -3
  99. data/ext/couchbase/test/test_integration_search.cxx +601 -0
  100. data/ext/couchbase/test/test_transaction_transaction_simple.cxx +73 -0
  101. data/ext/couchbase/test/test_unit_config_profiles.cxx +12 -12
  102. data/ext/couchbase/test/test_unit_connection_string.cxx +35 -0
  103. data/ext/couchbase/test/test_unit_transaction_utils.cxx +76 -19
  104. data/ext/couchbase/third_party/snappy/CMakeLists.txt +150 -27
  105. data/ext/couchbase/third_party/snappy/cmake/config.h.in +28 -24
  106. data/ext/couchbase/third_party/snappy/snappy-internal.h +189 -25
  107. data/ext/couchbase/third_party/snappy/snappy-sinksource.cc +26 -9
  108. data/ext/couchbase/third_party/snappy/snappy-sinksource.h +11 -11
  109. data/ext/couchbase/third_party/snappy/snappy-stubs-internal.cc +1 -1
  110. data/ext/couchbase/third_party/snappy/snappy-stubs-internal.h +227 -308
  111. data/ext/couchbase/third_party/snappy/snappy-stubs-public.h.in +0 -11
  112. data/ext/couchbase/third_party/snappy/snappy.cc +1176 -410
  113. data/ext/couchbase/third_party/snappy/snappy.h +19 -4
  114. data/ext/couchbase.cxx +506 -26
  115. data/ext/extconf.rb +2 -1
  116. data/ext/revisions.rb +3 -2
  117. data/lib/couchbase/binary_collection.rb +4 -4
  118. data/lib/couchbase/cluster.rb +13 -9
  119. data/lib/couchbase/cluster_registry.rb +7 -2
  120. data/lib/couchbase/collection.rb +5 -0
  121. data/lib/couchbase/configuration.rb +3 -4
  122. data/lib/couchbase/errors.rb +10 -0
  123. data/lib/couchbase/management/collection_query_index_manager.rb +183 -0
  124. data/lib/couchbase/management/query_index_manager.rb +35 -3
  125. data/lib/couchbase/management.rb +1 -0
  126. data/lib/couchbase/options.rb +87 -5
  127. data/lib/couchbase/search_options.rb +158 -240
  128. data/lib/couchbase/version.rb +1 -1
  129. metadata +21 -6
  130. data/ext/couchbase/core/CMakeLists.txt +0 -0
@@ -0,0 +1,182 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2023-Present 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 "test_helper_integration.hxx"
19
+
20
+ #include "core/operations/management/query_index_build.hxx"
21
+ #include "core/operations/management/query_index_create.hxx"
22
+ #include "core/operations/management/query_index_get_all.hxx"
23
+
24
+ #include <couchbase/cluster.hxx>
25
+ #include <couchbase/fmt/cas.hxx>
26
+ #include <couchbase/fmt/mutation_token.hxx>
27
+
28
+ #include <tao/json.hpp>
29
+
30
+ namespace start_using
31
+ {
32
+ //! [start-using]
33
+ #include <couchbase/cluster.hxx>
34
+ #include <couchbase/fmt/cas.hxx>
35
+ #include <couchbase/fmt/mutation_token.hxx>
36
+
37
+ #include <tao/json.hpp>
38
+
39
+ int
40
+ main(int argc, const char* argv[])
41
+ {
42
+ if (argc != 4) {
43
+ fmt::print("USAGE: ./start_using couchbase://127.0.0.1 Administrator password\n");
44
+ return 1;
45
+ }
46
+
47
+ std::string connection_string{ argv[1] };
48
+ std::string username{ argv[2] };
49
+ std::string password{ argv[3] };
50
+ std::string bucket_name{ "travel-sample" };
51
+
52
+ // run IO context on separate thread
53
+ asio::io_context io;
54
+ auto guard = asio::make_work_guard(io);
55
+ std::thread io_thread([&io]() { io.run(); });
56
+
57
+ auto options = couchbase::cluster_options(username, password);
58
+ // customize through the 'options'.
59
+ // For example, optimize timeouts for WAN
60
+ options.apply_profile("wan_development");
61
+
62
+ auto [cluster, ec] = couchbase::cluster::connect(io, connection_string, options).get();
63
+ if (ec) {
64
+ fmt::print("unable to connect to the cluster: {}\n", ec.message());
65
+ return 1;
66
+ }
67
+
68
+ // get a bucket reference
69
+ auto bucket = cluster.bucket(bucket_name);
70
+
71
+ // get a user-defined collection reference
72
+ auto scope = bucket.scope("tenant_agent_00");
73
+ auto collection = scope.collection("users");
74
+
75
+ {
76
+ // upsert document
77
+ auto [ctx, upsert_result] = collection.upsert("my-document", tao::json::value{ { "name", "mike" } }).get();
78
+ if (ctx.ec()) {
79
+ fmt::print("unable to upsert the document \"{}\": {}\n", ctx.id(), ctx.ec().message());
80
+ return 1;
81
+ }
82
+ fmt::print("saved document \"{}\", cas={}, token={}\n", ctx.id(), upsert_result.cas(), upsert_result.mutation_token().value());
83
+ }
84
+
85
+ {
86
+ // get document
87
+ auto [ctx, get_result] = collection.get("my-document").get();
88
+ if (ctx.ec()) {
89
+ fmt::print("unable to get the document \"{}\": {}\n", ctx.id(), ctx.ec().message());
90
+ return 1;
91
+ }
92
+ auto name = get_result.content_as<tao::json::value>()["name"].get_string();
93
+ fmt::print("retrieved document \"{}\", name=\"{}\"\n", ctx.id(), name);
94
+ }
95
+
96
+ {
97
+ // N1QL query
98
+ auto inventory_scope = bucket.scope("inventory");
99
+ auto [ctx, query_result] = inventory_scope.query("SELECT * FROM airline WHERE id = 10").get();
100
+ if (ctx.ec()) {
101
+ fmt::print("unable to perform query: {}, ({}, {})\n", ctx.ec().message(), ctx.first_error_code(), ctx.first_error_message());
102
+ return 1;
103
+ }
104
+ for (const auto& row : query_result.rows_as_json()) {
105
+ fmt::print("row: {}\n", tao::json::to_string(row));
106
+ }
107
+ }
108
+
109
+ // close cluster connection
110
+ cluster.close();
111
+ guard.reset();
112
+
113
+ io_thread.join();
114
+ return 0;
115
+ }
116
+
117
+ /*
118
+
119
+ $ ./start_using couchbase://127.0.0.1 Administrator password
120
+ saved document "my-document", cas=17486a1722b20000
121
+ retrieved document "my-document", name="mike"
122
+ row: {"airline":{"callsign":"MILE-AIR","country":"United States","iata":"Q5","icao":"MLA","id":10,"name":"40-Mile Air","type":"airline"}}
123
+
124
+ */
125
+ //! [start-using]
126
+
127
+ } // namespace start_using
128
+
129
+ TEST_CASE("example: start using", "[integration]")
130
+ {
131
+ test::utils::integration_test_guard integration;
132
+ if (!integration.cluster_version().supports_collections()) {
133
+ return;
134
+ }
135
+
136
+ {
137
+ couchbase::core::operations::management::query_index_create_request req{};
138
+ req.index_name = "def_inventory_airline_primary";
139
+ req.bucket_name = "travel-sample";
140
+ req.scope_name = "inventory";
141
+ req.collection_name = "airline";
142
+ req.is_primary = true;
143
+ req.ignore_if_exists = true;
144
+ auto resp = test::utils::execute(integration.cluster, req);
145
+ REQUIRE_FALSE(resp.ctx.ec);
146
+ }
147
+
148
+ {
149
+ couchbase::core::operations::management::query_index_build_request req{};
150
+ req.index_names = { "def_inventory_airline_primary" };
151
+ req.bucket_name = "travel-sample";
152
+ req.scope_name = "inventory";
153
+ req.collection_name = "airline";
154
+ auto resp = test::utils::execute(integration.cluster, req);
155
+ REQUIRE_FALSE(resp.ctx.ec);
156
+ }
157
+
158
+ CHECK(test::utils::wait_until(
159
+ [&integration]() {
160
+ couchbase::core::operations::management::query_index_get_all_request req{};
161
+ req.bucket_name = "travel-sample";
162
+ req.scope_name = "inventory";
163
+ auto resp = test::utils::execute(integration.cluster, req);
164
+ if (resp.ctx.ec) {
165
+ return false;
166
+ }
167
+ return std::any_of(resp.indexes.begin(), resp.indexes.end(), [](const auto& index) {
168
+ return index.collection_name == "airline" && index.is_primary && index.state == "online";
169
+ });
170
+ },
171
+ std::chrono::minutes{ 5 }));
172
+
173
+ const auto env = test::utils::test_context::load_from_environment();
174
+ const char* argv[] = {
175
+ "start_using", // name of the "executable"
176
+ env.connection_string.c_str(),
177
+ env.username.c_str(),
178
+ env.password.c_str(),
179
+ };
180
+
181
+ REQUIRE(start_using::main(4, argv) == 0);
182
+ }
@@ -2851,11 +2851,23 @@ wait_for_search_pindexes_ready(test::utils::integration_test_guard& integration,
2851
2851
  return false;
2852
2852
  }
2853
2853
  auto stats = couchbase::core::utils::json::parse(resp.stats);
2854
- const auto* num_pindexes_actual = stats.find(fmt::format("{}:{}:num_pindexes_actual", integration.ctx.bucket, index_name));
2854
+
2855
+ const auto num_pindexes_actual_key = fmt::format("{}:{}:num_pindexes_actual", integration.ctx.bucket, index_name);
2856
+ const auto num_pindexes_target_key = fmt::format("{}:{}:num_pindexes_target", integration.ctx.bucket, index_name);
2857
+ const auto* num_pindexes_actual = stats.find(num_pindexes_actual_key);
2858
+ const auto* num_pindexes_target = stats.find(num_pindexes_target_key);
2859
+ CB_LOG_DEBUG(
2860
+ "wait_for_search_pindexes_ready: {}={}, {}={}",
2861
+ num_pindexes_actual_key,
2862
+ (num_pindexes_actual == nullptr || !num_pindexes_actual->is_number()) ? "missing"
2863
+ : std::to_string(num_pindexes_actual->get_unsigned()),
2864
+ num_pindexes_target_key,
2865
+ (num_pindexes_target == nullptr || !num_pindexes_target->is_number()) ? "missing"
2866
+ : std::to_string(num_pindexes_target->get_unsigned()));
2867
+
2855
2868
  if (num_pindexes_actual == nullptr || !num_pindexes_actual->is_number()) {
2856
2869
  return false;
2857
2870
  }
2858
- const auto* num_pindexes_target = stats.find(fmt::format("{}:{}:num_pindexes_target", integration.ctx.bucket, index_name));
2859
2871
  if (num_pindexes_target == nullptr || !num_pindexes_target->is_number()) {
2860
2872
  return false;
2861
2873
  }
@@ -2889,7 +2901,7 @@ TEST_CASE("integration: search index management analyze document", "[integration
2889
2901
  REQUIRE_SUCCESS(resp.ctx.ec);
2890
2902
  }
2891
2903
 
2892
- REQUIRE(wait_for_search_pindexes_ready(integration, index_name));
2904
+ REQUIRE(test::utils::wait_for_search_pindexes_ready(integration.cluster, integration.ctx.bucket, index_name));
2893
2905
 
2894
2906
  couchbase::core::operations::management::search_index_analyze_document_response resp;
2895
2907
  bool operation_completed = test::utils::wait_until([&integration, &index_name, &resp]() {