couchbase 3.4.3 → 3.4.5

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 (179) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/couchbase/CMakeLists.txt +22 -1
  4. data/ext/couchbase/core/bucket.cxx +183 -152
  5. data/ext/couchbase/core/bucket.hxx +17 -4
  6. data/ext/couchbase/core/cluster.hxx +41 -13
  7. data/ext/couchbase/core/cluster_options.hxx +3 -0
  8. data/ext/couchbase/core/crud_component.cxx +51 -22
  9. data/ext/couchbase/core/error_context/key_value.cxx +2 -1
  10. data/ext/couchbase/core/error_context/key_value.hxx +10 -12
  11. data/ext/couchbase/core/impl/build_deferred_query_indexes.cxx +115 -50
  12. data/ext/couchbase/core/impl/cluster.cxx +6 -0
  13. data/ext/couchbase/core/impl/create_bucket.cxx +158 -0
  14. data/ext/couchbase/core/impl/create_collection.cxx +83 -0
  15. data/ext/couchbase/core/impl/create_query_index.cxx +172 -59
  16. data/ext/couchbase/core/impl/create_scope.cxx +69 -0
  17. data/ext/couchbase/core/impl/dns_srv_tracker.cxx +2 -1
  18. data/ext/couchbase/core/impl/drop_bucket.cxx +66 -0
  19. data/ext/couchbase/core/impl/drop_collection.cxx +76 -0
  20. data/ext/couchbase/core/impl/drop_query_index.cxx +138 -59
  21. data/ext/couchbase/core/impl/drop_scope.cxx +68 -0
  22. data/ext/couchbase/core/impl/flush_bucket.cxx +66 -0
  23. data/ext/couchbase/core/impl/get_all_buckets.cxx +178 -0
  24. data/ext/couchbase/core/impl/get_all_query_indexes.cxx +67 -37
  25. data/ext/couchbase/core/impl/get_all_scopes.cxx +94 -0
  26. data/ext/couchbase/core/impl/get_bucket.cxx +168 -0
  27. data/ext/couchbase/core/impl/internal_manager_error_context.cxx +113 -0
  28. data/ext/couchbase/core/impl/internal_manager_error_context.hxx +60 -0
  29. data/ext/couchbase/core/impl/key_value_error_category.cxx +2 -4
  30. data/ext/couchbase/core/impl/key_value_error_context.cxx +98 -0
  31. data/ext/couchbase/core/impl/lookup_in.cxx +1 -0
  32. data/ext/couchbase/core/impl/lookup_in_all_replicas.cxx +178 -0
  33. data/ext/couchbase/core/impl/lookup_in_all_replicas.hxx +80 -0
  34. data/ext/couchbase/core/impl/lookup_in_any_replica.cxx +169 -0
  35. data/ext/couchbase/core/impl/lookup_in_any_replica.hxx +75 -0
  36. data/ext/couchbase/core/impl/lookup_in_replica.cxx +104 -0
  37. data/ext/couchbase/core/impl/lookup_in_replica.hxx +67 -0
  38. data/ext/couchbase/core/impl/manager_error_context.cxx +100 -0
  39. data/ext/couchbase/core/impl/query.cxx +1 -0
  40. data/ext/couchbase/core/impl/query_error_context.cxx +75 -0
  41. data/ext/couchbase/core/impl/update_bucket.cxx +133 -0
  42. data/ext/couchbase/core/impl/update_collection.cxx +83 -0
  43. data/ext/couchbase/core/impl/watch_query_indexes.cxx +53 -29
  44. data/ext/couchbase/core/io/dns_client.cxx +111 -40
  45. data/ext/couchbase/core/io/dns_config.cxx +5 -4
  46. data/ext/couchbase/core/io/http_session.hxx +24 -1
  47. data/ext/couchbase/core/io/mcbp_command.hxx +9 -2
  48. data/ext/couchbase/core/io/mcbp_session.cxx +80 -43
  49. data/ext/couchbase/core/io/mcbp_session.hxx +4 -3
  50. data/ext/couchbase/core/logger/custom_rotating_file_sink.cxx +1 -1
  51. data/ext/couchbase/core/logger/logger.cxx +80 -20
  52. data/ext/couchbase/core/logger/logger.hxx +31 -0
  53. data/ext/couchbase/core/management/bucket_settings.hxx +8 -5
  54. data/ext/couchbase/core/management/bucket_settings_json.hxx +12 -2
  55. data/ext/couchbase/core/meta/features.hxx +42 -0
  56. data/ext/couchbase/core/operations/document_lookup_in.cxx +8 -1
  57. data/ext/couchbase/core/operations/document_lookup_in_all_replicas.hxx +192 -0
  58. data/ext/couchbase/core/operations/document_lookup_in_any_replica.hxx +188 -0
  59. data/ext/couchbase/core/operations/document_query.cxx +11 -0
  60. data/ext/couchbase/core/operations/document_query.hxx +1 -0
  61. data/ext/couchbase/core/operations/management/CMakeLists.txt +1 -0
  62. data/ext/couchbase/core/operations/management/bucket_create.cxx +30 -9
  63. data/ext/couchbase/core/operations/management/bucket_update.cxx +27 -6
  64. data/ext/couchbase/core/operations/management/collection_create.cxx +5 -1
  65. data/ext/couchbase/core/operations/management/collection_create.hxx +1 -0
  66. data/ext/couchbase/core/operations/management/collection_update.cxx +87 -0
  67. data/ext/couchbase/core/operations/management/collection_update.hxx +54 -0
  68. data/ext/couchbase/core/operations/management/collections.hxx +1 -0
  69. data/ext/couchbase/core/operations.hxx +2 -0
  70. data/ext/couchbase/core/origin.cxx +270 -0
  71. data/ext/couchbase/core/origin.hxx +2 -0
  72. data/ext/couchbase/core/protocol/client_response.hxx +1 -0
  73. data/ext/couchbase/core/protocol/cmd_hello.hxx +1 -0
  74. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.cxx +107 -0
  75. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.hxx +137 -0
  76. data/ext/couchbase/core/protocol/hello_feature.hxx +6 -0
  77. data/ext/couchbase/core/protocol/hello_feature_fmt.hxx +3 -0
  78. data/ext/couchbase/core/protocol/status.cxx +2 -2
  79. data/ext/couchbase/core/range_scan_options.cxx +3 -27
  80. data/ext/couchbase/core/range_scan_options.hxx +13 -17
  81. data/ext/couchbase/core/range_scan_orchestrator.cxx +388 -170
  82. data/ext/couchbase/core/range_scan_orchestrator.hxx +13 -2
  83. data/ext/couchbase/core/range_scan_orchestrator_options.hxx +5 -3
  84. data/ext/couchbase/core/scan_options.hxx +0 -19
  85. data/ext/couchbase/core/scan_result.cxx +19 -5
  86. data/ext/couchbase/core/scan_result.hxx +5 -2
  87. data/ext/couchbase/core/timeout_defaults.hxx +3 -4
  88. data/ext/couchbase/core/topology/capabilities.hxx +4 -0
  89. data/ext/couchbase/core/topology/capabilities_fmt.hxx +11 -0
  90. data/ext/couchbase/core/topology/collections_manifest.hxx +2 -0
  91. data/ext/couchbase/core/topology/collections_manifest_fmt.hxx +1 -1
  92. data/ext/couchbase/core/topology/collections_manifest_json.hxx +3 -0
  93. data/ext/couchbase/core/topology/configuration.hxx +20 -0
  94. data/ext/couchbase/core/topology/configuration_json.hxx +8 -1
  95. data/ext/couchbase/core/utils/connection_string.cxx +62 -47
  96. data/ext/couchbase/core/utils/connection_string.hxx +1 -0
  97. data/ext/couchbase/couchbase/analytics_error_context.hxx +1 -1
  98. data/ext/couchbase/couchbase/behavior_options.hxx +19 -2
  99. data/ext/couchbase/couchbase/bucket.hxx +14 -0
  100. data/ext/couchbase/couchbase/bucket_manager.hxx +135 -0
  101. data/ext/couchbase/couchbase/build_query_index_options.hxx +0 -30
  102. data/ext/couchbase/couchbase/cluster.hxx +14 -0
  103. data/ext/couchbase/couchbase/collection.hxx +111 -0
  104. data/ext/couchbase/couchbase/collection_manager.hxx +160 -0
  105. data/ext/couchbase/couchbase/collection_query_index_manager.hxx +7 -48
  106. data/ext/couchbase/couchbase/create_bucket_options.hxx +41 -0
  107. data/ext/couchbase/couchbase/create_collection_options.hxx +44 -0
  108. data/ext/couchbase/couchbase/create_primary_query_index_options.hxx +0 -29
  109. data/ext/couchbase/couchbase/create_query_index_options.hxx +0 -33
  110. data/ext/couchbase/couchbase/create_scope_options.hxx +41 -0
  111. data/ext/couchbase/couchbase/drop_bucket_options.hxx +41 -0
  112. data/ext/couchbase/couchbase/drop_collection_options.hxx +41 -0
  113. data/ext/couchbase/couchbase/drop_primary_query_index_options.hxx +0 -30
  114. data/ext/couchbase/couchbase/drop_query_index_options.hxx +0 -31
  115. data/ext/couchbase/couchbase/drop_scope_options.hxx +41 -0
  116. data/ext/couchbase/couchbase/error_codes.hxx +1 -2
  117. data/ext/couchbase/couchbase/error_context.hxx +10 -2
  118. data/ext/couchbase/couchbase/flush_bucket_options.hxx +41 -0
  119. data/ext/couchbase/{core/topology/error_map_fmt.hxx → couchbase/fmt/key_value_error_map_attribute.hxx} +21 -21
  120. data/ext/couchbase/couchbase/get_all_buckets_options.hxx +44 -0
  121. data/ext/couchbase/couchbase/get_all_query_indexes_options.hxx +0 -30
  122. data/ext/couchbase/couchbase/get_all_scopes_options.hxx +44 -0
  123. data/ext/couchbase/couchbase/get_and_lock_options.hxx +2 -2
  124. data/ext/couchbase/couchbase/get_and_touch_options.hxx +2 -2
  125. data/ext/couchbase/couchbase/get_bucket_options.hxx +43 -0
  126. data/ext/couchbase/couchbase/get_options.hxx +2 -2
  127. data/ext/couchbase/couchbase/insert_options.hxx +3 -3
  128. data/ext/couchbase/couchbase/key_value_error_context.hxx +7 -2
  129. data/ext/couchbase/couchbase/lookup_in_all_replicas_options.hxx +109 -0
  130. data/ext/couchbase/couchbase/lookup_in_any_replica_options.hxx +101 -0
  131. data/ext/couchbase/couchbase/lookup_in_options.hxx +2 -2
  132. data/ext/couchbase/couchbase/lookup_in_replica_result.hxx +74 -0
  133. data/ext/couchbase/couchbase/lookup_in_result.hxx +26 -0
  134. data/ext/couchbase/couchbase/management/bucket_settings.hxx +119 -0
  135. data/ext/couchbase/couchbase/management/collection_spec.hxx +29 -0
  136. data/ext/couchbase/couchbase/management/scope_spec.hxx +29 -0
  137. data/ext/couchbase/couchbase/manager_error_context.hxx +29 -53
  138. data/ext/couchbase/couchbase/mutate_in_options.hxx +2 -2
  139. data/ext/couchbase/couchbase/query_error_context.hxx +3 -1
  140. data/ext/couchbase/couchbase/query_index_manager.hxx +16 -83
  141. data/ext/couchbase/couchbase/query_options.hxx +18 -0
  142. data/ext/couchbase/couchbase/remove_options.hxx +2 -2
  143. data/ext/couchbase/couchbase/replace_options.hxx +3 -3
  144. data/ext/couchbase/couchbase/security_options.hxx +15 -0
  145. data/ext/couchbase/couchbase/subdocument_error_context.hxx +4 -2
  146. data/ext/couchbase/couchbase/touch_options.hxx +2 -2
  147. data/ext/couchbase/couchbase/unlock_options.hxx +2 -2
  148. data/ext/couchbase/couchbase/update_bucket_options.hxx +41 -0
  149. data/ext/couchbase/couchbase/update_collection_options.hxx +44 -0
  150. data/ext/couchbase/couchbase/upsert_options.hxx +3 -3
  151. data/ext/couchbase/couchbase/watch_query_indexes_options.hxx +0 -31
  152. data/ext/couchbase/test/CMakeLists.txt +1 -0
  153. data/ext/couchbase/test/test_integration_collections.cxx +6 -0
  154. data/ext/couchbase/test/test_integration_crud.cxx +5 -0
  155. data/ext/couchbase/test/test_integration_examples.cxx +137 -1
  156. data/ext/couchbase/test/test_integration_management.cxx +1009 -309
  157. data/ext/couchbase/test/test_integration_query.cxx +19 -7
  158. data/ext/couchbase/test/test_integration_range_scan.cxx +351 -112
  159. data/ext/couchbase/test/test_integration_search.cxx +10 -1
  160. data/ext/couchbase/test/test_integration_subdoc.cxx +721 -7
  161. data/ext/couchbase/test/test_transaction_public_async_api.cxx +13 -12
  162. data/ext/couchbase/test/test_transaction_public_blocking_api.cxx +27 -21
  163. data/ext/couchbase/test/test_unit_connection_string.cxx +29 -0
  164. data/ext/couchbase/test/test_unit_query.cxx +75 -0
  165. data/ext/couchbase.cxx +735 -60
  166. data/ext/revisions.rb +3 -3
  167. data/lib/couchbase/cluster.rb +1 -1
  168. data/lib/couchbase/collection.rb +108 -0
  169. data/lib/couchbase/collection_options.rb +100 -1
  170. data/lib/couchbase/errors.rb +5 -0
  171. data/lib/couchbase/key_value_scan.rb +125 -0
  172. data/lib/couchbase/management/bucket_manager.rb +22 -15
  173. data/lib/couchbase/management/collection_manager.rb +158 -9
  174. data/lib/couchbase/options.rb +151 -0
  175. data/lib/couchbase/scope.rb +1 -1
  176. data/lib/couchbase/utils/time.rb +14 -1
  177. data/lib/couchbase/version.rb +1 -1
  178. metadata +59 -8
  179. data/ext/couchbase/core/impl/collection_query_index_manager.cxx +0 -93
