couchbase 4.2.11-rc.1 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/deps/couchbase-cxx-cache/mozilla-ca-bundle.crt +49 -2
- package/deps/couchbase-cxx-cache/mozilla-ca-bundle.sha256 +1 -1
- package/deps/couchbase-cxx-client/CMakeLists.txt +1 -0
- package/deps/couchbase-cxx-client/cmake/ThirdPartyDependencies.cmake +2 -0
- package/deps/couchbase-cxx-client/core/bucket.cxx +2 -2
- package/deps/couchbase-cxx-client/core/impl/cluster.cxx +51 -5
- package/deps/couchbase-cxx-client/core/impl/collection.cxx +224 -209
- package/deps/couchbase-cxx-client/core/impl/query_error_context.cxx +2 -2
- package/deps/couchbase-cxx-client/core/impl/query_index_manager.cxx +1 -0
- package/deps/couchbase-cxx-client/core/io/dns_client.cxx +4 -0
- package/deps/couchbase-cxx-client/core/io/dns_config.cxx +15 -4
- package/deps/couchbase-cxx-client/core/io/dns_config.hxx +1 -1
- package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +95 -53
- package/deps/couchbase-cxx-client/core/io/mcbp_session.hxx +1 -0
- package/deps/couchbase-cxx-client/core/mcbp/operation_queue.cxx +1 -0
- package/deps/couchbase-cxx-client/core/meta/features.hxx +5 -0
- package/deps/couchbase-cxx-client/core/operations/document_lookup_in_all_replicas.hxx +116 -105
- package/deps/couchbase-cxx-client/core/operations/document_lookup_in_any_replica.hxx +116 -108
- package/deps/couchbase-cxx-client/core/operations/document_search.cxx +97 -81
- package/deps/couchbase-cxx-client/core/operations/document_search.hxx +5 -0
- package/deps/couchbase-cxx-client/core/range_scan_load_balancer.cxx +141 -0
- package/deps/couchbase-cxx-client/core/range_scan_load_balancer.hxx +64 -0
- package/deps/couchbase-cxx-client/core/range_scan_orchestrator.cxx +224 -336
- package/deps/couchbase-cxx-client/core/range_scan_orchestrator.hxx +5 -6
- package/deps/couchbase-cxx-client/core/range_scan_orchestrator_options.hxx +8 -5
- package/deps/couchbase-cxx-client/core/scan_result.hxx +1 -11
- package/deps/couchbase-cxx-client/core/transactions/atr_cleanup_entry.cxx +16 -7
- package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.cxx +578 -483
- package/deps/couchbase-cxx-client/core/transactions/attempt_context_testing_hooks.cxx +51 -50
- package/deps/couchbase-cxx-client/core/transactions/attempt_context_testing_hooks.hxx +4 -2
- package/deps/couchbase-cxx-client/core/transactions/cleanup_testing_hooks.cxx +6 -6
- package/deps/couchbase-cxx-client/core/transactions/cleanup_testing_hooks.hxx +3 -2
- package/deps/couchbase-cxx-client/core/transactions/internal/transactions_cleanup.hxx +2 -0
- package/deps/couchbase-cxx-client/core/transactions/internal/utils.hxx +5 -1
- package/deps/couchbase-cxx-client/core/transactions/staged_mutation.cxx +222 -179
- package/deps/couchbase-cxx-client/core/transactions/staged_mutation.hxx +23 -12
- package/deps/couchbase-cxx-client/core/transactions/transactions.cxx +61 -24
- package/deps/couchbase-cxx-client/core/transactions/transactions_cleanup.cxx +36 -16
- package/deps/couchbase-cxx-client/core/transactions/utils.cxx +9 -0
- package/deps/couchbase-cxx-client/core/transactions.hxx +40 -7
- package/deps/couchbase-cxx-client/couchbase/bucket.hxx +2 -2
- package/deps/couchbase-cxx-client/couchbase/cluster.hxx +20 -1
- package/deps/couchbase-cxx-client/couchbase/collection.hxx +1 -0
- package/deps/couchbase-cxx-client/couchbase/collection_query_index_manager.hxx +1 -1
- package/deps/couchbase-cxx-client/couchbase/error_context.hxx +1 -0
- package/deps/couchbase-cxx-client/couchbase/fork_event.hxx +39 -0
- package/deps/couchbase-cxx-client/couchbase/get_links_analytics_options.hxx +2 -2
- package/deps/couchbase-cxx-client/couchbase/scope.hxx +1 -1
- package/deps/couchbase-cxx-client/couchbase/search_options.hxx +2 -2
- package/deps/couchbase-cxx-client/couchbase/search_result.hxx +1 -1
- package/deps/couchbase-cxx-client/couchbase/subdocument_error_context.hxx +1 -0
- package/deps/couchbase-cxx-client/couchbase/transactions/transaction_options.hxx +1 -1
- package/deps/couchbase-cxx-client/couchbase-sdk-cxx-black-duck-manifest.yaml +1 -0
- package/dist/binding.d.ts +8 -0
- package/dist/bindingutilities.d.ts +6 -1
- package/dist/bindingutilities.js +15 -1
- package/dist/bucketmanager.d.ts +0 -12
- package/dist/cluster.d.ts +0 -2
- package/dist/cluster.js +0 -2
- package/dist/collection.d.ts +3 -3
- package/dist/collection.js +3 -1
- package/dist/querytypes.d.ts +0 -2
- package/dist/rangeScan.d.ts +0 -8
- package/dist/rangeScan.js +0 -8
- package/dist/scope.d.ts +0 -5
- package/dist/scope.js +0 -5
- package/dist/scopesearchindexmanager.d.ts +0 -2
- package/dist/scopesearchindexmanager.js +0 -2
- package/dist/searchexecutor.js +3 -1
- package/dist/searchtypes.d.ts +16 -6
- package/dist/searchtypes.js +2 -6
- package/dist/transactions.d.ts +23 -0
- package/dist/transactions.js +16 -10
- package/dist/vectorsearch.d.ts +8 -8
- package/dist/vectorsearch.js +7 -7
- package/package.json +7 -7
- package/src/instance.cpp +11 -1
- package/src/instance.hpp +1 -0
- package/src/jstocbpp_autogen.hpp +8 -1
- package/src/jstocbpp_transactions.hpp +40 -3
- package/src/transactions.cpp +12 -1
- package/tools/gen-bindings-json.py +0 -1
- package/deps/couchbase-cxx-client/core/scan_options.hxx +0 -44
@@ -62,123 +62,131 @@ struct lookup_in_any_replica_request {
|
|
62
62
|
template<typename Core, typename Handler>
|
63
63
|
void execute(Core core, Handler handler)
|
64
64
|
{
|
65
|
-
core->
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
65
|
+
core->open_bucket(id.bucket(),
|
66
|
+
[core, id = id, timeout = timeout, specs = specs, parent_span = parent_span, h = std::forward<Handler>(handler)](
|
67
|
+
std::error_code ec) mutable {
|
68
|
+
if (ec) {
|
69
|
+
std::optional<std::string> first_error_path{};
|
70
|
+
std::optional<std::size_t> first_error_index{};
|
71
|
+
h(response_type{ make_subdocument_error_context(
|
72
|
+
make_key_value_error_context(ec, id), ec, first_error_path, first_error_index, false) });
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
return core->with_bucket_configuration(
|
76
|
+
id.bucket(),
|
77
|
+
[core, id = id, timeout = timeout, specs = specs, parent_span = parent_span, h = std::forward<Handler>(h)](
|
78
|
+
std::error_code ec, const topology::configuration& config) mutable {
|
79
|
+
if (!config.capabilities.supports_subdoc_read_replica()) {
|
80
|
+
ec = errc::common::feature_not_available;
|
81
|
+
}
|
75
82
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
+
if (ec) {
|
84
|
+
std::optional<std::string> first_error_path{};
|
85
|
+
std::optional<std::size_t> first_error_index{};
|
86
|
+
return h(response_type{ make_subdocument_error_context(
|
87
|
+
make_key_value_error_context(ec, id), ec, first_error_path, first_error_index, false) });
|
88
|
+
}
|
89
|
+
using handler_type = utils::movable_function<void(response_type)>;
|
83
90
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
91
|
+
struct replica_context {
|
92
|
+
replica_context(handler_type&& handler, std::uint32_t expected_responses)
|
93
|
+
: handler_(std::move(handler))
|
94
|
+
, expected_responses_(expected_responses)
|
95
|
+
{
|
96
|
+
}
|
90
97
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
98
|
+
handler_type handler_;
|
99
|
+
std::uint32_t expected_responses_;
|
100
|
+
bool done_{ false };
|
101
|
+
std::mutex mutex_{};
|
102
|
+
};
|
103
|
+
auto ctx = std::make_shared<replica_context>(std::move(h), config.num_replicas.value_or(0U) + 1U);
|
97
104
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
105
|
+
for (std::size_t idx = 1U; idx <= config.num_replicas.value_or(0U); ++idx) {
|
106
|
+
document_id replica_id{ id };
|
107
|
+
replica_id.node_index(idx);
|
108
|
+
core->execute(impl::lookup_in_replica_request{ std::move(replica_id), specs, timeout, parent_span },
|
109
|
+
[ctx](impl::lookup_in_replica_response&& resp) {
|
110
|
+
handler_type local_handler;
|
111
|
+
{
|
112
|
+
std::scoped_lock lock(ctx->mutex_);
|
113
|
+
if (ctx->done_) {
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
--ctx->expected_responses_;
|
117
|
+
if (resp.ctx.ec()) {
|
118
|
+
if (ctx->expected_responses_ > 0) {
|
119
|
+
// just ignore the response
|
120
|
+
return;
|
121
|
+
}
|
122
|
+
// consider document irretrievable and give up
|
123
|
+
resp.ctx.override_ec(errc::key_value::document_irretrievable);
|
124
|
+
}
|
125
|
+
ctx->done_ = true;
|
126
|
+
std::swap(local_handler, ctx->handler_);
|
127
|
+
}
|
128
|
+
if (local_handler) {
|
129
|
+
response_type res{};
|
130
|
+
res.ctx = resp.ctx;
|
131
|
+
res.cas = resp.cas;
|
132
|
+
res.deleted = resp.deleted;
|
133
|
+
res.is_replica = true;
|
134
|
+
for (auto& field : resp.fields) {
|
135
|
+
auto lookup_in_entry = lookup_in_any_replica_response::entry{};
|
136
|
+
lookup_in_entry.path = field.path;
|
137
|
+
lookup_in_entry.value = field.value;
|
138
|
+
lookup_in_entry.status = field.status;
|
139
|
+
lookup_in_entry.ec = field.ec;
|
140
|
+
lookup_in_entry.exists = field.exists;
|
141
|
+
lookup_in_entry.original_index = field.original_index;
|
142
|
+
lookup_in_entry.opcode = field.opcode;
|
143
|
+
res.fields.emplace_back(lookup_in_entry);
|
144
|
+
}
|
145
|
+
return local_handler(res);
|
146
|
+
}
|
147
|
+
});
|
148
|
+
}
|
149
|
+
core->execute(lookup_in_request{ id, {}, {}, false, specs, timeout }, [ctx](lookup_in_response&& resp) {
|
150
|
+
handler_type local_handler{};
|
151
|
+
{
|
152
|
+
std::scoped_lock lock(ctx->mutex_);
|
153
|
+
if (ctx->done_) {
|
113
154
|
return;
|
114
155
|
}
|
115
|
-
|
116
|
-
resp.ctx.
|
156
|
+
--ctx->expected_responses_;
|
157
|
+
if (resp.ctx.ec()) {
|
158
|
+
if (ctx->expected_responses_ > 0) {
|
159
|
+
// just ignore the response
|
160
|
+
return;
|
161
|
+
}
|
162
|
+
// consider document irretrievable and give up
|
163
|
+
resp.ctx.override_ec(errc::key_value::document_irretrievable);
|
164
|
+
}
|
165
|
+
ctx->done_ = true;
|
166
|
+
std::swap(local_handler, ctx->handler_);
|
117
167
|
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
res.fields.emplace_back(lookup_in_entry);
|
168
|
+
if (local_handler) {
|
169
|
+
auto res = response_type{};
|
170
|
+
res.ctx = resp.ctx;
|
171
|
+
res.cas = resp.cas;
|
172
|
+
res.deleted = resp.deleted;
|
173
|
+
res.is_replica = false;
|
174
|
+
for (auto& field : resp.fields) {
|
175
|
+
auto lookup_in_entry = lookup_in_any_replica_response::entry{};
|
176
|
+
lookup_in_entry.path = field.path;
|
177
|
+
lookup_in_entry.value = field.value;
|
178
|
+
lookup_in_entry.status = field.status;
|
179
|
+
lookup_in_entry.ec = field.ec;
|
180
|
+
lookup_in_entry.exists = field.exists;
|
181
|
+
lookup_in_entry.original_index = field.original_index;
|
182
|
+
lookup_in_entry.opcode = field.opcode;
|
183
|
+
res.fields.emplace_back(lookup_in_entry);
|
184
|
+
}
|
185
|
+
return local_handler(res);
|
137
186
|
}
|
138
|
-
|
139
|
-
}
|
187
|
+
});
|
140
188
|
});
|
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
|
-
});
|
189
|
+
});
|
182
190
|
}
|
183
191
|
};
|
184
192
|
|
@@ -133,10 +133,10 @@ search_request::encode_to(search_request::encoded_request_type& encoded, http_co
|
|
133
133
|
encoded.method = "POST";
|
134
134
|
body_str = utils::json::generate(body);
|
135
135
|
encoded.body = body_str;
|
136
|
-
if (context.options.show_queries) {
|
137
|
-
CB_LOG_INFO("SEARCH: {}", utils::json::generate(body
|
136
|
+
if (context.options.show_queries || (log_request.has_value() && log_request.value())) {
|
137
|
+
CB_LOG_INFO("SEARCH: {}", utils::json::generate(body));
|
138
138
|
} else {
|
139
|
-
CB_LOG_DEBUG("SEARCH: {}", utils::json::generate(body
|
139
|
+
CB_LOG_DEBUG("SEARCH: {}", utils::json::generate(body));
|
140
140
|
}
|
141
141
|
if (row_callback) {
|
142
142
|
encoded.streaming.emplace(couchbase::core::io::streaming_settings{
|
@@ -165,6 +165,9 @@ search_request::make_response(error_context::search&& ctx, const encoded_respons
|
|
165
165
|
response.ctx.ec = errc::common::parsing_failure;
|
166
166
|
return response;
|
167
167
|
}
|
168
|
+
if (log_response.has_value() && log_response.value()) {
|
169
|
+
CB_LOG_INFO("SEARCH RESPONSE: {}", utils::json::generate(payload));
|
170
|
+
}
|
168
171
|
response.meta.metrics.took = std::chrono::nanoseconds(payload.at("took").get_unsigned());
|
169
172
|
response.meta.metrics.max_score = payload.at("max_score").as<double>();
|
170
173
|
response.meta.metrics.total_rows = payload.at("total_hits").get_unsigned();
|
@@ -187,106 +190,119 @@ search_request::make_response(error_context::search&& ctx, const encoded_respons
|
|
187
190
|
return response;
|
188
191
|
}
|
189
192
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
for (const auto& [
|
199
|
-
for (const auto&
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
193
|
+
try {
|
194
|
+
if (const auto* rows = payload.find("hits"); rows != nullptr && rows->is_array()) {
|
195
|
+
for (const auto& entry : rows->get_array()) {
|
196
|
+
search_response::search_row row{};
|
197
|
+
row.index = entry.optional<std::string>("index").value_or(std::string());
|
198
|
+
row.id = entry.optional<std::string>("id").value_or(std::string());
|
199
|
+
row.score = entry.optional<double>("score").value_or(0);
|
200
|
+
if (const auto* locations_map = entry.find("locations"); locations_map != nullptr && locations_map->is_object()) {
|
201
|
+
for (const auto& [field, terms] : locations_map->get_object()) {
|
202
|
+
for (const auto& [term, locations] : terms.get_object()) {
|
203
|
+
for (const auto& loc : locations.get_array()) {
|
204
|
+
search_response::search_location location{};
|
205
|
+
location.field = field;
|
206
|
+
location.term = term;
|
207
|
+
location.position = loc.at("pos").get_unsigned();
|
208
|
+
location.start_offset = loc.at("start").get_unsigned();
|
209
|
+
location.end_offset = loc.at("end").get_unsigned();
|
210
|
+
if (const auto* array_positions = loc.find("array_positions");
|
211
|
+
array_positions != nullptr && array_positions->is_array()) {
|
212
|
+
location.array_positions.emplace(array_positions->as<std::vector<std::uint64_t>>());
|
213
|
+
}
|
214
|
+
row.locations.emplace_back(location);
|
209
215
|
}
|
210
|
-
row.locations.emplace_back(location);
|
211
216
|
}
|
212
217
|
}
|
213
218
|
}
|
214
|
-
}
|
215
219
|
|
216
|
-
|
217
|
-
|
218
|
-
|
220
|
+
if (const auto* fragments_map = entry.find("fragments"); fragments_map != nullptr && fragments_map->is_object()) {
|
221
|
+
for (const auto& [field, fragments] : fragments_map->get_object()) {
|
222
|
+
row.fragments.try_emplace(field, fragments.as<std::vector<std::string>>());
|
223
|
+
}
|
219
224
|
}
|
225
|
+
if (const auto* response_fields = entry.find("fields");
|
226
|
+
response_fields != nullptr && response_fields->is_object()) {
|
227
|
+
row.fields = utils::json::generate(*response_fields);
|
228
|
+
}
|
229
|
+
if (const auto* explanation = entry.find("explanation"); explanation != nullptr && explanation->is_object()) {
|
230
|
+
row.explanation = utils::json::generate(*explanation);
|
231
|
+
}
|
232
|
+
response.rows.emplace_back(row);
|
220
233
|
}
|
221
|
-
if (const auto* response_fields = entry.find("fields"); response_fields != nullptr && response_fields->is_object()) {
|
222
|
-
row.fields = utils::json::generate(*response_fields);
|
223
|
-
}
|
224
|
-
if (const auto* explanation = entry.find("explanation"); explanation != nullptr && explanation->is_object()) {
|
225
|
-
row.explanation = utils::json::generate(*explanation);
|
226
|
-
}
|
227
|
-
response.rows.emplace_back(row);
|
228
234
|
}
|
235
|
+
} catch (const std::out_of_range& e) {
|
236
|
+
CB_LOG_ERROR("Error parsing search results. Error: {}.", e.what());
|
237
|
+
response.ctx.ec = errc::common::parsing_failure;
|
238
|
+
return response;
|
229
239
|
}
|
230
240
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
241
|
+
try {
|
242
|
+
if (const auto* response_facets = payload.find("facets"); response_facets != nullptr && response_facets->is_object()) {
|
243
|
+
for (const auto& [name, object] : response_facets->get_object()) {
|
244
|
+
search_response::search_facet facet;
|
245
|
+
facet.name = name;
|
246
|
+
facet.field = object.at("field").get_string();
|
247
|
+
facet.total = object.at("total").get_unsigned();
|
248
|
+
facet.missing = object.at("missing").get_unsigned();
|
249
|
+
facet.other = object.at("other").get_unsigned();
|
239
250
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
251
|
+
if (const auto* date_ranges = object.find("date_ranges"); date_ranges != nullptr && date_ranges->is_array()) {
|
252
|
+
for (const auto& date_range : date_ranges->get_array()) {
|
253
|
+
search_response::search_facet::date_range_facet date_range_facet;
|
254
|
+
date_range_facet.name = date_range.at("name").get_string();
|
255
|
+
date_range_facet.count = date_range.at("count").get_unsigned();
|
256
|
+
if (const auto* start = date_range.find("start"); start != nullptr && start->is_string()) {
|
257
|
+
date_range_facet.start = start->get_string();
|
258
|
+
}
|
259
|
+
if (const auto* end = date_range.find("end"); end != nullptr && end->is_string()) {
|
260
|
+
date_range_facet.end = end->get_string();
|
261
|
+
}
|
262
|
+
facet.date_ranges.emplace_back(date_range_facet);
|
250
263
|
}
|
251
|
-
facet.date_ranges.emplace_back(date_range_facet);
|
252
264
|
}
|
253
|
-
}
|
254
265
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
+
if (const auto& numeric_ranges = object.find("numeric_ranges");
|
267
|
+
numeric_ranges != nullptr && numeric_ranges->is_array()) {
|
268
|
+
for (const auto& numeric_range : numeric_ranges->get_array()) {
|
269
|
+
search_response::search_facet::numeric_range_facet numeric_range_facet;
|
270
|
+
numeric_range_facet.name = numeric_range.at("name").get_string();
|
271
|
+
numeric_range_facet.count = numeric_range.at("count").get_unsigned();
|
272
|
+
if (const auto* min = numeric_range.find("min"); min != nullptr) {
|
273
|
+
if (min->is_double()) {
|
274
|
+
numeric_range_facet.min = min->as<double>();
|
275
|
+
} else if (min->is_integer()) {
|
276
|
+
numeric_range_facet.min = min->get_unsigned();
|
277
|
+
}
|
266
278
|
}
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
279
|
+
if (const auto* max = numeric_range.find("max"); max != nullptr) {
|
280
|
+
if (max->is_double()) {
|
281
|
+
numeric_range_facet.max = max->as<double>();
|
282
|
+
} else if (max->is_integer()) {
|
283
|
+
numeric_range_facet.max = max->get_unsigned();
|
284
|
+
}
|
273
285
|
}
|
286
|
+
facet.numeric_ranges.emplace_back(numeric_range_facet);
|
274
287
|
}
|
275
|
-
facet.numeric_ranges.emplace_back(numeric_range_facet);
|
276
288
|
}
|
277
|
-
}
|
278
289
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
290
|
+
if (const auto* terms = object.find("terms"); terms != nullptr && terms->is_array()) {
|
291
|
+
for (const auto& term : terms->get_array()) {
|
292
|
+
search_response::search_facet::term_facet term_facet;
|
293
|
+
term_facet.term = term.at("term").get_string();
|
294
|
+
term_facet.count = term.at("count").get_unsigned();
|
295
|
+
facet.terms.emplace_back(term_facet);
|
296
|
+
}
|
285
297
|
}
|
286
|
-
}
|
287
298
|
|
288
|
-
|
299
|
+
response.facets.emplace_back(facet);
|
300
|
+
}
|
289
301
|
}
|
302
|
+
} catch (const std::out_of_range& e) {
|
303
|
+
CB_LOG_ERROR("Error parsing search facets. Error: {}.", e.what());
|
304
|
+
response.ctx.ec = errc::common::parsing_failure;
|
305
|
+
return response;
|
290
306
|
}
|
291
307
|
return response;
|
292
308
|
}
|
@@ -155,6 +155,11 @@ struct search_request {
|
|
155
155
|
std::optional<std::function<utils::json::stream_control(std::string)>> row_callback{};
|
156
156
|
std::optional<std::string> client_context_id{};
|
157
157
|
std::optional<std::chrono::milliseconds> timeout{};
|
158
|
+
/**
|
159
|
+
* UNCOMMITTED: If set to true, will log the request to and/or the response from the search service.
|
160
|
+
*/
|
161
|
+
std::optional<bool> log_request{ false };
|
162
|
+
std::optional<bool> log_response{ false };
|
158
163
|
|
159
164
|
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& context);
|
160
165
|
|
@@ -0,0 +1,141 @@
|
|
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 "range_scan_load_balancer.hxx"
|
19
|
+
|
20
|
+
#include <algorithm>
|
21
|
+
#include <limits>
|
22
|
+
#include <map>
|
23
|
+
#include <numeric>
|
24
|
+
#include <queue>
|
25
|
+
#include <random>
|
26
|
+
#include <vector>
|
27
|
+
|
28
|
+
namespace couchbase::core
|
29
|
+
{
|
30
|
+
range_scan_node_state::range_scan_node_state(std::queue<std::uint16_t> vbuckets)
|
31
|
+
: pending_vbuckets_{ std::move(vbuckets) }
|
32
|
+
{
|
33
|
+
}
|
34
|
+
|
35
|
+
auto
|
36
|
+
range_scan_node_state::fetch_vbucket_id() -> std::optional<std::uint16_t>
|
37
|
+
{
|
38
|
+
std::lock_guard<std::mutex> const lock{ mutex_ };
|
39
|
+
if (pending_vbuckets_.empty()) {
|
40
|
+
return {};
|
41
|
+
}
|
42
|
+
active_stream_count_++;
|
43
|
+
auto vbucket_id = pending_vbuckets_.front();
|
44
|
+
pending_vbuckets_.pop();
|
45
|
+
return vbucket_id;
|
46
|
+
}
|
47
|
+
|
48
|
+
void
|
49
|
+
range_scan_node_state::notify_stream_ended()
|
50
|
+
{
|
51
|
+
std::lock_guard<std::mutex> const lock{ mutex_ };
|
52
|
+
active_stream_count_--;
|
53
|
+
}
|
54
|
+
|
55
|
+
void
|
56
|
+
range_scan_node_state::enqueue_vbucket(std::uint16_t vbucket_id)
|
57
|
+
{
|
58
|
+
std::lock_guard<std::mutex> const lock{ mutex_ };
|
59
|
+
pending_vbuckets_.push(vbucket_id);
|
60
|
+
}
|
61
|
+
|
62
|
+
auto
|
63
|
+
range_scan_node_state::active_stream_count() -> std::uint16_t
|
64
|
+
{
|
65
|
+
std::lock_guard<std::mutex> const lock{ mutex_ };
|
66
|
+
return active_stream_count_;
|
67
|
+
}
|
68
|
+
|
69
|
+
auto
|
70
|
+
range_scan_node_state::pending_vbucket_count() -> std::size_t
|
71
|
+
{
|
72
|
+
std::lock_guard<std::mutex> const lock{ mutex_ };
|
73
|
+
return pending_vbuckets_.size();
|
74
|
+
}
|
75
|
+
|
76
|
+
range_scan_load_balancer::range_scan_load_balancer(const topology::configuration::vbucket_map& vbucket_map,
|
77
|
+
std::optional<std::uint64_t> seed)
|
78
|
+
: seed_{ seed }
|
79
|
+
{
|
80
|
+
std::map<std::int16_t, std::queue<std::uint16_t>> node_to_vbucket_map{};
|
81
|
+
for (std::uint16_t vbucket_id = 0; vbucket_id < vbucket_map.size(); vbucket_id++) {
|
82
|
+
auto node_id = vbucket_map[vbucket_id][0];
|
83
|
+
node_to_vbucket_map[node_id].push(vbucket_id);
|
84
|
+
}
|
85
|
+
for (auto [node_id, vbucket_ids] : node_to_vbucket_map) {
|
86
|
+
nodes_.emplace(node_id, std::move(vbucket_ids));
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
void
|
91
|
+
range_scan_load_balancer::seed(std::uint64_t seed)
|
92
|
+
{
|
93
|
+
seed_ = seed;
|
94
|
+
}
|
95
|
+
|
96
|
+
auto
|
97
|
+
range_scan_load_balancer::select_vbucket() -> std::optional<std::uint16_t>
|
98
|
+
{
|
99
|
+
std::lock_guard<std::mutex> const lock{ select_vbucket_mutex_ };
|
100
|
+
|
101
|
+
auto min_stream_count = std::numeric_limits<std::uint16_t>::max();
|
102
|
+
std::optional<std::int16_t> selected_node_id{};
|
103
|
+
|
104
|
+
std::vector<std::map<int16_t, range_scan_node_state>::iterator> iterators{ nodes_.size() };
|
105
|
+
|
106
|
+
std::iota(iterators.begin(), iterators.end(), nodes_.begin());
|
107
|
+
std::mt19937_64 gen{ std::random_device{}() };
|
108
|
+
if (seed_.has_value()) {
|
109
|
+
gen.seed(seed_.value());
|
110
|
+
}
|
111
|
+
std::shuffle(iterators.begin(), iterators.end(), gen);
|
112
|
+
|
113
|
+
for (auto it : iterators) {
|
114
|
+
auto& [node_id, node_status] = *it;
|
115
|
+
auto stream_count = node_status.active_stream_count();
|
116
|
+
|
117
|
+
if (stream_count < min_stream_count && node_status.pending_vbucket_count() > 0) {
|
118
|
+
min_stream_count = stream_count;
|
119
|
+
selected_node_id = node_id;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
if (!selected_node_id) {
|
124
|
+
return {};
|
125
|
+
}
|
126
|
+
|
127
|
+
return nodes_.at(selected_node_id.value()).fetch_vbucket_id();
|
128
|
+
}
|
129
|
+
|
130
|
+
void
|
131
|
+
range_scan_load_balancer::notify_stream_ended(std::int16_t node_id)
|
132
|
+
{
|
133
|
+
nodes_.at(node_id).notify_stream_ended();
|
134
|
+
}
|
135
|
+
|
136
|
+
void
|
137
|
+
range_scan_load_balancer::enqueue_vbucket(std::int16_t node_id, std::uint16_t vbucket_id)
|
138
|
+
{
|
139
|
+
nodes_.at(node_id).enqueue_vbucket(vbucket_id);
|
140
|
+
}
|
141
|
+
} // namespace couchbase::core
|