couchbase 3.8.0 → 3.8.1
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/cache/extconf_include.rb +4 -4
- data/ext/cache/mozilla-ca-bundle.crt +3 -575
- data/ext/cache/mozilla-ca-bundle.sha256 +1 -1
- data/ext/couchbase/CMakeLists.txt +3 -1
- data/ext/couchbase/core/error_context/base_error_context.hxx +32 -0
- data/ext/couchbase/core/error_context/key_value.cxx +1 -0
- data/ext/couchbase/core/error_context/key_value.hxx +23 -0
- data/ext/couchbase/core/error_context/key_value_error_context.hxx +35 -0
- data/ext/couchbase/core/error_context/subdocument_error_context.hxx +41 -0
- data/ext/couchbase/core/impl/binary_collection.cxx +123 -88
- data/ext/couchbase/core/impl/collection.cxx +416 -189
- data/ext/couchbase/core/impl/error.cxx +29 -4
- data/ext/couchbase/core/impl/invoke_with_node_id.hxx +44 -0
- data/ext/couchbase/core/impl/node_id.cxx +110 -0
- data/ext/couchbase/core/impl/node_id.hxx +40 -0
- data/ext/couchbase/core/io/http_session_manager.hxx +97 -57
- data/ext/couchbase/core/operations/document_get_all_replicas.hxx +14 -4
- data/ext/couchbase/core/operations/document_get_projected.cxx +3 -4
- data/ext/couchbase/core/operations/document_lookup_in_all_replicas.hxx +4 -0
- data/ext/couchbase/core/operations/document_query.cxx +12 -12
- data/ext/couchbase/core/operations/management/collection_create.cxx +11 -11
- data/ext/couchbase/core/operations/management/collection_drop.cxx +11 -11
- data/ext/couchbase/core/operations/management/collection_update.cxx +11 -11
- data/ext/couchbase/core/operations/management/error_utils.cxx +9 -6
- data/ext/couchbase/core/operations/management/query_index_create.cxx +5 -4
- data/ext/couchbase/core/operations/management/query_index_drop.cxx +7 -6
- data/ext/couchbase/core/operations/management/scope_create.cxx +12 -13
- data/ext/couchbase/core/operations/management/scope_drop.cxx +8 -9
- data/ext/couchbase/core/topology/configuration.cxx +21 -0
- data/ext/couchbase/core/topology/configuration.hxx +28 -0
- data/ext/couchbase/core/utils/contains_string.cxx +61 -0
- data/ext/couchbase/core/utils/contains_string.hxx +26 -0
- data/ext/couchbase/couchbase/collection.hxx +73 -0
- data/ext/couchbase/couchbase/error.hxx +16 -0
- data/ext/couchbase/couchbase/node_id.hxx +123 -0
- data/ext/couchbase/couchbase/node_id_for_options.hxx +61 -0
- data/ext/couchbase/couchbase/node_ids_options.hxx +62 -0
- data/ext/couchbase/couchbase/result.hxx +42 -0
- data/ext/rcb_crud.cxx +2 -0
- data/ext/rcb_logger.cxx +15 -17
- data/lib/couchbase/datastructures/couchbase_list.rb +1 -0
- data/lib/couchbase/datastructures/couchbase_map.rb +1 -0
- data/lib/couchbase/datastructures/couchbase_queue.rb +1 -0
- data/lib/couchbase/datastructures/couchbase_set.rb +1 -0
- data/lib/couchbase/errors.rb +1 -1
- data/lib/couchbase/json_transcoder.rb +1 -1
- data/lib/couchbase/options.rb +2 -2
- data/lib/couchbase/protostellar/client.rb +0 -2
- data/lib/couchbase/protostellar/cluster.rb +4 -0
- data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_pb.rb +54 -0
- data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_services_pb.rb +51 -0
- data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +5 -24
- data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +16 -0
- data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +5 -24
- data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +16 -0
- data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +5 -24
- data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +18 -0
- data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +2 -23
- data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +23 -0
- data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +4 -25
- data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +10 -0
- data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +6 -25
- data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +18 -0
- data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_pb.rb +46 -0
- data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_services_pb.rb +56 -0
- data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +3 -26
- data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +47 -0
- data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +4 -26
- data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +10 -0
- data/lib/couchbase/protostellar/generated/routing/v2/routing_pb.rb +26 -0
- data/lib/couchbase/protostellar/generated/routing/v2/routing_services_pb.rb +43 -0
- data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +5 -26
- data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +11 -0
- data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +2 -23
- data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +2 -23
- data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +9 -0
- data/lib/couchbase/protostellar/request_generator/admin/collection.rb +4 -2
- data/lib/couchbase/protostellar/request_generator/admin/query.rb +2 -0
- data/lib/couchbase/protostellar/request_generator/kv.rb +1 -1
- data/lib/couchbase/protostellar/scope.rb +4 -0
- data/lib/couchbase/utils/observability.rb +10 -4
- data/lib/couchbase/version.rb +1 -1
- metadata +19 -7
- data/lib/couchbase/protostellar/generated/routing/v1/routing_pb.rb +0 -52
- data/lib/couchbase/protostellar/generated/routing/v1/routing_services_pb.rb +0 -30
|
@@ -24,13 +24,11 @@
|
|
|
24
24
|
#include <spdlog/fmt/bundled/core.h>
|
|
25
25
|
#include <tao/json/value.hpp>
|
|
26
26
|
|
|
27
|
-
#include <regex>
|
|
28
|
-
|
|
29
27
|
namespace couchbase::core::operations::management
|
|
30
28
|
{
|
|
31
29
|
auto
|
|
32
|
-
collection_drop_request::encode_to(encoded_request_type& encoded,
|
|
33
|
-
|
|
30
|
+
collection_drop_request::encode_to(encoded_request_type& encoded, http_context& /* context */) const
|
|
31
|
+
-> std::error_code
|
|
34
32
|
{
|
|
35
33
|
encoded.method = "DELETE";
|
|
36
34
|
encoded.path = fmt::format("/pools/default/buckets/{}/scopes/{}/collections/{}",
|
|
@@ -47,16 +45,18 @@ collection_drop_request::make_response(error_context::http&& ctx,
|
|
|
47
45
|
{
|
|
48
46
|
collection_drop_response response{ std::move(ctx) };
|
|
49
47
|
if (!response.ctx.ec) {
|
|
50
|
-
switch (encoded.status_code) {
|
|
48
|
+
switch (const auto& body = encoded.body.data(); encoded.status_code) {
|
|
51
49
|
case 400:
|
|
52
50
|
response.ctx.ec = errc::common::unsupported_operation;
|
|
53
51
|
break;
|
|
54
52
|
case 404: {
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
if (std::
|
|
53
|
+
const auto collection_prefix_pos = body.find("Collection with name ");
|
|
54
|
+
const auto scope_prefix_pos = body.find("Scope with name ");
|
|
55
|
+
if (collection_prefix_pos != std::string_view::npos &&
|
|
56
|
+
body.find(" is not found", collection_prefix_pos) != std::string_view::npos) {
|
|
58
57
|
response.ctx.ec = errc::common::collection_not_found;
|
|
59
|
-
} else if (std::
|
|
58
|
+
} else if (scope_prefix_pos != std::string_view::npos &&
|
|
59
|
+
body.find(" is not found", scope_prefix_pos) != std::string_view::npos) {
|
|
60
60
|
response.ctx.ec = errc::common::scope_not_found;
|
|
61
61
|
} else {
|
|
62
62
|
response.ctx.ec = errc::common::bucket_not_found;
|
|
@@ -65,7 +65,7 @@ collection_drop_request::make_response(error_context::http&& ctx,
|
|
|
65
65
|
case 200: {
|
|
66
66
|
tao::json::value payload{};
|
|
67
67
|
try {
|
|
68
|
-
payload = utils::json::parse(
|
|
68
|
+
payload = utils::json::parse(body);
|
|
69
69
|
} catch (const tao::pegtl::parse_error&) {
|
|
70
70
|
response.ctx.ec = errc::common::parsing_failure;
|
|
71
71
|
return response;
|
|
@@ -73,7 +73,7 @@ collection_drop_request::make_response(error_context::http&& ctx,
|
|
|
73
73
|
response.uid = std::stoull(payload.at("uid").get_string(), nullptr, 16);
|
|
74
74
|
} break;
|
|
75
75
|
default:
|
|
76
|
-
response.ctx.ec = extract_common_error_code(encoded.status_code,
|
|
76
|
+
response.ctx.ec = extract_common_error_code(encoded.status_code, body);
|
|
77
77
|
break;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -24,13 +24,11 @@
|
|
|
24
24
|
#include <spdlog/fmt/bundled/core.h>
|
|
25
25
|
#include <tao/json/value.hpp>
|
|
26
26
|
|
|
27
|
-
#include <regex>
|
|
28
|
-
|
|
29
27
|
namespace couchbase::core::operations::management
|
|
30
28
|
{
|
|
31
29
|
auto
|
|
32
|
-
collection_update_request::encode_to(encoded_request_type& encoded,
|
|
33
|
-
|
|
30
|
+
collection_update_request::encode_to(encoded_request_type& encoded, http_context& /*context*/) const
|
|
31
|
+
-> std::error_code
|
|
34
32
|
{
|
|
35
33
|
encoded.method = "PATCH";
|
|
36
34
|
encoded.path = fmt::format("/pools/default/buckets/{}/scopes/{}/collections/{}",
|
|
@@ -60,16 +58,18 @@ collection_update_request::make_response(error_context::http&& ctx,
|
|
|
60
58
|
{
|
|
61
59
|
collection_update_response response{ std::move(ctx) };
|
|
62
60
|
if (!response.ctx.ec) {
|
|
63
|
-
switch (encoded.status_code) {
|
|
61
|
+
switch (const auto& body = encoded.body.data(); encoded.status_code) {
|
|
64
62
|
case 400: {
|
|
65
63
|
response.ctx.ec = errc::common::invalid_argument;
|
|
66
64
|
} break;
|
|
67
65
|
case 404: {
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
if (std::
|
|
66
|
+
const auto collection_prefix_pos = body.find("Collection with name ");
|
|
67
|
+
const auto scope_prefix_pos = body.find("Scope with name ");
|
|
68
|
+
if (collection_prefix_pos != std::string_view::npos &&
|
|
69
|
+
body.find(" is not found", collection_prefix_pos) != std::string_view::npos) {
|
|
71
70
|
response.ctx.ec = errc::common::collection_not_found;
|
|
72
|
-
} else if (std::
|
|
71
|
+
} else if (scope_prefix_pos != std::string_view::npos &&
|
|
72
|
+
body.find(" is not found", scope_prefix_pos) != std::string_view::npos) {
|
|
73
73
|
response.ctx.ec = errc::common::scope_not_found;
|
|
74
74
|
} else {
|
|
75
75
|
response.ctx.ec = errc::common::bucket_not_found;
|
|
@@ -78,7 +78,7 @@ collection_update_request::make_response(error_context::http&& ctx,
|
|
|
78
78
|
case 200: {
|
|
79
79
|
tao::json::value payload{};
|
|
80
80
|
try {
|
|
81
|
-
payload = utils::json::parse(
|
|
81
|
+
payload = utils::json::parse(body);
|
|
82
82
|
} catch (const tao::pegtl::parse_error&) {
|
|
83
83
|
response.ctx.ec = errc::common::parsing_failure;
|
|
84
84
|
return response;
|
|
@@ -86,7 +86,7 @@ collection_update_request::make_response(error_context::http&& ctx,
|
|
|
86
86
|
response.uid = std::stoull(payload.at("uid").get_string(), nullptr, 16);
|
|
87
87
|
} break;
|
|
88
88
|
default:
|
|
89
|
-
response.ctx.ec = extract_common_error_code(encoded.status_code,
|
|
89
|
+
response.ctx.ec = extract_common_error_code(encoded.status_code, body);
|
|
90
90
|
break;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -16,12 +16,11 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
#include "error_utils.hxx"
|
|
19
|
+
#include "core/utils/contains_string.hxx"
|
|
19
20
|
#include "core/utils/json.hxx"
|
|
20
21
|
|
|
21
22
|
#include <tao/json/value.hpp>
|
|
22
23
|
|
|
23
|
-
#include <regex>
|
|
24
|
-
|
|
25
24
|
namespace couchbase::core::operations::management
|
|
26
25
|
{
|
|
27
26
|
|
|
@@ -143,12 +142,16 @@ translate_query_error_code(std::uint64_t error, const std::string& message, std:
|
|
|
143
142
|
{
|
|
144
143
|
switch (error) {
|
|
145
144
|
case 5000: /* IKey: "Internal Error" */
|
|
146
|
-
if (
|
|
145
|
+
if (utils::contains_string(message, "index", true) &&
|
|
146
|
+
utils::contains_string(message, "already exist", true)) {
|
|
147
147
|
return errc::common::index_exists;
|
|
148
|
-
}
|
|
149
|
-
|
|
148
|
+
}
|
|
149
|
+
if (utils::contains_string(message, "Index does not exist") ||
|
|
150
|
+
(utils::contains_string(message, "index", true) &&
|
|
151
|
+
utils::contains_string(message, "not found", true))) {
|
|
150
152
|
return errc::common::index_not_found;
|
|
151
|
-
}
|
|
153
|
+
}
|
|
154
|
+
if (message.find("Bucket Not Found") != std::string::npos) {
|
|
152
155
|
return errc::common::bucket_not_found;
|
|
153
156
|
}
|
|
154
157
|
break;
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
#include "query_index_create.hxx"
|
|
19
19
|
|
|
20
|
+
#include "core/utils/contains_string.hxx"
|
|
20
21
|
#include "core/utils/json.hxx"
|
|
21
22
|
#include "core/utils/keyspace.hxx"
|
|
22
23
|
#include "error_utils.hxx"
|
|
@@ -24,8 +25,6 @@
|
|
|
24
25
|
#include <spdlog/fmt/bundled/core.h>
|
|
25
26
|
#include <tao/json/value.hpp>
|
|
26
27
|
|
|
27
|
-
#include <regex>
|
|
28
|
-
|
|
29
28
|
namespace couchbase::core::operations::management
|
|
30
29
|
{
|
|
31
30
|
auto
|
|
@@ -118,13 +117,15 @@ query_index_create_request::make_response(error_context::http&& ctx,
|
|
|
118
117
|
error.message = entry.at("msg").get_string();
|
|
119
118
|
switch (error.code) {
|
|
120
119
|
case 5000: /* IKey: "Internal Error" */
|
|
121
|
-
|
|
120
|
+
{
|
|
121
|
+
if (utils::contains_string(error.message, "index", true) &&
|
|
122
|
+
utils::contains_string(error.message, "already exist", true)) {
|
|
122
123
|
index_already_exists = true;
|
|
123
124
|
}
|
|
124
125
|
if (error.message.find("Bucket Not Found") != std::string::npos) {
|
|
125
126
|
bucket_not_found = true;
|
|
126
127
|
}
|
|
127
|
-
|
|
128
|
+
} break;
|
|
128
129
|
|
|
129
130
|
case 12003: /* IKey: "datastore.couchbase.keyspace_not_found" */
|
|
130
131
|
if (error.message.find("missing_collection") != std::string::npos) {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
#include "query_index_drop.hxx"
|
|
19
19
|
|
|
20
|
+
#include "core/utils/contains_string.hxx"
|
|
20
21
|
#include "core/utils/json.hxx"
|
|
21
22
|
#include "core/utils/keyspace.hxx"
|
|
22
23
|
#include "error_utils.hxx"
|
|
@@ -24,13 +25,11 @@
|
|
|
24
25
|
#include <spdlog/fmt/bundled/core.h>
|
|
25
26
|
#include <tao/json/value.hpp>
|
|
26
27
|
|
|
27
|
-
#include <regex>
|
|
28
|
-
|
|
29
28
|
namespace couchbase::core::operations::management
|
|
30
29
|
{
|
|
31
30
|
auto
|
|
32
|
-
query_index_drop_request::encode_to(encoded_request_type& encoded,
|
|
33
|
-
|
|
31
|
+
query_index_drop_request::encode_to(encoded_request_type& encoded, http_context& /*context*/) const
|
|
32
|
+
-> std::error_code
|
|
34
33
|
{
|
|
35
34
|
if (!utils::check_query_management_request(*this)) {
|
|
36
35
|
return errc::common::invalid_argument;
|
|
@@ -87,10 +86,12 @@ query_index_drop_request::make_response(error_context::http&& ctx,
|
|
|
87
86
|
error.message = entry.at("msg").get_string();
|
|
88
87
|
switch (error.code) {
|
|
89
88
|
case 5000: /* IKey: "Internal Error" */
|
|
90
|
-
|
|
89
|
+
{
|
|
90
|
+
if (utils::contains_string(error.message, "index", true) &&
|
|
91
|
+
utils::contains_string(error.message, "not found", true)) {
|
|
91
92
|
index_not_found = true;
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
+
} break;
|
|
94
95
|
|
|
95
96
|
case 12003: /* IKey: "datastore.couchbase.keyspace_not_found" */
|
|
96
97
|
if (error.message.find("missing_collection") != std::string::npos) {
|
|
@@ -24,13 +24,11 @@
|
|
|
24
24
|
#include <spdlog/fmt/bundled/core.h>
|
|
25
25
|
#include <tao/json/value.hpp>
|
|
26
26
|
|
|
27
|
-
#include <regex>
|
|
28
|
-
|
|
29
27
|
namespace couchbase::core::operations::management
|
|
30
28
|
{
|
|
31
29
|
auto
|
|
32
|
-
scope_create_request::encode_to(encoded_request_type& encoded,
|
|
33
|
-
|
|
30
|
+
scope_create_request::encode_to(encoded_request_type& encoded, http_context& /* context */) const
|
|
31
|
+
-> std::error_code
|
|
34
32
|
{
|
|
35
33
|
encoded.method = "POST";
|
|
36
34
|
encoded.path = fmt::format("/pools/default/buckets/{}/scopes",
|
|
@@ -41,18 +39,19 @@ scope_create_request::encode_to(encoded_request_type& encoded,
|
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
auto
|
|
44
|
-
scope_create_request::make_response(error_context::http&& ctx,
|
|
45
|
-
|
|
42
|
+
scope_create_request::make_response(error_context::http&& ctx,
|
|
43
|
+
const encoded_response_type& encoded) const
|
|
44
|
+
-> scope_create_response
|
|
46
45
|
{
|
|
47
46
|
scope_create_response response{ std::move(ctx) };
|
|
48
47
|
if (!response.ctx.ec) {
|
|
49
|
-
switch (encoded.status_code) {
|
|
48
|
+
switch (const auto& body = encoded.body.data(); encoded.status_code) {
|
|
50
49
|
case 400: {
|
|
51
|
-
const
|
|
52
|
-
if (std::
|
|
50
|
+
const auto prefix_pos = body.find("Scope with name ");
|
|
51
|
+
if (prefix_pos != std::string_view::npos &&
|
|
52
|
+
body.find(" already exists", prefix_pos) != std::string_view::npos) {
|
|
53
53
|
response.ctx.ec = errc::management::scope_exists;
|
|
54
|
-
} else if (
|
|
55
|
-
std::string::npos) {
|
|
54
|
+
} else if (body.find("Not allowed on this version of cluster") != std::string::npos) {
|
|
56
55
|
response.ctx.ec = errc::common::feature_not_available;
|
|
57
56
|
} else {
|
|
58
57
|
response.ctx.ec = errc::common::invalid_argument;
|
|
@@ -64,7 +63,7 @@ scope_create_request::make_response(error_context::http&& ctx, const encoded_res
|
|
|
64
63
|
case 200: {
|
|
65
64
|
tao::json::value payload{};
|
|
66
65
|
try {
|
|
67
|
-
payload = utils::json::parse(
|
|
66
|
+
payload = utils::json::parse(body);
|
|
68
67
|
} catch (const tao::pegtl::parse_error&) {
|
|
69
68
|
response.ctx.ec = errc::common::parsing_failure;
|
|
70
69
|
return response;
|
|
@@ -72,7 +71,7 @@ scope_create_request::make_response(error_context::http&& ctx, const encoded_res
|
|
|
72
71
|
response.uid = std::stoull(payload.at("uid").get_string(), nullptr, 16);
|
|
73
72
|
} break;
|
|
74
73
|
default:
|
|
75
|
-
response.ctx.ec = extract_common_error_code(encoded.status_code,
|
|
74
|
+
response.ctx.ec = extract_common_error_code(encoded.status_code, body);
|
|
76
75
|
break;
|
|
77
76
|
}
|
|
78
77
|
}
|
|
@@ -24,13 +24,11 @@
|
|
|
24
24
|
#include <spdlog/fmt/bundled/core.h>
|
|
25
25
|
#include <tao/json/value.hpp>
|
|
26
26
|
|
|
27
|
-
#include <regex>
|
|
28
|
-
|
|
29
27
|
namespace couchbase::core::operations::management
|
|
30
28
|
{
|
|
31
29
|
auto
|
|
32
|
-
scope_drop_request::encode_to(encoded_request_type& encoded,
|
|
33
|
-
|
|
30
|
+
scope_drop_request::encode_to(encoded_request_type& encoded, http_context& /* context */) const
|
|
31
|
+
-> std::error_code
|
|
34
32
|
{
|
|
35
33
|
encoded.method = "DELETE";
|
|
36
34
|
encoded.path = fmt::format("/pools/default/buckets/{}/scopes/{}",
|
|
@@ -45,13 +43,14 @@ scope_drop_request::make_response(error_context::http&& ctx,
|
|
|
45
43
|
{
|
|
46
44
|
scope_drop_response response{ std::move(ctx) };
|
|
47
45
|
if (!response.ctx.ec) {
|
|
48
|
-
switch (encoded.status_code) {
|
|
46
|
+
switch (const auto& body = encoded.body.data(); encoded.status_code) {
|
|
49
47
|
case 400:
|
|
50
48
|
response.ctx.ec = errc::common::unsupported_operation;
|
|
51
49
|
break;
|
|
52
50
|
case 404: {
|
|
53
|
-
const
|
|
54
|
-
if (std::
|
|
51
|
+
const auto prefix_pos = body.find("Scope with name ");
|
|
52
|
+
if (prefix_pos != std::string_view::npos &&
|
|
53
|
+
body.find(" is not found", prefix_pos) != std::string_view::npos) {
|
|
55
54
|
response.ctx.ec = errc::common::scope_not_found;
|
|
56
55
|
} else {
|
|
57
56
|
response.ctx.ec = errc::common::bucket_not_found;
|
|
@@ -60,7 +59,7 @@ scope_drop_request::make_response(error_context::http&& ctx,
|
|
|
60
59
|
case 200: {
|
|
61
60
|
tao::json::value payload{};
|
|
62
61
|
try {
|
|
63
|
-
payload = utils::json::parse(
|
|
62
|
+
payload = utils::json::parse(body);
|
|
64
63
|
} catch (const tao::pegtl::parse_error&) {
|
|
65
64
|
response.ctx.ec = errc::common::parsing_failure;
|
|
66
65
|
return response;
|
|
@@ -68,7 +67,7 @@ scope_drop_request::make_response(error_context::http&& ctx,
|
|
|
68
67
|
response.uid = std::stoull(payload.at("uid").get_string(), nullptr, 16);
|
|
69
68
|
} break;
|
|
70
69
|
default:
|
|
71
|
-
response.ctx.ec = extract_common_error_code(encoded.status_code,
|
|
70
|
+
response.ctx.ec = extract_common_error_code(encoded.status_code, body);
|
|
72
71
|
break;
|
|
73
72
|
}
|
|
74
73
|
}
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
#include "configuration.hxx"
|
|
19
19
|
|
|
20
|
+
#include "core/impl/node_id.hxx"
|
|
20
21
|
#include "core/logger/logger.hxx"
|
|
21
22
|
#include "core/service_type_fmt.hxx"
|
|
22
23
|
#include "core/utils/crc32.hxx"
|
|
@@ -171,6 +172,26 @@ configuration::node::endpoint(const std::string& network, service_type type, boo
|
|
|
171
172
|
return fmt::format("{}:{}", hostname_for(network), p);
|
|
172
173
|
}
|
|
173
174
|
|
|
175
|
+
auto
|
|
176
|
+
configuration::node::effective_node_id(bool is_tls) const -> couchbase::node_id
|
|
177
|
+
{
|
|
178
|
+
return internal_node_id::build(node_uuid, hostname, port_or(service_type::key_value, is_tls, 0));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
auto
|
|
182
|
+
configuration::effective_node_ids(bool is_tls) const -> std::vector<couchbase::node_id>
|
|
183
|
+
{
|
|
184
|
+
std::vector<couchbase::node_id> result;
|
|
185
|
+
result.reserve(nodes.size());
|
|
186
|
+
for (const auto& n : nodes) {
|
|
187
|
+
if (n.port_or(service_type::key_value, is_tls, 0) == 0) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
result.push_back(n.effective_node_id(is_tls));
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
|
|
174
195
|
auto
|
|
175
196
|
configuration::has_node(const std::string& network,
|
|
176
197
|
service_type type,
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
#include "core/platform/uuid.h"
|
|
22
22
|
#include "core/service_type.hxx"
|
|
23
23
|
|
|
24
|
+
#include <couchbase/node_id.hxx>
|
|
25
|
+
|
|
24
26
|
#include <map>
|
|
25
27
|
#include <optional>
|
|
26
28
|
#include <set>
|
|
@@ -83,10 +85,36 @@ struct configuration {
|
|
|
83
85
|
|
|
84
86
|
[[nodiscard]] auto endpoint(const std::string& network, service_type type, bool is_tls) const
|
|
85
87
|
-> std::optional<std::string>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Returns a node_id built from this node's UUID (when available on
|
|
91
|
+
* Server 8.0.1+) with fallback to a deterministic hash of hostname +
|
|
92
|
+
* KV port for older servers.
|
|
93
|
+
*
|
|
94
|
+
* The KV port selected mirrors what mcbp_session uses for the same node
|
|
95
|
+
* (TLS port when @p is_tls, plain port otherwise), ensuring that the
|
|
96
|
+
* node_id surfaced on the request side via collection::node_id_for
|
|
97
|
+
* matches the node_id attached to results and errors.
|
|
98
|
+
*/
|
|
99
|
+
[[nodiscard]] auto effective_node_id(bool is_tls) const -> couchbase::node_id;
|
|
86
100
|
};
|
|
87
101
|
|
|
88
102
|
[[nodiscard]] auto select_network(const std::string& bootstrap_hostname) const -> std::string;
|
|
89
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Returns one node_id per cluster node that currently serves the
|
|
106
|
+
* key-value service over the requested transport. Nodes that do not
|
|
107
|
+
* expose a KV port for @p is_tls are filtered out — without a KV port
|
|
108
|
+
* the fallback hash would be derived from a meaningless port=0 and
|
|
109
|
+
* could collide with a sibling node that is also missing its KV port.
|
|
110
|
+
*
|
|
111
|
+
* The returned vector preserves topology order; callers that want a
|
|
112
|
+
* set semantic should hash the entries themselves (couchbase::node_id
|
|
113
|
+
* is hashable). Topology nodes are unique by construction, so no
|
|
114
|
+
* dedup is performed here.
|
|
115
|
+
*/
|
|
116
|
+
[[nodiscard]] auto effective_node_ids(bool is_tls) const -> std::vector<couchbase::node_id>;
|
|
117
|
+
|
|
90
118
|
using vbucket_map = typename std::vector<std::vector<std::int16_t>>;
|
|
91
119
|
|
|
92
120
|
std::optional<std::int64_t> epoch{};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#include "contains_string.hxx"
|
|
19
|
+
|
|
20
|
+
namespace couchbase::core::utils
|
|
21
|
+
{
|
|
22
|
+
|
|
23
|
+
namespace
|
|
24
|
+
{
|
|
25
|
+
constexpr auto ascii_lower = [](unsigned char c) -> unsigned char {
|
|
26
|
+
return (c >= 'A' && c <= 'Z') ? static_cast<unsigned char>(c + ('a' - 'A')) : c;
|
|
27
|
+
};
|
|
28
|
+
} // namespace
|
|
29
|
+
|
|
30
|
+
auto
|
|
31
|
+
contains_string(std::string_view input, std::string_view substr, bool ignore_case) -> bool
|
|
32
|
+
{
|
|
33
|
+
if (substr.empty()) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (input.empty() || substr.size() > input.size()) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!ignore_case) {
|
|
42
|
+
return input.find(substr) != std::string_view::npos;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const auto end = input.size() - substr.size() + 1;
|
|
46
|
+
for (std::size_t i = 0; i < end; i++) {
|
|
47
|
+
bool match = true;
|
|
48
|
+
for (std::size_t j = 0; j < substr.size(); j++) {
|
|
49
|
+
if (ascii_lower(static_cast<unsigned char>(input[i + j])) !=
|
|
50
|
+
ascii_lower(static_cast<unsigned char>(substr[j]))) {
|
|
51
|
+
match = false;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (match) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
} // namespace couchbase::core::utils
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#pragma once
|
|
19
|
+
|
|
20
|
+
#include <string_view>
|
|
21
|
+
|
|
22
|
+
namespace couchbase::core::utils
|
|
23
|
+
{
|
|
24
|
+
auto
|
|
25
|
+
contains_string(std::string_view input, std::string_view substr, bool ignore_case = false) -> bool;
|
|
26
|
+
} // namespace couchbase::core::utils
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
#include <couchbase/lookup_in_specs.hxx>
|
|
36
36
|
#include <couchbase/mutate_in_options.hxx>
|
|
37
37
|
#include <couchbase/mutate_in_specs.hxx>
|
|
38
|
+
#include <couchbase/node_id_for_options.hxx>
|
|
39
|
+
#include <couchbase/node_ids_options.hxx>
|
|
38
40
|
#include <couchbase/query_options.hxx>
|
|
39
41
|
#include <couchbase/remove_options.hxx>
|
|
40
42
|
#include <couchbase/replace_options.hxx>
|
|
@@ -1090,6 +1092,77 @@ public:
|
|
|
1090
1092
|
[[nodiscard]] auto scan(const scan_type& scan_type, const scan_options& options = {}) const
|
|
1091
1093
|
-> std::future<std::pair<error, scan_result>>;
|
|
1092
1094
|
|
|
1095
|
+
/**
|
|
1096
|
+
* Resolves a document key to the identity of the cluster node that currently
|
|
1097
|
+
* owns it, using the client-side vBucket map (no network round-trip).
|
|
1098
|
+
*
|
|
1099
|
+
* @param document_id the document id to resolve
|
|
1100
|
+
* @param options options to customize the request
|
|
1101
|
+
* @param handler the handler that receives the result
|
|
1102
|
+
*
|
|
1103
|
+
* @since 1.3.2
|
|
1104
|
+
* @uncommitted
|
|
1105
|
+
*/
|
|
1106
|
+
void node_id_for(std::string document_id,
|
|
1107
|
+
const node_id_for_options& options,
|
|
1108
|
+
node_id_for_handler&& handler) const;
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* Resolves a document key to the identity of the cluster node that currently
|
|
1112
|
+
* owns it, using the client-side vBucket map (no network round-trip).
|
|
1113
|
+
*
|
|
1114
|
+
* @param document_id the document id to resolve
|
|
1115
|
+
* @param options options to customize the request
|
|
1116
|
+
* @return future carrying the error (if any) and node_id
|
|
1117
|
+
*
|
|
1118
|
+
* @since 1.3.2
|
|
1119
|
+
* @uncommitted
|
|
1120
|
+
*/
|
|
1121
|
+
[[nodiscard]] auto node_id_for(std::string document_id,
|
|
1122
|
+
const node_id_for_options& options = {}) const
|
|
1123
|
+
-> std::future<std::pair<error, node_id>>;
|
|
1124
|
+
|
|
1125
|
+
/**
|
|
1126
|
+
* Returns the set of cluster nodes that currently serve key-value
|
|
1127
|
+
* traffic for this collection's bucket, drawn from the client-side
|
|
1128
|
+
* topology snapshot (no network round-trip).
|
|
1129
|
+
*
|
|
1130
|
+
* Each entry corresponds to one cluster node and is the same node_id
|
|
1131
|
+
* the SDK reports on KV results and errors that touched that node, so
|
|
1132
|
+
* the returned set is directly comparable to the keys of any
|
|
1133
|
+
* application-side state that is keyed by node_id (e.g. a per-node
|
|
1134
|
+
* circuit breaker registry). A periodic sweep that diffs the
|
|
1135
|
+
* registry's keys against this set is the canonical way to retire
|
|
1136
|
+
* tracker state for a node that has been removed from the cluster
|
|
1137
|
+
* topology.
|
|
1138
|
+
*
|
|
1139
|
+
* Nodes that do not expose a key-value port for the configured
|
|
1140
|
+
* transport (TLS or plain) are excluded from the returned set, since
|
|
1141
|
+
* they do not serve KV operations and therefore have no meaningful
|
|
1142
|
+
* identity from the SDK's point of view.
|
|
1143
|
+
*
|
|
1144
|
+
* @param options options to customize the request
|
|
1145
|
+
* @param handler the handler that receives the result
|
|
1146
|
+
*
|
|
1147
|
+
* @since 1.3.2
|
|
1148
|
+
* @uncommitted
|
|
1149
|
+
*/
|
|
1150
|
+
void node_ids(const node_ids_options& options, node_ids_handler&& handler) const;
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Returns the set of cluster nodes that currently serve key-value
|
|
1154
|
+
* traffic for this collection's bucket, drawn from the client-side
|
|
1155
|
+
* topology snapshot (no network round-trip).
|
|
1156
|
+
*
|
|
1157
|
+
* @param options options to customize the request
|
|
1158
|
+
* @return future carrying the error (if any) and the set of node_ids
|
|
1159
|
+
*
|
|
1160
|
+
* @since 1.3.2
|
|
1161
|
+
* @uncommitted
|
|
1162
|
+
*/
|
|
1163
|
+
[[nodiscard]] auto node_ids(const node_ids_options& options = {}) const
|
|
1164
|
+
-> std::future<std::pair<error, std::vector<node_id>>>;
|
|
1165
|
+
|
|
1093
1166
|
[[nodiscard]] auto query_indexes() const -> collection_query_index_manager;
|
|
1094
1167
|
|
|
1095
1168
|
private:
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
#pragma once
|
|
19
19
|
|
|
20
20
|
#include <couchbase/error_context.hxx>
|
|
21
|
+
#include <couchbase/node_id.hxx>
|
|
21
22
|
|
|
22
23
|
#include <memory>
|
|
23
24
|
#include <optional>
|
|
@@ -32,12 +33,26 @@ public:
|
|
|
32
33
|
error() = default;
|
|
33
34
|
error(std::error_code ec, std::string message = {}, error_context ctx = {});
|
|
34
35
|
error(std::error_code ec, std::string message, error_context ctx, error cause);
|
|
36
|
+
error(std::error_code ec, std::string message, error_context ctx, couchbase::node_id node_id);
|
|
35
37
|
|
|
36
38
|
[[nodiscard]] auto ec() const -> std::error_code;
|
|
37
39
|
[[nodiscard]] auto message() const -> const std::string&;
|
|
38
40
|
[[nodiscard]] auto ctx() const -> const error_context&;
|
|
39
41
|
[[nodiscard]] auto cause() const -> std::optional<error>;
|
|
40
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Returns the identity of the cluster node where the error occurred.
|
|
45
|
+
*
|
|
46
|
+
* The returned node_id is default-constructed (falsy) when the node
|
|
47
|
+
* could not be determined (e.g. for non-KV errors).
|
|
48
|
+
*
|
|
49
|
+
* @return identity of the node that returned the error
|
|
50
|
+
*
|
|
51
|
+
* @since 1.3.2
|
|
52
|
+
* @uncommitted
|
|
53
|
+
*/
|
|
54
|
+
[[nodiscard]] auto node_id() const -> const couchbase::node_id&;
|
|
55
|
+
|
|
41
56
|
explicit operator bool() const;
|
|
42
57
|
auto operator==(const error& other) const -> bool;
|
|
43
58
|
|
|
@@ -46,6 +61,7 @@ private:
|
|
|
46
61
|
std::string message_{};
|
|
47
62
|
error_context ctx_{};
|
|
48
63
|
std::shared_ptr<error> cause_{};
|
|
64
|
+
couchbase::node_id node_id_{};
|
|
49
65
|
};
|
|
50
66
|
|
|
51
67
|
} // namespace couchbase
|