@@ -0,0 +1,188 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-2021 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/error_context/key_value.hxx"
21
+ #include "core/impl/lookup_in_replica.hxx"
22
+ #include "core/impl/subdoc/command.hxx"
23
+ #include "core/operations/document_lookup_in.hxx"
24
+ #include "core/operations/operation_traits.hxx"
25
+ #include "core/utils/movable_function.hxx"
26
+ #include "couchbase/codec/encoded_value.hxx"
27
+ #include "couchbase/error_codes.hxx"
28
+
29
+ #include <functional>
30
+ #include <memory>
31
+ #include <mutex>
32
+
33
+ namespace couchbase::core::operations
34
+ {
35
+ struct lookup_in_any_replica_response {
36
+ struct entry {
37
+ std::string path;
38
+ codec::binary value;
39
+ std::size_t original_index;
40
+ bool exists;
41
+ protocol::subdoc_opcode opcode;
42
+ key_value_status_code status;
43
+ std::error_code ec{};
44
+ };
45
+ subdocument_error_context ctx{};
46
+ couchbase::cas cas{};
47
+ std::vector<entry> fields{};
48
+ bool deleted{ false };
49
+ bool is_replica{ true };
50
+ };
51
+
52
+ struct lookup_in_any_replica_request {
53
+ using response_type = lookup_in_any_replica_response;
54
+ using encoded_request_type = core::protocol::client_request<core::protocol::lookup_in_replica_request_body>;
55
+ using encoded_response_type = core::protocol::client_response<core::protocol::lookup_in_replica_response_body>;
56
+
57
+ core::document_id id;
58
+ std::vector<couchbase::core::impl::subdoc::command> specs{};
59
+ std::optional<std::chrono::milliseconds> timeout{};
60
+ std::shared_ptr<couchbase::tracing::request_span> parent_span{ nullptr };
61
+
62
+ template<typename Core, typename Handler>
63
+ void execute(Core core, Handler handler)
64
+ {
65
+ core->with_bucket_configuration(
66
+ id.bucket(),
67
+ [core, id = id, timeout = timeout, specs = specs, parent_span = parent_span, h = std::forward<Handler>(handler)](
68
+ std::error_code ec, const topology::configuration& config) mutable {
69
+ if (!config.supports_subdoc_read_replica()) {
70
+ ec = errc::common::feature_not_available;
71
+ }
72
+ if (specs.size() > 16) {
73
+ ec = errc::common::invalid_argument;
74
+ }
75
+
76
+ if (ec) {
77
+ std::optional<std::string> first_error_path{};
78
+ std::optional<std::size_t> first_error_index{};
79
+ return h(response_type{
80
+ make_subdocument_error_context(make_key_value_error_context(ec, id), ec, first_error_path, first_error_index, false) });
81
+ }
82
+ using handler_type = utils::movable_function<void(response_type)>;
83
+
84
+ struct replica_context {
85
+ replica_context(handler_type&& handler, std::uint32_t expected_responses)
86
+ : handler_(std::move(handler))
87
+ , expected_responses_(expected_responses)
88
+ {
89
+ }
90
+
91
+ handler_type handler_;
92
+ std::uint32_t expected_responses_;
93
+ bool done_{ false };
94
+ std::mutex mutex_{};
95
+ };
96
+ auto ctx = std::make_shared<replica_context>(std::move(h), config.num_replicas.value_or(0U) + 1U);
97
+
98
+ for (std::size_t idx = 1U; idx <= config.num_replicas.value_or(0U); ++idx) {
99
+ document_id replica_id{ id };
100
+ replica_id.node_index(idx);
101
+ core->execute(impl::lookup_in_replica_request{ std::move(replica_id), specs, timeout, parent_span },
102
+ [ctx](impl::lookup_in_replica_response&& resp) {
103
+ handler_type local_handler;
104
+ {
105
+ std::scoped_lock lock(ctx->mutex_);
106
+ if (ctx->done_) {
107
+ return;
108
+ }
109
+ --ctx->expected_responses_;
110
+ if (resp.ctx.ec()) {
111
+ if (ctx->expected_responses_ > 0) {
112
+ // just ignore the response
113
+ return;
114
+ }
115
+ // consider document irretrievable and give up
116
+ resp.ctx.override_ec(errc::key_value::document_irretrievable);
117
+ }
118
+ ctx->done_ = true;
119
+ std::swap(local_handler, ctx->handler_);
120
+ }
121
+ if (local_handler) {
122
+ response_type res{};
123
+ res.ctx = resp.ctx;
124
+ res.cas = resp.cas;
125
+ res.deleted = resp.deleted;
126
+ res.is_replica = true;
127
+ for (auto& field : resp.fields) {
128
+ auto lookup_in_entry = lookup_in_any_replica_response::entry{};
129
+ lookup_in_entry.path = field.path;
130
+ lookup_in_entry.value = field.value;
131
+ lookup_in_entry.status = field.status;
132
+ lookup_in_entry.ec = field.ec;
133
+ lookup_in_entry.exists = field.exists;
134
+ lookup_in_entry.original_index = field.original_index;
135
+ lookup_in_entry.opcode = field.opcode;
136
+ res.fields.emplace_back(lookup_in_entry);
137
+ }
138
+ return local_handler(res);
139
+ }
140
+ });
141
+ }
142
+ core->execute(lookup_in_request{ id, {}, {}, false, specs, timeout }, [ctx](lookup_in_response&& resp) {
143
+ handler_type local_handler{};
144
+ {
145
+ std::scoped_lock lock(ctx->mutex_);
146
+ if (ctx->done_) {
147
+ return;
148
+ }
149
+ --ctx->expected_responses_;
150
+ if (resp.ctx.ec()) {
151
+ if (ctx->expected_responses_ > 0) {
152
+ // just ignore the response
153
+ return;
154
+ }
155
+ // consider document irretrievable and give up
156
+ resp.ctx.override_ec(errc::key_value::document_irretrievable);
157
+ }
158
+ ctx->done_ = true;
159
+ std::swap(local_handler, ctx->handler_);
160
+ }
161
+ if (local_handler) {
162
+ auto res = response_type{};
163
+ res.ctx = resp.ctx;
164
+ res.cas = resp.cas;
165
+ res.deleted = resp.deleted;
166
+ res.is_replica = false;
167
+ for (auto& field : resp.fields) {
168
+ auto lookup_in_entry = lookup_in_any_replica_response::entry{};
169
+ lookup_in_entry.path = field.path;
170
+ lookup_in_entry.value = field.value;
171
+ lookup_in_entry.status = field.status;
172
+ lookup_in_entry.ec = field.ec;
173
+ lookup_in_entry.exists = field.exists;
174
+ lookup_in_entry.original_index = field.original_index;
175
+ lookup_in_entry.opcode = field.opcode;
176
+ res.fields.emplace_back(lookup_in_entry);
177
+ }
178
+ return local_handler(res);
179
+ }
180
+ });
181
+ });
182
+ }
183
+ };
184
+
185
+ template<>
186
+ struct is_compound_operation<lookup_in_any_replica_request> : public std::true_type {
187
+ };
188
+ } // namespace couchbase::core::operations
@@ -85,6 +85,17 @@ query_request::encode_to(query_request::encoded_request_type& encoded, http_cont
85
85
  case couchbase::query_profile::off:
86
86
  break;
87
87
  }
