couchbase 3.1.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/CMakeLists.txt +3 -1
- data/ext/build_version.hxx.in +1 -1
- data/ext/cmake/Testing.cmake +1 -0
- data/ext/cmake/ThirdPartyDependencies.cmake +6 -0
- data/ext/cmake/VersionInfo.cmake +3 -0
- data/ext/couchbase/bucket.hxx +47 -28
- data/ext/couchbase/cbsasl/client.h +1 -1
- data/ext/couchbase/cbsasl/context.cc +1 -1
- data/ext/couchbase/cbsasl/context.h +3 -3
- data/ext/couchbase/cbsasl/mechanism.cc +5 -8
- data/ext/couchbase/cbsasl/mechanism.h +1 -4
- data/ext/couchbase/cbsasl/plain/plain.cc +1 -1
- data/ext/couchbase/cbsasl/scram-sha/scram-sha.cc +30 -36
- data/ext/couchbase/cluster.hxx +40 -22
- data/ext/couchbase/cluster_options.hxx +7 -1
- data/ext/couchbase/configuration.hxx +37 -16
- data/ext/couchbase/couchbase.cxx +1145 -291
- data/ext/couchbase/error_map.hxx +1 -1
- data/ext/couchbase/errors.hxx +25 -17
- data/ext/couchbase/io/dns_client.hxx +3 -3
- data/ext/couchbase/io/dns_codec.hxx +4 -5
- data/ext/couchbase/io/dns_config.hxx +5 -6
- data/ext/couchbase/io/dns_message.hxx +3 -3
- data/ext/couchbase/io/http_command.hxx +70 -35
- data/ext/couchbase/io/http_session.hxx +4 -3
- data/ext/couchbase/io/http_session_manager.hxx +28 -19
- data/ext/couchbase/io/mcbp_command.hxx +51 -19
- data/ext/couchbase/io/mcbp_context.hxx +1 -1
- data/ext/couchbase/io/mcbp_parser.hxx +4 -4
- data/ext/couchbase/io/mcbp_session.hxx +91 -101
- data/ext/couchbase/io/query_cache.hxx +2 -2
- data/ext/couchbase/io/retry_orchestrator.hxx +2 -4
- data/ext/couchbase/io/retry_reason.hxx +2 -2
- data/ext/couchbase/io/retry_strategy.hxx +1 -6
- data/ext/couchbase/io/streams.hxx +7 -7
- data/ext/couchbase/metrics/logging_meter.hxx +228 -0
- data/ext/couchbase/metrics/logging_meter_options.hxx +28 -0
- data/ext/couchbase/metrics/meter.hxx +49 -0
- data/ext/couchbase/metrics/noop_meter.hxx +43 -0
- data/ext/couchbase/operations/analytics_dataset_create.hxx +16 -12
- data/ext/couchbase/operations/analytics_dataset_drop.hxx +11 -11
- data/ext/couchbase/operations/analytics_dataset_get_all.hxx +6 -6
- data/ext/couchbase/operations/analytics_dataverse_create.hxx +10 -11
- data/ext/couchbase/operations/analytics_dataverse_drop.hxx +10 -11
- data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +9 -11
- data/ext/couchbase/operations/analytics_index_create.hxx +14 -13
- data/ext/couchbase/operations/analytics_index_drop.hxx +18 -12
- data/ext/couchbase/operations/analytics_index_get_all.hxx +8 -6
- data/ext/couchbase/operations/analytics_link.hxx +39 -0
- data/ext/couchbase/operations/analytics_link_azure_blob_external.hxx +145 -0
- data/ext/couchbase/operations/analytics_link_connect.hxx +14 -12
- data/ext/couchbase/operations/analytics_link_couchbase_remote.hxx +220 -0
- data/ext/couchbase/operations/analytics_link_create.hxx +128 -0
- data/ext/couchbase/operations/analytics_link_disconnect.hxx +11 -12
- data/ext/couchbase/operations/analytics_link_drop.hxx +130 -0
- data/ext/couchbase/operations/analytics_link_get_all.hxx +160 -0
- data/ext/couchbase/operations/analytics_link_replace.hxx +128 -0
- data/ext/couchbase/operations/analytics_link_s3_external.hxx +122 -0
- data/ext/couchbase/operations/bucket_create.hxx +8 -8
- data/ext/couchbase/operations/bucket_drop.hxx +5 -5
- data/ext/couchbase/operations/bucket_flush.hxx +5 -5
- data/ext/couchbase/operations/bucket_get.hxx +7 -7
- data/ext/couchbase/operations/bucket_get_all.hxx +7 -5
- data/ext/couchbase/operations/bucket_settings.hxx +40 -49
- data/ext/couchbase/operations/bucket_update.hxx +8 -8
- data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +7 -7
- data/ext/couchbase/operations/collection_create.hxx +11 -11
- data/ext/couchbase/operations/collection_drop.hxx +12 -10
- data/ext/couchbase/operations/collections_manifest_get.hxx +3 -3
- data/ext/couchbase/operations/design_document.hxx +2 -2
- data/ext/couchbase/operations/document_analytics.hxx +29 -36
- data/ext/couchbase/operations/document_append.hxx +3 -3
- data/ext/couchbase/operations/document_decrement.hxx +3 -3
- data/ext/couchbase/operations/document_exists.hxx +2 -2
- data/ext/couchbase/operations/document_get.hxx +3 -3
- data/ext/couchbase/operations/document_get_and_lock.hxx +5 -3
- data/ext/couchbase/operations/document_get_and_touch.hxx +5 -3
- data/ext/couchbase/operations/document_get_projected.hxx +10 -11
- data/ext/couchbase/operations/document_increment.hxx +3 -3
- data/ext/couchbase/operations/document_insert.hxx +3 -3
- data/ext/couchbase/operations/document_lookup_in.hxx +12 -18
- data/ext/couchbase/operations/document_mutate_in.hxx +13 -18
- data/ext/couchbase/operations/document_prepend.hxx +3 -3
- data/ext/couchbase/operations/document_query.hxx +39 -41
- data/ext/couchbase/operations/document_remove.hxx +3 -3
- data/ext/couchbase/operations/document_replace.hxx +3 -3
- data/ext/couchbase/operations/document_search.hxx +56 -61
- data/ext/couchbase/operations/document_touch.hxx +3 -3
- data/ext/couchbase/operations/document_unlock.hxx +3 -3
- data/ext/couchbase/operations/document_upsert.hxx +3 -3
- data/ext/couchbase/operations/document_view.hxx +23 -23
- data/ext/couchbase/operations/group_drop.hxx +5 -5
- data/ext/couchbase/operations/group_get.hxx +7 -7
- data/ext/couchbase/operations/group_get_all.hxx +6 -6
- data/ext/couchbase/operations/group_upsert.hxx +11 -11
- data/ext/couchbase/operations/http_noop.hxx +6 -6
- data/ext/couchbase/operations/mcbp_noop.hxx +3 -3
- data/ext/couchbase/operations/query_index_build_deferred.hxx +6 -6
- data/ext/couchbase/operations/query_index_create.hxx +10 -8
- data/ext/couchbase/operations/query_index_drop.hxx +8 -8
- data/ext/couchbase/operations/query_index_get_all.hxx +43 -39
- data/ext/couchbase/operations/rbac.hxx +40 -63
- data/ext/couchbase/operations/role_get_all.hxx +6 -6
- data/ext/couchbase/operations/scope_create.hxx +10 -10
- data/ext/couchbase/operations/scope_drop.hxx +9 -9
- data/ext/couchbase/operations/scope_get_all.hxx +8 -8
- data/ext/couchbase/operations/search_get_stats.hxx +5 -3
- data/ext/couchbase/operations/search_index.hxx +6 -15
- data/ext/couchbase/operations/search_index_analyze_document.hxx +11 -11
- data/ext/couchbase/operations/search_index_control_ingest.hxx +9 -9
- data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +9 -9
- data/ext/couchbase/operations/search_index_control_query.hxx +9 -9
- data/ext/couchbase/operations/search_index_drop.hxx +11 -9
- data/ext/couchbase/operations/search_index_get.hxx +11 -9
- data/ext/couchbase/operations/search_index_get_all.hxx +11 -11
- data/ext/couchbase/operations/search_index_get_documents_count.hxx +10 -10
- data/ext/couchbase/operations/search_index_get_stats.hxx +10 -8
- data/ext/couchbase/operations/search_index_upsert.hxx +12 -10
- data/ext/couchbase/operations/user_drop.hxx +5 -5
- data/ext/couchbase/operations/user_get.hxx +7 -7
- data/ext/couchbase/operations/user_get_all.hxx +6 -6
- data/ext/couchbase/operations/user_upsert.hxx +9 -9
- data/ext/couchbase/operations/view_index_drop.hxx +10 -10
- data/ext/couchbase/operations/view_index_get.hxx +13 -15
- data/ext/couchbase/operations/view_index_get_all.hxx +17 -20
- data/ext/couchbase/operations/view_index_upsert.hxx +9 -7
- data/ext/couchbase/operations.hxx +4 -0
- data/ext/couchbase/origin.hxx +14 -10
- data/ext/couchbase/platform/backtrace.c +1 -1
- data/ext/couchbase/platform/base64.cc +5 -5
- data/ext/couchbase/platform/base64.h +2 -5
- data/ext/couchbase/protocol/client_opcode.hxx +7 -4
- data/ext/couchbase/protocol/client_request.hxx +2 -2
- data/ext/couchbase/protocol/client_response.hxx +41 -16
- data/ext/couchbase/protocol/cmd_append.hxx +17 -16
- data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +4 -4
- data/ext/couchbase/protocol/cmd_decrement.hxx +10 -11
- data/ext/couchbase/protocol/cmd_exists.hxx +12 -15
- data/ext/couchbase/protocol/cmd_get.hxx +11 -14
- data/ext/couchbase/protocol/cmd_get_and_lock.hxx +10 -12
- data/ext/couchbase/protocol/cmd_get_and_touch.hxx +10 -12
- data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +13 -18
- data/ext/couchbase/protocol/cmd_get_collection_id.hxx +12 -15
- data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +12 -16
- data/ext/couchbase/protocol/cmd_get_error_map.hxx +14 -17
- data/ext/couchbase/protocol/cmd_hello.hxx +8 -10
- data/ext/couchbase/protocol/cmd_increment.hxx +9 -10
- data/ext/couchbase/protocol/cmd_insert.hxx +9 -9
- data/ext/couchbase/protocol/cmd_lookup_in.hxx +12 -13
- data/ext/couchbase/protocol/cmd_mutate_in.hxx +11 -11
- data/ext/couchbase/protocol/cmd_noop.hxx +16 -20
- data/ext/couchbase/protocol/cmd_prepend.hxx +9 -10
- data/ext/couchbase/protocol/cmd_remove.hxx +10 -13
- data/ext/couchbase/protocol/cmd_replace.hxx +7 -7
- data/ext/couchbase/protocol/cmd_sasl_auth.hxx +8 -10
- data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +10 -15
- data/ext/couchbase/protocol/cmd_sasl_step.hxx +10 -12
- data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -18
- data/ext/couchbase/protocol/cmd_touch.hxx +8 -11
- data/ext/couchbase/protocol/cmd_unlock.hxx +10 -14
- data/ext/couchbase/protocol/cmd_upsert.hxx +8 -8
- data/ext/couchbase/protocol/datatype.hxx +3 -3
- data/ext/couchbase/protocol/durability_level.hxx +2 -2
- data/ext/couchbase/protocol/frame_info_id.hxx +4 -4
- data/ext/couchbase/protocol/hello_feature.hxx +2 -2
- data/ext/couchbase/protocol/magic.hxx +2 -2
- data/ext/couchbase/protocol/server_opcode.hxx +2 -2
- data/ext/couchbase/protocol/server_request.hxx +1 -1
- data/ext/couchbase/protocol/status.hxx +4 -7
- data/ext/couchbase/protocol/unsigned_leb128.h +5 -20
- data/ext/couchbase/service_type.hxx +4 -4
- data/ext/couchbase/tracing/constants.hxx +261 -0
- data/ext/couchbase/tracing/noop_tracer.hxx +50 -0
- data/ext/couchbase/tracing/request_tracer.hxx +77 -0
- data/ext/couchbase/tracing/threshold_logging_options.hxx +64 -0
- data/ext/couchbase/tracing/threshold_logging_tracer.hxx +366 -0
- data/ext/couchbase/utils/byteswap.hxx +1 -1
- data/ext/couchbase/utils/connection_string.hxx +21 -1
- data/ext/couchbase/utils/name_codec.hxx +41 -0
- data/ext/couchbase/utils/url_codec.hxx +236 -0
- data/ext/couchbase/version.hxx +1 -1
- data/ext/test/CMakeLists.txt +1 -0
- data/ext/test/test_native_trivial_query.cxx +60 -0
- data/ext/third_party/hdr_histogram_c/CMakeLists.txt +84 -0
- data/ext/third_party/hdr_histogram_c/COPYING.txt +121 -0
- data/ext/third_party/hdr_histogram_c/LICENSE.txt +41 -0
- data/ext/third_party/hdr_histogram_c/config.cmake.in +6 -0
- data/ext/third_party/hdr_histogram_c/src/CMakeLists.txt +83 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_atomic.h +146 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_encoding.c +322 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_encoding.h +79 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_endian.h +116 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram.c +1196 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram.h +516 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log.c +1290 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log.h +236 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log_no_op.c +171 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_interval_recorder.c +227 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_interval_recorder.h +109 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_malloc.h +19 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_tests.h +22 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_thread.c +108 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_thread.h +55 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_time.c +98 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_time.h +49 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_writer_reader_phaser.c +143 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_writer_reader_phaser.h +51 -0
- data/lib/couchbase/cluster.rb +1 -0
- data/lib/couchbase/errors.rb +3 -0
- data/lib/couchbase/management/analytics_index_manager.rb +920 -226
- data/lib/couchbase/management/bucket_manager.rb +207 -69
- data/lib/couchbase/management/collection_manager.rb +173 -61
- data/lib/couchbase/management/query_index_manager.rb +357 -169
- data/lib/couchbase/options.rb +75 -3
- data/lib/couchbase/scope.rb +102 -0
- data/lib/couchbase/utils/time.rb +4 -0
- data/lib/couchbase/version.rb +6 -6
- metadata +50 -7
@@ -17,14 +17,18 @@
|
|
17
17
|
|
18
18
|
#pragma once
|
19
19
|
|
20
|
+
#include <functional>
|
21
|
+
#include <utility>
|
22
|
+
|
20
23
|
#include <platform/uuid.h>
|
21
24
|
|
22
25
|
#include <io/mcbp_session.hxx>
|
23
26
|
#include <io/retry_orchestrator.hxx>
|
24
27
|
|
25
28
|
#include <protocol/cmd_get_collection_id.hxx>
|
26
|
-
|
27
|
-
#include <
|
29
|
+
|
30
|
+
#include <tracing/request_tracer.hxx>
|
31
|
+
#include <metrics/meter.hxx>
|
28
32
|
|
29
33
|
namespace couchbase::operations
|
30
34
|
{
|
@@ -44,6 +48,7 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
|
|
44
48
|
mcbp_command_handler handler_{};
|
45
49
|
std::shared_ptr<Manager> manager_{};
|
46
50
|
std::string id_;
|
51
|
+
tracing::request_span* span_{ nullptr };
|
47
52
|
|
48
53
|
mcbp_command(asio::io_context& ctx, std::shared_ptr<Manager> manager, Request req)
|
49
54
|
: deadline(ctx)
|
@@ -56,7 +61,11 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
|
|
56
61
|
|
57
62
|
void start(mcbp_command_handler&& handler)
|
58
63
|
{
|
59
|
-
|
64
|
+
span_ = manager_->tracer()->start_span(tracing::span_name_for_mcbp_command(encoded_request_type::body_type::opcode), nullptr);
|
65
|
+
span_->add_tag(tracing::attributes::service, tracing::service::key_value);
|
66
|
+
span_->add_tag(tracing::attributes::instance, request.id.bucket);
|
67
|
+
|
68
|
+
handler_ = std::move(handler);
|
60
69
|
deadline.expires_after(request.timeout);
|
61
70
|
deadline.async_wait([self = this->shared_from_this()](std::error_code ec) {
|
62
71
|
if (ec == asio::error::operation_aborted) {
|
@@ -73,14 +82,21 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
|
|
73
82
|
handler_ = nullptr;
|
74
83
|
}
|
75
84
|
}
|
76
|
-
invoke_handler(
|
77
|
-
: error::common_errc::ambiguous_timeout));
|
85
|
+
invoke_handler(request.retries.idempotent ? error::common_errc::unambiguous_timeout : error::common_errc::ambiguous_timeout);
|
78
86
|
retry_backoff.cancel();
|
79
87
|
deadline.cancel();
|
80
88
|
}
|
81
89
|
|
82
90
|
void invoke_handler(std::error_code ec, std::optional<io::mcbp_message> msg = {})
|
83
91
|
{
|
92
|
+
if (span_) {
|
93
|
+
if (msg) {
|
94
|
+
auto server_duration_us = static_cast<std::uint64_t>(protocol::parse_server_duration_us(msg.value()));
|
95
|
+
span_->add_tag(tracing::attributes::server_duration, server_duration_us);
|
96
|
+
}
|
97
|
+
span_->end();
|
98
|
+
span_ = nullptr;
|
99
|
+
}
|
84
100
|
if (handler_) {
|
85
101
|
handler_(ec, std::move(msg));
|
86
102
|
}
|
@@ -100,9 +116,9 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
|
|
100
116
|
req.data(session_->supports_feature(protocol::hello_feature::snappy)),
|
101
117
|
[self = this->shared_from_this()](std::error_code ec, io::retry_reason /* reason */, io::mcbp_message&& msg) mutable {
|
102
118
|
if (ec == asio::error::operation_aborted) {
|
103
|
-
return self->invoke_handler(
|
119
|
+
return self->invoke_handler(error::common_errc::ambiguous_timeout);
|
104
120
|
}
|
105
|
-
if (ec ==
|
121
|
+
if (ec == error::common_errc::collection_not_found) {
|
106
122
|
if (self->request.id.collection_uid) {
|
107
123
|
return self->invoke_handler(ec);
|
108
124
|
}
|
@@ -111,7 +127,7 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
|
|
111
127
|
if (ec) {
|
112
128
|
return self->invoke_handler(ec);
|
113
129
|
}
|
114
|
-
protocol::client_response<protocol::get_collection_id_response_body> resp(msg);
|
130
|
+
protocol::client_response<protocol::get_collection_id_response_body> resp(std::move(msg));
|
115
131
|
self->session_->update_collection_uid(self->request.id.collection, resp.body().collection_uid());
|
116
132
|
self->request.id.collection_uid = resp.body().collection_uid();
|
117
133
|
return self->send();
|
@@ -130,8 +146,8 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
|
|
130
146
|
std::chrono::duration_cast<std::chrono::milliseconds>(time_left).count(),
|
131
147
|
id_);
|
132
148
|
if (time_left < backoff) {
|
133
|
-
return invoke_handler(
|
134
|
-
|
149
|
+
return invoke_handler(make_error_code(request.retries.idempotent ? error::common_errc::unambiguous_timeout
|
150
|
+
: error::common_errc::ambiguous_timeout));
|
135
151
|
}
|
136
152
|
retry_backoff.expires_after(backoff);
|
137
153
|
retry_backoff.async_wait([self = this->shared_from_this()](std::error_code ec) mutable {
|
@@ -146,6 +162,7 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
|
|
146
162
|
{
|
147
163
|
opaque_ = session_->next_opaque();
|
148
164
|
request.opaque = *opaque_;
|
165
|
+
span_->add_tag(tracing::attributes::operation_id, fmt::format("0x{:x}", request.opaque));
|
149
166
|
if (request.id.use_collections && !request.id.collection_uid) {
|
150
167
|
if (session_->supports_feature(protocol::hello_feature::collections)) {
|
151
168
|
auto collection_id = session_->get_collection_uid(request.id.collection);
|
@@ -163,26 +180,38 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
|
|
163
180
|
}
|
164
181
|
} else {
|
165
182
|
if (!request.id.collection.empty() && request.id.collection != "_default._default") {
|
166
|
-
return invoke_handler(
|
183
|
+
return invoke_handler(error::common_errc::unsupported_operation);
|
167
184
|
}
|
168
185
|
}
|
169
186
|
}
|
170
|
-
|
171
|
-
if (
|
172
|
-
return invoke_handler(
|
187
|
+
|
188
|
+
if (auto ec = request.encode_to(encoded, session_->context()); ec) {
|
189
|
+
return invoke_handler(ec);
|
173
190
|
}
|
174
191
|
|
175
192
|
session_->write_and_subscribe(
|
176
193
|
request.opaque,
|
177
194
|
encoded.data(session_->supports_feature(protocol::hello_feature::snappy)),
|
178
|
-
[self = this->shared_from_this()
|
195
|
+
[self = this->shared_from_this(),
|
196
|
+
start = std::chrono::steady_clock::now()](std::error_code ec, io::retry_reason reason, io::mcbp_message&& msg) mutable {
|
197
|
+
static std::string meter_name = "db.couchbase.operations";
|
198
|
+
static std::map<std::string, std::string> tags = {
|
199
|
+
{ "db.couchbase.service", "kv" },
|
200
|
+
{ "db.operation", fmt::format("{}", encoded_request_type::body_type::opcode) },
|
201
|
+
};
|
202
|
+
self->manager_->meter()
|
203
|
+
->get_value_recorder(meter_name, tags)
|
204
|
+
->record_value(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count());
|
205
|
+
|
179
206
|
self->retry_backoff.cancel();
|
180
207
|
if (ec == asio::error::operation_aborted) {
|
181
|
-
|
182
|
-
|
208
|
+
self->span_->add_tag(tracing::attributes::orphan, "aborted");
|
209
|
+
return self->invoke_handler(make_error_code(self->request.retries.idempotent ? error::common_errc::unambiguous_timeout
|
210
|
+
: error::common_errc::ambiguous_timeout));
|
183
211
|
}
|
184
|
-
if (ec ==
|
212
|
+
if (ec == error::common_errc::request_canceled) {
|
185
213
|
if (reason == io::retry_reason::do_not_retry) {
|
214
|
+
self->span_->add_tag(tracing::attributes::orphan, "canceled");
|
186
215
|
return self->invoke_handler(ec);
|
187
216
|
}
|
188
217
|
return io::retry_orchestrator::maybe_retry(self->manager_, self, reason, ec);
|
@@ -190,7 +219,7 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
|
|
190
219
|
protocol::status status = protocol::status::invalid;
|
191
220
|
std::optional<error_map::error_info> error_code{};
|
192
221
|
if (protocol::is_valid_status(msg.header.status())) {
|
193
|
-
status =
|
222
|
+
status = protocol::status(msg.header.status());
|
194
223
|
} else {
|
195
224
|
error_code = self->session_->decode_error_code(msg.header.status());
|
196
225
|
}
|
@@ -242,6 +271,9 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
|
|
242
271
|
return;
|
243
272
|
}
|
244
273
|
session_ = std::move(session);
|
274
|
+
span_->add_tag(tracing::attributes::remote_socket, session_->remote_address());
|
275
|
+
span_->add_tag(tracing::attributes::local_socket, session_->local_address());
|
276
|
+
span_->add_tag(tracing::attributes::local_id, session_->id());
|
245
277
|
send();
|
246
278
|
}
|
247
279
|
};
|
@@ -28,7 +28,7 @@ struct mcbp_context {
|
|
28
28
|
const std::optional<configuration>& config;
|
29
29
|
const std::vector<protocol::hello_feature>& supported_features;
|
30
30
|
|
31
|
-
[[nodiscard]] bool supports_feature(protocol::hello_feature feature)
|
31
|
+
[[nodiscard]] bool supports_feature(protocol::hello_feature feature) const
|
32
32
|
{
|
33
33
|
return std::find(supported_features.begin(), supported_features.end(), feature) != supported_features.end();
|
34
34
|
}
|
@@ -28,7 +28,7 @@
|
|
28
28
|
namespace couchbase::io
|
29
29
|
{
|
30
30
|
struct mcbp_parser {
|
31
|
-
enum result { ok, need_data, failure };
|
31
|
+
enum class result { ok, need_data, failure };
|
32
32
|
|
33
33
|
template<typename Iterator>
|
34
34
|
void feed(Iterator begin, Iterator end)
|
@@ -46,12 +46,12 @@ struct mcbp_parser {
|
|
46
46
|
{
|
47
47
|
static const size_t header_size = 24;
|
48
48
|
if (buf.size() < header_size) {
|
49
|
-
return need_data;
|
49
|
+
return result::need_data;
|
50
50
|
}
|
51
51
|
std::memcpy(&msg.header, buf.data(), header_size);
|
52
52
|
uint32_t body_size = ntohl(msg.header.bodylen);
|
53
53
|
if (body_size > 0 && buf.size() - header_size < body_size) {
|
54
|
-
return need_data;
|
54
|
+
return result::need_data;
|
55
55
|
}
|
56
56
|
msg.body.clear();
|
57
57
|
msg.body.reserve(body_size);
|
@@ -93,7 +93,7 @@ struct mcbp_parser {
|
|
93
93
|
spdlog::to_hex(buf));
|
94
94
|
reset();
|
95
95
|
}
|
96
|
-
return ok;
|
96
|
+
return result::ok;
|
97
97
|
}
|
98
98
|
|
99
99
|
std::vector<std::uint8_t> buf;
|
@@ -71,8 +71,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
71
71
|
[[nodiscard]] std::optional<std::uint32_t> get(const std::string& path)
|
72
72
|
{
|
73
73
|
Expects(!path.empty());
|
74
|
-
auto ptr = cid_map_.find(path);
|
75
|
-
if (ptr != cid_map_.end()) {
|
74
|
+
if (auto ptr = cid_map_.find(path); ptr != cid_map_.end()) {
|
76
75
|
return ptr->second;
|
77
76
|
}
|
78
77
|
return {};
|
@@ -124,8 +123,8 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
124
123
|
|
125
124
|
explicit bootstrap_handler(std::shared_ptr<mcbp_session> session)
|
126
125
|
: session_(session)
|
127
|
-
, sasl_([origin = session_->origin_]()
|
128
|
-
[origin = session_->origin_]()
|
126
|
+
, sasl_([origin = session_->origin_]() { return origin.username(); },
|
127
|
+
[origin = session_->origin_]() { return origin.password(); },
|
129
128
|
session_->origin_.credentials().allowed_sasl_mechanisms)
|
130
129
|
{
|
131
130
|
tao::json::value user_agent{
|
@@ -156,9 +155,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
156
155
|
session_->write(list_req.data());
|
157
156
|
|
158
157
|
protocol::client_request<protocol::sasl_auth_request_body> auth_req;
|
159
|
-
|
160
|
-
std::string_view sasl_payload;
|
161
|
-
std::tie(sasl_code, sasl_payload) = sasl_.start();
|
158
|
+
auto [sasl_code, sasl_payload] = sasl_.start();
|
162
159
|
auth_req.opaque(session_->next_opaque());
|
163
160
|
auth_req.body().mechanism(sasl_.get_name());
|
164
161
|
auth_req.body().sasl_data(sasl_payload);
|
@@ -200,10 +197,9 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
200
197
|
return;
|
201
198
|
}
|
202
199
|
Expects(protocol::is_valid_client_opcode(msg.header.opcode));
|
203
|
-
auto opcode =
|
204
|
-
switch (opcode) {
|
200
|
+
switch (auto opcode = protocol::client_opcode(msg.header.opcode)) {
|
205
201
|
case protocol::client_opcode::hello: {
|
206
|
-
protocol::client_response<protocol::hello_response_body> resp(msg);
|
202
|
+
protocol::client_response<protocol::hello_response_body> resp(std::move(msg));
|
207
203
|
if (resp.status() == protocol::status::success) {
|
208
204
|
session_->supported_features_ = resp.body().supported_features();
|
209
205
|
spdlog::debug("{} supported_features=[{}]", session_->log_prefix_, fmt::join(session_->supported_features_, ", "));
|
@@ -216,28 +212,26 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
216
212
|
session_->log_prefix_,
|
217
213
|
resp.error_message(),
|
218
214
|
resp.opaque());
|
219
|
-
return complete(
|
215
|
+
return complete(error::network_errc::handshake_failure);
|
220
216
|
}
|
221
217
|
} break;
|
222
218
|
case protocol::client_opcode::sasl_list_mechs: {
|
223
|
-
protocol::client_response<protocol::sasl_list_mechs_response_body> resp(msg);
|
219
|
+
protocol::client_response<protocol::sasl_list_mechs_response_body> resp(std::move(msg));
|
224
220
|
if (resp.status() != protocol::status::success) {
|
225
221
|
spdlog::warn("{} unexpected message status during bootstrap: {} (opaque={})",
|
226
222
|
session_->log_prefix_,
|
227
223
|
resp.error_message(),
|
228
224
|
resp.opaque());
|
229
|
-
return complete(
|
225
|
+
return complete(error::common_errc::authentication_failure);
|
230
226
|
}
|
231
227
|
} break;
|
232
228
|
case protocol::client_opcode::sasl_auth: {
|
233
|
-
protocol::client_response<protocol::sasl_auth_response_body> resp(msg);
|
229
|
+
protocol::client_response<protocol::sasl_auth_response_body> resp(std::move(msg));
|
234
230
|
if (resp.status() == protocol::status::success) {
|
235
231
|
return auth_success();
|
236
232
|
}
|
237
233
|
if (resp.status() == protocol::status::auth_continue) {
|
238
|
-
|
239
|
-
std::string_view sasl_payload;
|
240
|
-
std::tie(sasl_code, sasl_payload) = sasl_.step(resp.body().value());
|
234
|
+
auto [sasl_code, sasl_payload] = sasl_.step(resp.body().value());
|
241
235
|
if (sasl_code == sasl::error::OK) {
|
242
236
|
return auth_success();
|
243
237
|
}
|
@@ -250,25 +244,25 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
250
244
|
} else {
|
251
245
|
spdlog::error(
|
252
246
|
"{} unable to authenticate: (sasl_code={}, opaque={})", session_->log_prefix_, sasl_code, resp.opaque());
|
253
|
-
return complete(
|
247
|
+
return complete(error::common_errc::authentication_failure);
|
254
248
|
}
|
255
249
|
} else {
|
256
250
|
spdlog::warn("{} unexpected message status during bootstrap: {} (opaque={})",
|
257
251
|
session_->log_prefix_,
|
258
252
|
resp.error_message(),
|
259
253
|
resp.opaque());
|
260
|
-
return complete(
|
254
|
+
return complete(error::common_errc::authentication_failure);
|
261
255
|
}
|
262
256
|
} break;
|
263
257
|
case protocol::client_opcode::sasl_step: {
|
264
|
-
protocol::client_response<protocol::sasl_step_response_body> resp(msg);
|
258
|
+
protocol::client_response<protocol::sasl_step_response_body> resp(std::move(msg));
|
265
259
|
if (resp.status() == protocol::status::success) {
|
266
260
|
return auth_success();
|
267
261
|
}
|
268
|
-
return complete(
|
262
|
+
return complete(error::common_errc::authentication_failure);
|
269
263
|
}
|
270
264
|
case protocol::client_opcode::get_error_map: {
|
271
|
-
protocol::client_response<protocol::get_error_map_response_body> resp(msg);
|
265
|
+
protocol::client_response<protocol::get_error_map_response_body> resp(std::move(msg));
|
272
266
|
if (resp.status() == protocol::status::success) {
|
273
267
|
session_->error_map_.emplace(resp.body().errmap());
|
274
268
|
} else {
|
@@ -277,11 +271,11 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
277
271
|
resp.error_message(),
|
278
272
|
resp.opaque(),
|
279
273
|
spdlog::to_hex(msg.header_data()));
|
280
|
-
return complete(
|
274
|
+
return complete(error::network_errc::protocol_error);
|
281
275
|
}
|
282
276
|
} break;
|
283
277
|
case protocol::client_opcode::select_bucket: {
|
284
|
-
protocol::client_response<protocol::select_bucket_response_body> resp(msg);
|
278
|
+
protocol::client_response<protocol::select_bucket_response_body> resp(std::move(msg));
|
285
279
|
if (resp.status() == protocol::status::success) {
|
286
280
|
spdlog::debug("{} selected bucket: {}", session_->log_prefix_, session_->bucket_name_.value_or(""));
|
287
281
|
session_->bucket_selected_ = true;
|
@@ -291,24 +285,24 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
291
285
|
opcode,
|
292
286
|
resp.status(),
|
293
287
|
resp.opaque());
|
294
|
-
return complete(
|
288
|
+
return complete(error::network_errc::configuration_not_available);
|
295
289
|
} else if (resp.status() == protocol::status::no_access) {
|
296
290
|
spdlog::debug("{} unable to select bucket: {}, probably the bucket does not exist",
|
297
291
|
session_->log_prefix_,
|
298
292
|
session_->bucket_name_.value_or(""));
|
299
293
|
session_->bucket_selected_ = false;
|
300
|
-
return complete(
|
294
|
+
return complete(error::common_errc::bucket_not_found);
|
301
295
|
} else {
|
302
296
|
spdlog::warn("{} unexpected message status during bootstrap: {} (opaque={}, {:n})",
|
303
297
|
session_->log_prefix_,
|
304
298
|
resp.error_message(),
|
305
299
|
resp.opaque(),
|
306
300
|
spdlog::to_hex(msg.header_data()));
|
307
|
-
return complete(
|
301
|
+
return complete(error::common_errc::bucket_not_found);
|
308
302
|
}
|
309
303
|
} break;
|
310
304
|
case protocol::client_opcode::get_cluster_config: {
|
311
|
-
protocol::client_response<protocol::get_cluster_config_response_body> resp(msg);
|
305
|
+
protocol::client_response<protocol::get_cluster_config_response_body> resp(std::move(msg));
|
312
306
|
if (resp.status() == protocol::status::success) {
|
313
307
|
session_->update_configuration(resp.body().config());
|
314
308
|
complete({});
|
@@ -318,7 +312,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
318
312
|
opcode,
|
319
313
|
resp.status(),
|
320
314
|
resp.opaque());
|
321
|
-
return complete(
|
315
|
+
return complete(error::network_errc::configuration_not_available);
|
322
316
|
} else if (resp.status() == protocol::status::no_bucket && !session_->bucket_name_) {
|
323
317
|
// bucket-less session, but the server wants bucket
|
324
318
|
session_->supports_gcccp_ = false;
|
@@ -333,12 +327,12 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
333
327
|
resp.error_message(),
|
334
328
|
resp.opaque(),
|
335
329
|
spdlog::to_hex(msg.header_data()));
|
336
|
-
return complete(
|
330
|
+
return complete(error::network_errc::protocol_error);
|
337
331
|
}
|
338
332
|
} break;
|
339
333
|
default:
|
340
334
|
spdlog::warn("{} unexpected message during bootstrap: {}", session_->log_prefix_, opcode);
|
341
|
-
return complete(
|
335
|
+
return complete(error::network_errc::protocol_error);
|
342
336
|
}
|
343
337
|
}
|
344
338
|
};
|
@@ -378,13 +372,13 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
378
372
|
return;
|
379
373
|
}
|
380
374
|
Expects(protocol::is_valid_magic(msg.header.magic));
|
381
|
-
switch (auto magic =
|
375
|
+
switch (auto magic = protocol::magic(msg.header.magic)) {
|
382
376
|
case protocol::magic::client_response:
|
383
377
|
case protocol::magic::alt_client_response:
|
384
378
|
Expects(protocol::is_valid_client_opcode(msg.header.opcode));
|
385
|
-
switch (auto opcode =
|
379
|
+
switch (auto opcode = protocol::client_opcode(msg.header.opcode)) {
|
386
380
|
case protocol::client_opcode::get_cluster_config: {
|
387
|
-
protocol::client_response<protocol::get_cluster_config_response_body> resp(msg);
|
381
|
+
protocol::client_response<protocol::get_cluster_config_response_body> resp(std::move(msg));
|
388
382
|
if (resp.status() == protocol::status::success) {
|
389
383
|
if (session_) {
|
390
384
|
session_->update_configuration(resp.body().config());
|
@@ -570,7 +564,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
570
564
|
|
571
565
|
[[nodiscard]] diag::endpoint_diag_info diag_info() const
|
572
566
|
{
|
573
|
-
return { service_type::
|
567
|
+
return { service_type::key_value,
|
574
568
|
id_,
|
575
569
|
last_active_.time_since_epoch().count() == 0 ? std::nullopt
|
576
570
|
: std::make_optional(std::chrono::duration_cast<std::chrono::microseconds>(
|
@@ -597,7 +591,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
597
591
|
error.emplace(fmt::format("code={}, message={}, reason={}", ec.value(), ec.message(), reason));
|
598
592
|
}
|
599
593
|
handler(diag::endpoint_ping_info{
|
600
|
-
service_type::
|
594
|
+
service_type::key_value,
|
601
595
|
self->id_,
|
602
596
|
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start),
|
603
597
|
self->remote_address(),
|
@@ -623,7 +617,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
623
617
|
return;
|
624
618
|
}
|
625
619
|
spdlog::warn("{} unable to bootstrap in time", self->log_prefix_);
|
626
|
-
self->bootstrap_handler_(
|
620
|
+
self->bootstrap_handler_(error::common_errc::unambiguous_timeout, {});
|
627
621
|
self->bootstrap_handler_ = nullptr;
|
628
622
|
self->stop(retry_reason::socket_closed_while_in_flight);
|
629
623
|
});
|
@@ -703,7 +697,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
703
697
|
if (stream_->is_open()) {
|
704
698
|
stream_->close();
|
705
699
|
}
|
706
|
-
|
700
|
+
std::error_code ec = error::common_errc::request_canceled;
|
707
701
|
if (!bootstrapped_ && bootstrap_handler_) {
|
708
702
|
bootstrap_handler_(ec, {});
|
709
703
|
bootstrap_handler_ = nullptr;
|
@@ -713,11 +707,10 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
713
707
|
}
|
714
708
|
{
|
715
709
|
std::scoped_lock lock(command_handlers_mutex_);
|
716
|
-
for (auto& handler : command_handlers_) {
|
717
|
-
if (handler
|
718
|
-
spdlog::debug(
|
719
|
-
|
720
|
-
auto fun = std::move(handler.second);
|
710
|
+
for (auto& [opaque, handler] : command_handlers_) {
|
711
|
+
if (handler) {
|
712
|
+
spdlog::debug("{} MCBP cancel operation during session close, opaque={}, ec={}", log_prefix_, opaque, ec.message());
|
713
|
+
auto fun = std::move(handler);
|
721
714
|
fun(ec, reason, {});
|
722
715
|
}
|
723
716
|
}
|
@@ -767,12 +760,12 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
767
760
|
{
|
768
761
|
if (stopped_) {
|
769
762
|
spdlog::warn("{} MCBP cancel operation, while trying to write to closed session, opaque={}", log_prefix_, opaque);
|
770
|
-
handler(
|
763
|
+
handler(error::common_errc::request_canceled, retry_reason::socket_closed_while_in_flight, {});
|
771
764
|
return;
|
772
765
|
}
|
773
766
|
{
|
774
767
|
std::scoped_lock lock(command_handlers_mutex_);
|
775
|
-
command_handlers_.
|
768
|
+
command_handlers_.try_emplace(opaque, std::move(handler));
|
776
769
|
}
|
777
770
|
if (bootstrapped_ && stream_->is_open()) {
|
778
771
|
write_and_flush(data);
|
@@ -789,8 +782,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
789
782
|
return false;
|
790
783
|
}
|
791
784
|
command_handlers_mutex_.lock();
|
792
|
-
auto handler = command_handlers_.find(opaque);
|
793
|
-
if (handler != command_handlers_.end()) {
|
785
|
+
if (auto handler = command_handlers_.find(opaque); handler != command_handlers_.end()) {
|
794
786
|
spdlog::debug("{} MCBP cancel operation, opaque={}, ec={} ({})", log_prefix_, opaque, ec.value(), ec.message());
|
795
787
|
if (handler->second) {
|
796
788
|
auto fun = std::move(handler->second);
|
@@ -850,9 +842,9 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
850
842
|
return ++opaque_;
|
851
843
|
}
|
852
844
|
|
853
|
-
std::error_code map_status_code(protocol::client_opcode opcode, uint16_t status)
|
845
|
+
[[nodiscard]] std::error_code map_status_code(protocol::client_opcode opcode, uint16_t status) const
|
854
846
|
{
|
855
|
-
switch (
|
847
|
+
switch (protocol::status(status)) {
|
856
848
|
case protocol::status::success:
|
857
849
|
case protocol::status::subdoc_multi_path_failure:
|
858
850
|
case protocol::status::subdoc_success_deleted:
|
@@ -861,115 +853,115 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
861
853
|
|
862
854
|
case protocol::status::not_found:
|
863
855
|
case protocol::status::not_stored:
|
864
|
-
return
|
856
|
+
return error::key_value_errc::document_not_found;
|
865
857
|
|
866
858
|
case protocol::status::exists:
|
867
859
|
if (opcode == protocol::client_opcode::insert) {
|
868
|
-
return
|
860
|
+
return error::key_value_errc::document_exists;
|
869
861
|
}
|
870
|
-
return
|
862
|
+
return error::common_errc::cas_mismatch;
|
871
863
|
|
872
864
|
case protocol::status::too_big:
|
873
|
-
return
|
865
|
+
return error::key_value_errc::value_too_large;
|
874
866
|
|
875
867
|
case protocol::status::invalid:
|
876
868
|
case protocol::status::xattr_invalid:
|
877
869
|
case protocol::status::subdoc_invalid_combo:
|
878
|
-
return
|
870
|
+
return error::common_errc::invalid_argument;
|
879
871
|
|
880
872
|
case protocol::status::delta_bad_value:
|
881
|
-
return
|
873
|
+
return error::key_value_errc::delta_invalid;
|
882
874
|
|
883
875
|
case protocol::status::no_bucket:
|
884
|
-
return
|
876
|
+
return error::common_errc::bucket_not_found;
|
885
877
|
|
886
878
|
case protocol::status::locked:
|
887
|
-
return
|
879
|
+
return error::key_value_errc::document_locked;
|
888
880
|
|
889
881
|
case protocol::status::auth_stale:
|
890
882
|
case protocol::status::auth_error:
|
891
883
|
case protocol::status::no_access:
|
892
|
-
return
|
884
|
+
return error::common_errc::authentication_failure;
|
893
885
|
|
894
886
|
case protocol::status::not_supported:
|
895
887
|
case protocol::status::unknown_command:
|
896
|
-
return
|
888
|
+
return error::common_errc::unsupported_operation;
|
897
889
|
|
898
890
|
case protocol::status::internal:
|
899
|
-
return
|
891
|
+
return error::common_errc::internal_server_failure;
|
900
892
|
|
901
893
|
case protocol::status::busy:
|
902
894
|
case protocol::status::temporary_failure:
|
903
895
|
case protocol::status::no_memory:
|
904
896
|
case protocol::status::not_initialized:
|
905
|
-
return
|
897
|
+
return error::common_errc::temporary_failure;
|
906
898
|
|
907
899
|
case protocol::status::unknown_collection:
|
908
|
-
return
|
900
|
+
return error::common_errc::collection_not_found;
|
909
901
|
|
910
902
|
case protocol::status::unknown_scope:
|
911
|
-
return
|
903
|
+
return error::common_errc::scope_not_found;
|
912
904
|
|
913
905
|
case protocol::status::durability_invalid_level:
|
914
|
-
return
|
906
|
+
return error::key_value_errc::durability_level_not_available;
|
915
907
|
|
916
908
|
case protocol::status::durability_impossible:
|
917
|
-
return
|
909
|
+
return error::key_value_errc::durability_impossible;
|
918
910
|
|
919
911
|
case protocol::status::sync_write_in_progress:
|
920
|
-
return
|
912
|
+
return error::key_value_errc::durable_write_in_progress;
|
921
913
|
|
922
914
|
case protocol::status::sync_write_ambiguous:
|
923
|
-
return
|
915
|
+
return error::key_value_errc::durability_ambiguous;
|
924
916
|
|
925
917
|
case protocol::status::sync_write_re_commit_in_progress:
|
926
|
-
return
|
918
|
+
return error::key_value_errc::durable_write_re_commit_in_progress;
|
927
919
|
|
928
920
|
case protocol::status::subdoc_path_not_found:
|
929
|
-
return
|
921
|
+
return error::key_value_errc::path_not_found;
|
930
922
|
|
931
923
|
case protocol::status::subdoc_path_mismatch:
|
932
|
-
return
|
924
|
+
return error::key_value_errc::path_mismatch;
|
933
925
|
|
934
926
|
case protocol::status::subdoc_path_invalid:
|
935
|
-
return
|
927
|
+
return error::key_value_errc::path_invalid;
|
936
928
|
|
937
929
|
case protocol::status::subdoc_path_too_big:
|
938
|
-
return
|
930
|
+
return error::key_value_errc::path_too_big;
|
939
931
|
|
940
932
|
case protocol::status::subdoc_doc_too_deep:
|
941
|
-
return
|
933
|
+
return error::key_value_errc::value_too_deep;
|
942
934
|
|
943
935
|
case protocol::status::subdoc_value_cannot_insert:
|
944
|
-
return
|
936
|
+
return error::key_value_errc::value_invalid;
|
945
937
|
|
946
938
|
case protocol::status::subdoc_doc_not_json:
|
947
|
-
return
|
939
|
+
return error::key_value_errc::document_not_json;
|
948
940
|
|
949
941
|
case protocol::status::subdoc_num_range_error:
|
950
|
-
return
|
942
|
+
return error::key_value_errc::number_too_big;
|
951
943
|
|
952
944
|
case protocol::status::subdoc_delta_invalid:
|
953
|
-
return
|
945
|
+
return error::key_value_errc::delta_invalid;
|
954
946
|
|
955
947
|
case protocol::status::subdoc_path_exists:
|
956
|
-
return
|
948
|
+
return error::key_value_errc::path_exists;
|
957
949
|
|
958
950
|
case protocol::status::subdoc_value_too_deep:
|
959
|
-
return
|
951
|
+
return error::key_value_errc::value_too_deep;
|
960
952
|
|
961
953
|
case protocol::status::subdoc_xattr_invalid_flag_combo:
|
962
954
|
case protocol::status::subdoc_xattr_invalid_key_combo:
|
963
|
-
return
|
955
|
+
return error::key_value_errc::xattr_invalid_key_combo;
|
964
956
|
|
965
957
|
case protocol::status::subdoc_xattr_unknown_macro:
|
966
|
-
return
|
958
|
+
return error::key_value_errc::xattr_unknown_macro;
|
967
959
|
|
968
960
|
case protocol::status::subdoc_xattr_unknown_vattr:
|
969
|
-
return
|
961
|
+
return error::key_value_errc::xattr_unknown_virtual_attribute;
|
970
962
|
|
971
963
|
case protocol::status::subdoc_xattr_cannot_modify_vattr:
|
972
|
-
return
|
964
|
+
return error::key_value_errc::xattr_cannot_modify_virtual_attribute;
|
973
965
|
|
974
966
|
case protocol::status::subdoc_invalid_xattr_order:
|
975
967
|
case protocol::status::not_my_vbucket:
|
@@ -985,7 +977,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
985
977
|
}
|
986
978
|
// FIXME: use error map here
|
987
979
|
spdlog::warn("{} unknown status code: {} (opcode={})", log_prefix_, protocol::status_to_string(status), opcode);
|
988
|
-
return
|
980
|
+
return error::network_errc::protocol_error;
|
989
981
|
}
|
990
982
|
|
991
983
|
std::optional<error_map::error_info> decode_error_code(std::uint16_t code)
|
@@ -1014,15 +1006,13 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
1014
1006
|
spdlog::debug("{} received a configuration with a different number of vbuckets, ignoring", log_prefix_);
|
1015
1007
|
return;
|
1016
1008
|
}
|
1017
|
-
if (
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
return;
|
1025
|
-
}
|
1009
|
+
if (config == config_) {
|
1010
|
+
spdlog::trace("{} received a configuration with identical revision (rev={}), ignoring", log_prefix_, config.rev_str());
|
1011
|
+
return;
|
1012
|
+
}
|
1013
|
+
if (config < config_) {
|
1014
|
+
spdlog::debug("{} received a configuration with older revision, ignoring", log_prefix_);
|
1015
|
+
return;
|
1026
1016
|
}
|
1027
1017
|
}
|
1028
1018
|
bool this_node_found = false;
|
@@ -1046,7 +1036,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
1046
1036
|
}
|
1047
1037
|
config_.emplace(config);
|
1048
1038
|
spdlog::debug("{} received new configuration: {}", log_prefix_, config_.value());
|
1049
|
-
for (auto& listener : config_listeners_) {
|
1039
|
+
for (const auto& listener : config_listeners_) {
|
1050
1040
|
listener(*config_);
|
1051
1041
|
}
|
1052
1042
|
}
|
@@ -1059,7 +1049,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
1059
1049
|
Expects(msg.header.magic == static_cast<std::uint8_t>(protocol::magic::alt_client_response) ||
|
1060
1050
|
msg.header.magic == static_cast<std::uint8_t>(protocol::magic::client_response));
|
1061
1051
|
if (protocol::has_json_datatype(msg.header.datatype)) {
|
1062
|
-
auto magic =
|
1052
|
+
auto magic = protocol::magic(msg.header.magic);
|
1063
1053
|
uint8_t extras_size = msg.header.extlen;
|
1064
1054
|
uint8_t framing_extras_size = 0;
|
1065
1055
|
uint16_t key_size = htons(msg.header.keylen);
|
@@ -1073,7 +1063,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
1073
1063
|
auto config = protocol::parse_config(msg.body.begin() + offset, msg.body.end());
|
1074
1064
|
spdlog::debug("{} received not_my_vbucket status for {}, opaque={} with config rev={} in the payload",
|
1075
1065
|
log_prefix_,
|
1076
|
-
|
1066
|
+
protocol::client_opcode(msg.header.opcode),
|
1077
1067
|
msg.header.opaque,
|
1078
1068
|
config.rev_str());
|
1079
1069
|
update_configuration(std::move(config));
|
@@ -1097,10 +1087,10 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
1097
1087
|
private:
|
1098
1088
|
void invoke_bootstrap_handler(std::error_code ec)
|
1099
1089
|
{
|
1100
|
-
if (ec ==
|
1090
|
+
if (ec == error::network_errc::configuration_not_available) {
|
1101
1091
|
return initiate_bootstrap();
|
1102
1092
|
}
|
1103
|
-
if (retry_bootstrap_on_bucket_not_found_ && ec ==
|
1093
|
+
if (retry_bootstrap_on_bucket_not_found_ && ec == error::common_errc::bucket_not_found) {
|
1104
1094
|
spdlog::debug(R"({} server returned {} ({}), it must be transient condition, retrying)", log_prefix_, ec.value(), ec.message());
|
1105
1095
|
return initiate_bootstrap();
|
1106
1096
|
}
|
@@ -1241,7 +1231,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
1241
1231
|
for (;;) {
|
1242
1232
|
mcbp_message msg{};
|
1243
1233
|
switch (self->parser_.next(msg)) {
|
1244
|
-
case mcbp_parser::ok:
|
1234
|
+
case mcbp_parser::result::ok:
|
1245
1235
|
spdlog::trace(
|
1246
1236
|
"{} MCBP recv, opaque={}, {:n}", self->log_prefix_, msg.header.opaque, spdlog::to_hex(msg.header_data()));
|
1247
1237
|
SPDLOG_TRACE("{} MCBP recv, opaque={}{:a}{:a}",
|
@@ -1254,13 +1244,13 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
1254
1244
|
return;
|
1255
1245
|
}
|
1256
1246
|
break;
|
1257
|
-
case mcbp_parser::need_data:
|
1247
|
+
case mcbp_parser::result::need_data:
|
1258
1248
|
self->reading_ = false;
|
1259
1249
|
if (!self->stopped_ && self->stream_->is_open()) {
|
1260
1250
|
self->do_read();
|
1261
1251
|
}
|
1262
1252
|
return;
|
1263
|
-
case mcbp_parser::failure:
|
1253
|
+
case mcbp_parser::result::failure:
|
1264
1254
|
return self->stop(retry_reason::kv_temporary_failure);
|
1265
1255
|
}
|
1266
1256
|
}
|