88
+ if (use_replica.has_value()) {
89
+ if (context.config.supports_read_from_replica()) {
90
+ if (use_replica.value()) {
91
+ body["use_replica"] = "on";
92
+ } else {
93
+ body["use_replica"] = "off";
94
+ }
95
+ } else {
96
+ return errc::common::feature_not_available;
97
+ }
98
+ }
88
99
  if (max_parallelism) {
89
100
  body["max_parallelism"] = std::to_string(max_parallelism.value());
90
101
  }
@@ -91,6 +91,7 @@ struct query_request {
91
91
  bool flex_index{ false };
92
92
  bool preserve_expiry{ false };
93
93
 
94
+ std::optional<bool> use_replica{};
94
95
  std::optional<std::uint64_t> max_parallelism{};
95
96
  std::optional<std::uint64_t> scan_cap{};
96
97
  std::optional<std::chrono::milliseconds> scan_wait{};
@@ -28,6 +28,7 @@ add_library(
28
28
  collection_create.cxx
29
29
  collection_drop.cxx
30
30
  collections_manifest_get.cxx
31
+ collection_update.cxx
31
32
  error_utils.cxx
32
33
  eventing_deploy_function.cxx
33
34
  eventing_drop_function.cxx
@@ -48,17 +48,35 @@ bucket_create_request::encode_to(encoded_request_type& encoded, http_context& /*
48
48
  case couchbase::core::management::cluster::bucket_type::unknown:
49
49
  break;
50
50
  }
51
- encoded.body.append(fmt::format("&ramQuotaMB={}", bucket.ram_quota_mb));
52
- if (bucket.bucket_type != couchbase::core::management::cluster::bucket_type::memcached) {
53
- encoded.body.append(fmt::format("&replicaNumber={}", bucket.num_replicas));
51
+ if (bucket.ram_quota_mb == 0) {
52
+ encoded.body.append(fmt::format("&ramQuotaMB={}", 100)); // If not explicitly set, set to prior default value of 100
53
+ } else {
54
+ encoded.body.append(fmt::format("&ramQuotaMB={}", bucket.ram_quota_mb));
54
55
  }
55
- if (bucket.max_expiry > 0) {
56
- encoded.body.append(fmt::format("&maxTTL={}", bucket.max_expiry));
56
+
57
+ if (bucket.bucket_type != couchbase::core::management::cluster::bucket_type::memcached && bucket.num_replicas.has_value()) {
58
+ encoded.body.append(fmt::format("&replicaNumber={}", bucket.num_replicas.value()));
59
+ }
60
+ if (bucket.max_expiry.has_value()) {
61
+ encoded.body.append(fmt::format("&maxTTL={}", bucket.max_expiry.value()));
62
+ }
63
+ if (bucket.bucket_type != couchbase::core::management::cluster::bucket_type::ephemeral && bucket.replica_indexes.has_value()) {
64
+ encoded.body.append(fmt::format("&replicaIndex={}", bucket.replica_indexes.value() ? "1" : "0"));
65
+ }
66
+ if (bucket.history_retention_collection_default.has_value()) {
67
+ encoded.body.append(
68
+ fmt::format("&historyRetentionCollectionDefault={}", bucket.history_retention_collection_default.value() ? "true" : "false"));
57
69
  }
58
- if (bucket.bucket_type != couchbase::core::management::cluster::bucket_type::ephemeral) {
59
- encoded.body.append(fmt::format("&replicaIndex={}", bucket.replica_indexes ? "1" : "0"));
70
+ if (bucket.history_retention_bytes.has_value()) {
71
+ encoded.body.append(fmt::format("&historyRetentionBytes={}", bucket.history_retention_bytes.value()));
60
72
  }
61
- encoded.body.append(fmt::format("&flushEnabled={}", bucket.flush_enabled ? "1" : "0"));
73
+ if (bucket.history_retention_duration.has_value()) {
74
+ encoded.body.append(fmt::format("&historyRetentionSeconds={}", bucket.history_retention_duration.value()));
75
+ }
76
+ if (bucket.flush_enabled.has_value()) {
77
+ encoded.body.append(fmt::format("&flushEnabled={}", bucket.flush_enabled.value() ? "1" : "0"));
78
+ }
79
+
62
80
  switch (bucket.eviction_policy) {
63
81
  case couchbase::core::management::cluster::bucket_eviction_policy::full:
64
82
  encoded.body.append("&evictionPolicy=fullEviction");
@@ -101,7 +119,7 @@ bucket_create_request::encode_to(encoded_request_type& encoded, http_context& /*
101
119
  case couchbase::core::management::cluster::bucket_conflict_resolution::unknown:
102
120
  break;
103
121
  }
104
- if (bucket.minimum_durability_level) {
122
+ if (bucket.minimum_durability_level.has_value()) {
105
123
  switch (bucket.minimum_durability_level.value()) {
106
124
  case durability_level::none:
107
125
  encoded.body.append("&durabilityMinLevel=none");
@@ -151,6 +169,9 @@ bucket_create_request::make_response(error_context::http&& ctx, const encoded_re
151
169
  if (errors != nullptr) {
152
170
  std::vector<std::string> error_list{};
153
171
  for (const auto& [code, message] : errors->get_object()) {
172
+ if (message.get_string().find("Bucket with given name already exists") != std::string::npos) {
173
+ response.ctx.ec = errc::management::bucket_exists;
174
+ }
154
175
  error_list.emplace_back(message.get_string());
155
176
  }
156
177
  if (!error_list.empty()) {
@@ -33,13 +33,34 @@ bucket_update_request::encode_to(encoded_request_type& encoded, http_context& /*
33
33
  encoded.path = fmt::format("/pools/default/buckets/{}", bucket.name);
34
34
 
35
35
  encoded.headers["content-type"] = "application/x-www-form-urlencoded";
36
- encoded.body.append(fmt::format("&ramQuotaMB={}", bucket.ram_quota_mb));
37
- encoded.body.append(fmt::format("&replicaNumber={}", bucket.num_replicas));
38
- if (bucket.max_expiry > 0) {
39
- encoded.body.append(fmt::format("&maxTTL={}", bucket.max_expiry));
36
+
37
+ if (bucket.ram_quota_mb > 0) {
38
+ encoded.body.append(fmt::format("&ramQuotaMB={}", bucket.ram_quota_mb));
39
+ }
40
+ if (bucket.num_replicas.has_value()) {
41
+ encoded.body.append(fmt::format("&replicaNumber={}", bucket.num_replicas.value()));
42
+ }
43
+
44
+ if (bucket.max_expiry.has_value()) {
45
+ encoded.body.append(fmt::format("&maxTTL={}", bucket.max_expiry.value()));
46
+ }
47
+ if (bucket.history_retention_collection_default.has_value()) {
48
+ encoded.body.append(
49
+ fmt::format("&historyRetentionCollectionDefault={}", bucket.history_retention_collection_default.value() ? "true" : "false"));
40
50
  }
41
- encoded.body.append(fmt::format("&replicaIndex={}", bucket.replica_indexes ? "1" : "0"));
42
- encoded.body.append(fmt::format("&flushEnabled={}", bucket.flush_enabled ? "1" : "0"));
51
+ if (bucket.history_retention_bytes.has_value()) {
52
+ encoded.body.append(fmt::format("&historyRetentionBytes={}", bucket.history_retention_bytes.value()));
53
+ }
54
+ if (bucket.history_retention_duration.has_value()) {
55
+ encoded.body.append(fmt::format("&historyRetentionSeconds={}", bucket.history_retention_duration.value()));
56
+ }
57
+ if (bucket.replica_indexes.has_value()) {
58
+ encoded.body.append(fmt::format("&replicaIndex={}", bucket.replica_indexes.value() ? "1" : "0"));
59
+ }
60
+ if (bucket.flush_enabled.has_value()) {
61
+ encoded.body.append(fmt::format("&flushEnabled={}", bucket.flush_enabled.value() ? "1" : "0"));
62
+ }
63
+
43
64
  switch (bucket.eviction_policy) {
44
65
  case couchbase::core::management::cluster::bucket_eviction_policy::full:
45
66
  encoded.body.append("&evictionPolicy=fullEviction");
@@ -35,6 +35,9 @@ collection_create_request::encode_to(encoded_request_type& encoded, http_context
35
35
  if (max_expiry > 0) {
36
36
  encoded.body.append(fmt::format("&maxTTL={}", max_expiry));
37
37
  }
38
+ if (history.has_value()) {
39
+ encoded.body.append(fmt::format("&history={}", history.value()));
40
+ }
38
41
  return {};
39
42
  }
40
43
 
@@ -48,7 +51,8 @@ collection_create_request::make_response(error_context::http&& ctx, const encode
48
51
  std::regex collection_exists("Collection with name .+ already exists");
49
52
  if (std::regex_search(encoded.body.data(), collection_exists)) {
50
53
  response.ctx.ec = errc::management::collection_exists;
51
- } else if (encoded.body.data().find("Not allowed on this version of cluster") != std::string::npos) {
54
+ } else if (encoded.body.data().find("Not allowed on this version of cluster") != std::string::npos ||
55
+ encoded.body.data().find("Bucket must have storage_mode=magma") != std::string::npos) {
52
56
  response.ctx.ec = errc::common::feature_not_available;
53
57
  } else {
54
58
  response.ctx.ec = errc::common::invalid_argument;
@@ -42,6 +42,7 @@ struct collection_create_request {
42
42
  std::string scope_name;
43
43
  std::string collection_name;
44
44
  std::uint32_t max_expiry{ 0 };
45
+ std::optional<bool> history{};
45
46
 
46
47
  std::optional<std::string> client_context_id{};
47
48
  std::optional<std::chrono::milliseconds> timeout{};
@@ -0,0 +1,87 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-2021 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 "collection_update.hxx"
19
+
20
+ #include "core/utils/json.hxx"
21
+ #include "core/utils/url_codec.hxx"
22
+ #include "error_utils.hxx"
23
+
24
+ #include <regex>
25
+
26
+ namespace couchbase::core::operations::management
27
+ {
28
+ std::error_code
29
+ collection_update_request::encode_to(encoded_request_type& encoded, http_context& /* context */) const
30
+ {
31
+ encoded.method = "PATCH";
32
+ encoded.path = fmt::format("/pools/default/buckets/{}/scopes/{}/collections/{}", bucket_name, scope_name, collection_name);
33
+ encoded.headers["content-type"] = "application/x-www-form-urlencoded";
34
+ std::map<std::string, std::string> values{};
35
+ if (max_expiry.has_value()) {
36
+ values["maxTTL"] = std::to_string(max_expiry.value());
37
+ }
38
+ if (history.has_value()) {
39
+ values["history"] = history.value() ? "true" : "false";
40
+ }
41
+ encoded.body = utils::string_codec::v2::form_encode(values);
42
+ return {};
43
+ }
44
+
45
+ collection_update_response
46
+ collection_update_request::make_response(error_context::http&& ctx, const encoded_response_type& encoded) const
47
+ {
48
+ collection_update_response response{ std::move(ctx) };
49
+ if (!response.ctx.ec) {
50
+ switch (encoded.status_code) {
51
+ case 400: {
52
+ if (encoded.body.data().find("Not allowed on this version of cluster") != std::string::npos ||
53
+ encoded.body.data().find("Bucket must have storage_mode=magma") != std::string::npos) {
54
+ response.ctx.ec = errc::common::feature_not_available;
55
+ } else {
56
+ response.ctx.ec = errc::common::invalid_argument;
57
+ }
58
+ } break;
59
+ case 404: {
60
+ std::regex scope_not_found("Scope with name .+ is not found");
61
+ std::regex collection_not_found("Collection with name .+ is not found");
62
+ if (std::regex_search(encoded.body.data(), collection_not_found)) {
63
+ response.ctx.ec = errc::common::collection_not_found;
64
+ } else if (std::regex_search(encoded.body.data(), scope_not_found)) {
65
+ response.ctx.ec = errc::common::scope_not_found;
66
+ } else {
67
+ response.ctx.ec = errc::common::bucket_not_found;
68
+ }
69
+ } break;
70
+ case 200: {
71
+ tao::json::value payload{};
72
+ try {
73
+ payload = utils::json::parse(encoded.body.data());
74
+ } catch (const tao::pegtl::parse_error&) {
75
+ response.ctx.ec = errc::common::parsing_failure;
76
+ return response;
77
+ }
78
+ response.uid = std::stoull(payload.at("uid").get_string(), nullptr, 16);
79
+ } break;
80
+ default:
81
+ response.ctx.ec = extract_common_error_code(encoded.status_code, encoded.body.data());
82
+ break;
83
+ }
84
+ }
85
+ return response;
86
+ }
87
+ } // namespace couchbase::core::operations::management
@@ -0,0 +1,54 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-2021 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/error_context/http.hxx"
21
+ #include "core/io/http_context.hxx"
22
+ #include "core/io/http_message.hxx"
23
+ #include "core/platform/uuid.h"
24
+ #include "core/timeout_defaults.hxx"
25
+
26
+ namespace couchbase::core::operations::management
27
+ {
28
+ struct collection_update_response {
29
+ error_context::http ctx;
30
+ std::uint64_t uid{ 0 };
31
+ };
32
+
33
+ struct collection_update_request {
34
+ using response_type = collection_update_response;
35
+ using encoded_request_type = io::http_request;
36
+ using encoded_response_type = io::http_response;
37
+ using error_context_type = error_context::http;
38
+
39
+ static const inline service_type type = service_type::management;
40
+
41
+ std::string bucket_name;
42
+ std::string scope_name;
43
+ std::string collection_name;
44
+ std::optional<std::uint32_t> max_expiry{};
45
+ std::optional<bool> history{};
46
+
47
+ std::optional<std::string> client_context_id{};
48
+ std::optional<std::chrono::milliseconds> timeout{};
49
+
50
+ [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& context) const;
51
+
52
+ [[nodiscard]] collection_update_response make_response(error_context::http&& ctx, const encoded_response_type& encoded) const;
53
+ };
54
+ } // namespace couchbase::core::operations::management
@@ -19,6 +19,7 @@
19
19
 
20
20
  #include "collection_create.hxx"
21
21
  #include "collection_drop.hxx"
22
+ #include "collection_update.hxx"
22
23
  #include "collections_manifest_get.hxx"
23
24
  #include "scope_create.hxx"
24
25
  #include "scope_drop.hxx"
@@ -30,6 +30,8 @@
30
30
  #include "core/operations/document_increment.hxx"
31
31
  #include "core/operations/document_insert.hxx"
32
32
  #include "core/operations/document_lookup_in.hxx"
33
+ #include "core/operations/document_lookup_in_all_replicas.hxx"
34
+ #include "core/operations/document_lookup_in_any_replica.hxx"
33
35
  #include "core/operations/document_mutate_in.hxx"
34
36
  #include "core/operations/document_prepend.hxx"
35
37
  #include "core/operations/document_query.hxx"