couchbase 3.4.3 → 3.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/couchbase/CMakeLists.txt +15 -1
  4. data/ext/couchbase/core/bucket.cxx +183 -152
  5. data/ext/couchbase/core/bucket.hxx +17 -4
  6. data/ext/couchbase/core/cluster.hxx +34 -13
  7. data/ext/couchbase/core/cluster_options.hxx +3 -0
  8. data/ext/couchbase/core/crud_component.cxx +51 -22
  9. data/ext/couchbase/core/error_context/key_value.cxx +2 -1
  10. data/ext/couchbase/core/error_context/key_value.hxx +10 -12
  11. data/ext/couchbase/core/impl/build_deferred_query_indexes.cxx +115 -50
  12. data/ext/couchbase/core/impl/cluster.cxx +6 -0
  13. data/ext/couchbase/core/impl/create_bucket.cxx +155 -0
  14. data/ext/couchbase/core/impl/create_query_index.cxx +172 -59
  15. data/ext/couchbase/core/impl/dns_srv_tracker.cxx +2 -1
  16. data/ext/couchbase/core/impl/drop_bucket.cxx +66 -0
  17. data/ext/couchbase/core/impl/drop_query_index.cxx +138 -59
  18. data/ext/couchbase/core/impl/flush_bucket.cxx +66 -0
  19. data/ext/couchbase/core/impl/get_all_buckets.cxx +163 -0
  20. data/ext/couchbase/core/impl/get_all_query_indexes.cxx +67 -37
  21. data/ext/couchbase/core/impl/get_bucket.cxx +153 -0
  22. data/ext/couchbase/core/impl/internal_manager_error_context.cxx +113 -0
  23. data/ext/couchbase/core/impl/internal_manager_error_context.hxx +60 -0
  24. data/ext/couchbase/core/impl/key_value_error_category.cxx +2 -4
  25. data/ext/couchbase/core/impl/key_value_error_context.cxx +98 -0
  26. data/ext/couchbase/core/impl/lookup_in.cxx +1 -0
  27. data/ext/couchbase/core/impl/lookup_in_all_replicas.cxx +176 -0
  28. data/ext/couchbase/core/impl/lookup_in_all_replicas.hxx +80 -0
  29. data/ext/couchbase/core/impl/lookup_in_any_replica.cxx +167 -0
  30. data/ext/couchbase/core/impl/lookup_in_any_replica.hxx +75 -0
  31. data/ext/couchbase/core/impl/lookup_in_replica.cxx +97 -0
  32. data/ext/couchbase/core/impl/lookup_in_replica.hxx +67 -0
  33. data/ext/couchbase/core/impl/manager_error_context.cxx +100 -0
  34. data/ext/couchbase/core/impl/query.cxx +1 -0
  35. data/ext/couchbase/core/impl/query_error_context.cxx +75 -0
  36. data/ext/couchbase/core/impl/update_bucket.cxx +130 -0
  37. data/ext/couchbase/core/impl/watch_query_indexes.cxx +53 -29
  38. data/ext/couchbase/core/io/dns_client.cxx +111 -40
  39. data/ext/couchbase/core/io/dns_config.cxx +5 -4
  40. data/ext/couchbase/core/io/http_session.hxx +24 -1
  41. data/ext/couchbase/core/io/mcbp_command.hxx +9 -2
  42. data/ext/couchbase/core/io/mcbp_session.cxx +80 -43
  43. data/ext/couchbase/core/io/mcbp_session.hxx +4 -3
  44. data/ext/couchbase/core/logger/custom_rotating_file_sink.cxx +1 -1
  45. data/ext/couchbase/core/logger/logger.cxx +80 -20
  46. data/ext/couchbase/core/logger/logger.hxx +31 -0
  47. data/ext/couchbase/core/meta/features.hxx +25 -0
  48. data/ext/couchbase/core/operations/document_lookup_in_all_replicas.hxx +192 -0
  49. data/ext/couchbase/core/operations/document_lookup_in_any_replica.hxx +188 -0
  50. data/ext/couchbase/core/operations/document_query.cxx +11 -0
  51. data/ext/couchbase/core/operations/document_query.hxx +1 -0
  52. data/ext/couchbase/core/operations.hxx +2 -0
  53. data/ext/couchbase/core/origin.cxx +270 -0
  54. data/ext/couchbase/core/origin.hxx +2 -0
  55. data/ext/couchbase/core/protocol/client_response.hxx +1 -0
  56. data/ext/couchbase/core/protocol/cmd_hello.hxx +1 -0
  57. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.cxx +107 -0
  58. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.hxx +137 -0
  59. data/ext/couchbase/core/protocol/hello_feature.hxx +6 -0
  60. data/ext/couchbase/core/protocol/hello_feature_fmt.hxx +3 -0
  61. data/ext/couchbase/core/protocol/status.cxx +2 -2
  62. data/ext/couchbase/core/range_scan_options.cxx +3 -27
  63. data/ext/couchbase/core/range_scan_options.hxx +13 -17
  64. data/ext/couchbase/core/range_scan_orchestrator.cxx +388 -170
  65. data/ext/couchbase/core/range_scan_orchestrator.hxx +13 -2
  66. data/ext/couchbase/core/range_scan_orchestrator_options.hxx +5 -3
  67. data/ext/couchbase/core/scan_options.hxx +0 -19
  68. data/ext/couchbase/core/scan_result.cxx +19 -5
  69. data/ext/couchbase/core/scan_result.hxx +5 -2
  70. data/ext/couchbase/core/timeout_defaults.hxx +2 -3
  71. data/ext/couchbase/core/topology/capabilities.hxx +3 -0
  72. data/ext/couchbase/core/topology/capabilities_fmt.hxx +8 -0
  73. data/ext/couchbase/core/topology/collections_manifest_fmt.hxx +1 -1
  74. data/ext/couchbase/core/topology/configuration.hxx +15 -0
  75. data/ext/couchbase/core/topology/configuration_json.hxx +6 -1
  76. data/ext/couchbase/core/utils/connection_string.cxx +62 -47
  77. data/ext/couchbase/core/utils/connection_string.hxx +1 -0
  78. data/ext/couchbase/couchbase/analytics_error_context.hxx +1 -1
  79. data/ext/couchbase/couchbase/behavior_options.hxx +19 -2
  80. data/ext/couchbase/couchbase/bucket_manager.hxx +135 -0
  81. data/ext/couchbase/couchbase/build_query_index_options.hxx +0 -30
  82. data/ext/couchbase/couchbase/cluster.hxx +14 -0
  83. data/ext/couchbase/couchbase/collection.hxx +111 -0
  84. data/ext/couchbase/couchbase/collection_query_index_manager.hxx +7 -48
  85. data/ext/couchbase/couchbase/create_bucket_options.hxx +41 -0
  86. data/ext/couchbase/couchbase/create_primary_query_index_options.hxx +0 -29
  87. data/ext/couchbase/couchbase/create_query_index_options.hxx +0 -33
  88. data/ext/couchbase/couchbase/drop_bucket_options.hxx +41 -0
  89. data/ext/couchbase/couchbase/drop_primary_query_index_options.hxx +0 -30
  90. data/ext/couchbase/couchbase/drop_query_index_options.hxx +0 -31
  91. data/ext/couchbase/couchbase/error_codes.hxx +1 -2
  92. data/ext/couchbase/couchbase/error_context.hxx +10 -2
  93. data/ext/couchbase/couchbase/flush_bucket_options.hxx +41 -0
  94. data/ext/couchbase/{core/topology/error_map_fmt.hxx → couchbase/fmt/key_value_error_map_attribute.hxx} +21 -21
  95. data/ext/couchbase/couchbase/get_all_buckets_options.hxx +44 -0
  96. data/ext/couchbase/couchbase/get_all_query_indexes_options.hxx +0 -30
  97. data/ext/couchbase/couchbase/get_and_lock_options.hxx +2 -2
  98. data/ext/couchbase/couchbase/get_and_touch_options.hxx +2 -2
  99. data/ext/couchbase/couchbase/get_bucket_options.hxx +43 -0
  100. data/ext/couchbase/couchbase/get_options.hxx +2 -2
  101. data/ext/couchbase/couchbase/insert_options.hxx +3 -3
  102. data/ext/couchbase/couchbase/key_value_error_context.hxx +7 -2
  103. data/ext/couchbase/couchbase/lookup_in_all_replicas_options.hxx +109 -0
  104. data/ext/couchbase/couchbase/lookup_in_any_replica_options.hxx +101 -0
  105. data/ext/couchbase/couchbase/lookup_in_options.hxx +2 -2
  106. data/ext/couchbase/couchbase/lookup_in_replica_result.hxx +74 -0
  107. data/ext/couchbase/couchbase/lookup_in_result.hxx +26 -0
  108. data/ext/couchbase/couchbase/management/bucket_settings.hxx +116 -0
  109. data/ext/couchbase/couchbase/manager_error_context.hxx +29 -53
  110. data/ext/couchbase/couchbase/mutate_in_options.hxx +2 -2
  111. data/ext/couchbase/couchbase/query_error_context.hxx +3 -1
  112. data/ext/couchbase/couchbase/query_index_manager.hxx +16 -83
  113. data/ext/couchbase/couchbase/query_options.hxx +18 -0
  114. data/ext/couchbase/couchbase/remove_options.hxx +2 -2
  115. data/ext/couchbase/couchbase/replace_options.hxx +3 -3
  116. data/ext/couchbase/couchbase/security_options.hxx +15 -0
  117. data/ext/couchbase/couchbase/subdocument_error_context.hxx +4 -2
  118. data/ext/couchbase/couchbase/touch_options.hxx +2 -2
  119. data/ext/couchbase/couchbase/unlock_options.hxx +2 -2
  120. data/ext/couchbase/couchbase/update_bucket_options.hxx +41 -0
  121. data/ext/couchbase/couchbase/upsert_options.hxx +3 -3
  122. data/ext/couchbase/couchbase/watch_query_indexes_options.hxx +0 -31
  123. data/ext/couchbase/test/CMakeLists.txt +1 -0
  124. data/ext/couchbase/test/test_integration_collections.cxx +6 -0
  125. data/ext/couchbase/test/test_integration_crud.cxx +5 -0
  126. data/ext/couchbase/test/test_integration_examples.cxx +137 -1
  127. data/ext/couchbase/test/test_integration_management.cxx +709 -266
  128. data/ext/couchbase/test/test_integration_query.cxx +19 -7
  129. data/ext/couchbase/test/test_integration_range_scan.cxx +351 -112
  130. data/ext/couchbase/test/test_integration_search.cxx +10 -1
  131. data/ext/couchbase/test/test_integration_subdoc.cxx +655 -0
  132. data/ext/couchbase/test/test_transaction_public_async_api.cxx +13 -12
  133. data/ext/couchbase/test/test_transaction_public_blocking_api.cxx +27 -21
  134. data/ext/couchbase/test/test_unit_connection_string.cxx +29 -0
  135. data/ext/couchbase/test/test_unit_query.cxx +75 -0
  136. data/ext/couchbase.cxx +583 -29
  137. data/ext/revisions.rb +3 -3
  138. data/lib/couchbase/cluster.rb +1 -1
  139. data/lib/couchbase/collection.rb +108 -0
  140. data/lib/couchbase/collection_options.rb +100 -0
  141. data/lib/couchbase/errors.rb +5 -0
  142. data/lib/couchbase/key_value_scan.rb +125 -0
  143. data/lib/couchbase/options.rb +151 -0
  144. data/lib/couchbase/scope.rb +1 -1
  145. data/lib/couchbase/utils/time.rb +14 -1
  146. data/lib/couchbase/version.rb +1 -1
  147. metadata +41 -7
  148. data/ext/couchbase/core/impl/collection_query_index_manager.cxx +0 -93
@@ -0,0 +1,192 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include "core/error_context/key_value.hxx"
21
+ #include "core/impl/lookup_in_replica.hxx"
22
+ #include "core/impl/subdoc/command.hxx"
23
+ #include "core/operations/document_lookup_in.hxx"
24
+ #include "core/operations/operation_traits.hxx"
25
+ #include "core/utils/movable_function.hxx"
26
+ #include "couchbase/codec/encoded_value.hxx"
27
+ #include "couchbase/error_codes.hxx"
28
+
29
+ #include <functional>
30
+ #include <memory>
31
+ #include <mutex>
32
+
33
+ namespace couchbase::core::operations
34
+ {
35
+ struct lookup_in_all_replicas_response {
36
+ struct entry {
37
+ struct lookup_in_entry {
38
+ std::string path;
39
+ codec::binary value;
40
+ std::size_t original_index;
41
+ bool exists;
42
+ protocol::subdoc_opcode opcode;
43
+ key_value_status_code status;
44
+ std::error_code ec{};
45
+ };
46
+ std::vector<lookup_in_entry> fields{};
47
+ couchbase::cas cas{};
48
+ bool deleted{ false };
49
+ bool is_replica{ true };
50
+ };
51
+ subdocument_error_context ctx{};
52
+ std::vector<entry> entries{};
53
+ };
54
+
55
+ struct lookup_in_all_replicas_request {
56
+ using response_type = lookup_in_all_replicas_response;
57
+ using encoded_request_type = core::protocol::client_request<core::protocol::lookup_in_replica_request_body>;
58
+ using encoded_response_type = core::protocol::client_response<core::protocol::lookup_in_replica_response_body>;
59
+
60
+ core::document_id id;
61
+ std::vector<couchbase::core::impl::subdoc::command> specs{};
62
+ std::optional<std::chrono::milliseconds> timeout{};
63
+ std::shared_ptr<couchbase::tracing::request_span> parent_span{ nullptr };
64
+
65
+ template<typename Core, typename Handler>
66
+ void execute(Core core, Handler handler)
67
+ {
68
+ core->with_bucket_configuration(
69
+ id.bucket(),
70
+ [core, id = id, timeout = timeout, specs = specs, parent_span = parent_span, h = std::forward<Handler>(handler)](
71
+ std::error_code ec, const topology::configuration& config) mutable {
72
+ if (!config.supports_subdoc_read_replica()) {
73
+ ec = errc::common::feature_not_available;
74
+ }
75
+
76
+ if (ec) {
77
+ std::optional<std::string> first_error_path{};
78
+ std::optional<std::size_t> first_error_index{};
79
+ return h(response_type{
80
+ make_subdocument_error_context(make_key_value_error_context(ec, id), ec, first_error_path, first_error_index, false) });
81
+ }
82
+ using handler_type = utils::movable_function<void(response_type)>;
83
+
84
+ struct replica_context {
85
+ replica_context(handler_type handler, std::uint32_t expected_responses)
86
+ : handler_(std::move(handler))
87
+ , expected_responses_(expected_responses)
88
+ {
89
+ }
90
+
91
+ handler_type handler_;
92
+ std::uint32_t expected_responses_;
93
+ bool done_{ false };
94
+ std::mutex mutex_{};
95
+ std::vector<lookup_in_all_replicas_response::entry> result_{};
96
+ };
97
+ auto ctx = std::make_shared<replica_context>(std::move(h), config.num_replicas.value_or(0U) + 1U);
98
+
99
+ for (std::size_t idx = 1U; idx <= config.num_replicas.value_or(0U); ++idx) {
100
+ document_id replica_id{ id };
101
+ replica_id.node_index(idx);
102
+ core->execute(impl::lookup_in_replica_request{ std::move(replica_id), specs, timeout, parent_span },
103
+ [ctx](impl::lookup_in_replica_response&& resp) {
104
+ handler_type local_handler{};
105
+ {
106
+ std::scoped_lock lock(ctx->mutex_);
107
+ if (ctx->done_) {
108
+ return;
109
+ }
110
+ --ctx->expected_responses_;
111
+ if (resp.ctx.ec()) {
112
+ if (ctx->expected_responses_ > 0) {
113
+ // just ignore the response
114
+ return;
115
+ }
116
+ } else {
117
+ lookup_in_all_replicas_response::entry top_entry{};
118
+ top_entry.cas = resp.cas;
119
+ top_entry.deleted = resp.deleted;
120
+ top_entry.is_replica = true;
121
+ for (auto& field : resp.fields) {
122
+ lookup_in_all_replicas_response::entry::lookup_in_entry lookup_in_entry{};
123
+ lookup_in_entry.path = field.path;
124
+ lookup_in_entry.value = field.value;
125
+ lookup_in_entry.status = field.status;
126
+ lookup_in_entry.ec = field.ec;
127
+ lookup_in_entry.exists = field.exists;
128
+ lookup_in_entry.original_index = field.original_index;
129
+ lookup_in_entry.opcode = field.opcode;
130
+ top_entry.fields.emplace_back(lookup_in_entry);
131
+ }
132
+ ctx->result_.emplace_back(lookup_in_all_replicas_response::entry{ top_entry });
133
+ }
134
+ if (ctx->expected_responses_ == 0) {
135
+ ctx->done_ = true;
136
+ std::swap(local_handler, ctx->handler_);
137
+ }
138
+ }
139
+ if (local_handler) {
140
+ return local_handler({ std::move(resp.ctx), std::move(ctx->result_) });
141
+ }
142
+ });
143
+ }
144
+
145
+ core->execute(lookup_in_request{ document_id{ id }, {}, {}, false, specs, timeout }, [ctx](lookup_in_response&& resp) {
146
+ handler_type local_handler{};
147
+ {
148
+ std::scoped_lock lock(ctx->mutex_);
149
+ if (ctx->done_) {
150
+ return;
151
+ }
152
+ --ctx->expected_responses_;
153
+ if (resp.ctx.ec()) {
154
+ if (ctx->expected_responses_ > 0) {
155
+ // just ignore the response
156
+ return;
157
+ }
158
+ } else {
159
+ lookup_in_all_replicas_response::entry top_entry{};
160
+ top_entry.cas = resp.cas;
161
+ top_entry.deleted = resp.deleted;
162
+ top_entry.is_replica = false;
163
+ for (auto& field : resp.fields) {
164
+ lookup_in_all_replicas_response::entry::lookup_in_entry lookup_in_entry{};
165
+ lookup_in_entry.path = field.path;
166
+ lookup_in_entry.value = field.value;
167
+ lookup_in_entry.status = field.status;
168
+ lookup_in_entry.ec = field.ec;
169
+ lookup_in_entry.exists = field.exists;
170
+ lookup_in_entry.original_index = field.original_index;
171
+ lookup_in_entry.opcode = field.opcode;
172
+ top_entry.fields.emplace_back(lookup_in_entry);
173
+ }
174
+ ctx->result_.emplace_back(lookup_in_all_replicas_response::entry{ top_entry });
175
+ }
176
+ if (ctx->expected_responses_ == 0) {
177
+ ctx->done_ = true;
178
+ std::swap(local_handler, ctx->handler_);
179
+ }
180
+ }
181
+ if (local_handler) {
182
+ return local_handler({ std::move(resp.ctx), std::move(ctx->result_) });
183
+ }
184
+ });
185
+ });
186
+ }
187
+ };
188
+
189
+ template<>
190
+ struct is_compound_operation<lookup_in_all_replicas_request> : public std::true_type {
191
+ };
192
+ } // namespace couchbase::core::operations
@@ -0,0 +1,188 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include "core/error_context/key_value.hxx"
21
+ #include "core/impl/lookup_in_replica.hxx"
22
+ #include "core/impl/subdoc/command.hxx"
23
+ #include "core/operations/document_lookup_in.hxx"
24
+ #include "core/operations/operation_traits.hxx"
25
+ #include "core/utils/movable_function.hxx"
26
+ #include "couchbase/codec/encoded_value.hxx"
27
+ #include "couchbase/error_codes.hxx"
28
+
29
+ #include <functional>
30
+ #include <memory>
31
+ #include <mutex>
32
+
33
+ namespace couchbase::core::operations
34
+ {
35
+ struct lookup_in_any_replica_response {
36
+ struct entry {
37
+ std::string path;
38
+ codec::binary value;
39
+ std::size_t original_index;
40
+ bool exists;
41
+ protocol::subdoc_opcode opcode;
42
+ key_value_status_code status;
43
+ std::error_code ec{};
44
+ };
45
+ subdocument_error_context ctx{};
46
+ couchbase::cas cas{};
47
+ std::vector<entry> fields{};
48
+ bool deleted{ false };
49
+ bool is_replica{ true };
50
+ };
51
+
52
+ struct lookup_in_any_replica_request {
53
+ using response_type = lookup_in_any_replica_response;
54
+ using encoded_request_type = core::protocol::client_request<core::protocol::lookup_in_replica_request_body>;
55
+ using encoded_response_type = core::protocol::client_response<core::protocol::lookup_in_replica_response_body>;
56
+
57
+ core::document_id id;
58
+ std::vector<couchbase::core::impl::subdoc::command> specs{};
59
+ std::optional<std::chrono::milliseconds> timeout{};
60
+ std::shared_ptr<couchbase::tracing::request_span> parent_span{ nullptr };
61
+
62
+ template<typename Core, typename Handler>
63
+ void execute(Core core, Handler handler)
64
+ {
65
+ core->with_bucket_configuration(
66
+ id.bucket(),
67
+ [core, id = id, timeout = timeout, specs = specs, parent_span = parent_span, h = std::forward<Handler>(handler)](
68
+ std::error_code ec, const topology::configuration& config) mutable {
69
+ if (!config.supports_subdoc_read_replica()) {
70
+ ec = errc::common::feature_not_available;
71
+ }
72
+ if (specs.size() > 16) {
73
+ ec = errc::common::invalid_argument;
74
+ }
75
+
76
+ if (ec) {
77
+ std::optional<std::string> first_error_path{};
78
+ std::optional<std::size_t> first_error_index{};
79
+ return h(response_type{
80
+ make_subdocument_error_context(make_key_value_error_context(ec, id), ec, first_error_path, first_error_index, false) });
81
+ }
82
+ using handler_type = utils::movable_function<void(response_type)>;
83
+
84
+ struct replica_context {
85
+ replica_context(handler_type&& handler, std::uint32_t expected_responses)
86
+ : handler_(std::move(handler))
87
+ , expected_responses_(expected_responses)
88
+ {
89
+ }
90
+
91
+ handler_type handler_;
92
+ std::uint32_t expected_responses_;
93
+ bool done_{ false };
94
+ std::mutex mutex_{};
95
+ };
96
+ auto ctx = std::make_shared<replica_context>(std::move(h), config.num_replicas.value_or(0U) + 1U);
97
+
98
+ for (std::size_t idx = 1U; idx <= config.num_replicas.value_or(0U); ++idx) {
99
+ document_id replica_id{ id };
100
+ replica_id.node_index(idx);
101
+ core->execute(impl::lookup_in_replica_request{ std::move(replica_id), specs, timeout, parent_span },
102
+ [ctx](impl::lookup_in_replica_response&& resp) {
103
+ handler_type local_handler;
104
+ {
105
+ std::scoped_lock lock(ctx->mutex_);
106
+ if (ctx->done_) {
107
+ return;
108
+ }
109
+ --ctx->expected_responses_;
110
+ if (resp.ctx.ec()) {
111
+ if (ctx->expected_responses_ > 0) {
112
+ // just ignore the response
113
+ return;
114
+ }
115
+ // consider document irretrievable and give up
116
+ resp.ctx.override_ec(errc::key_value::document_irretrievable);
117
+ }
118
+ ctx->done_ = true;
119
+ std::swap(local_handler, ctx->handler_);
120
+ }
121
+ if (local_handler) {
122
+ response_type res{};
123
+ res.ctx = resp.ctx;
124
+ res.cas = resp.cas;
125
+ res.deleted = resp.deleted;
126
+ res.is_replica = true;
127
+ for (auto& field : resp.fields) {
128
+ auto lookup_in_entry = lookup_in_any_replica_response::entry{};
129
+ lookup_in_entry.path = field.path;
130
+ lookup_in_entry.value = field.value;
131
+ lookup_in_entry.status = field.status;
132
+ lookup_in_entry.ec = field.ec;
133
+ lookup_in_entry.exists = field.exists;
134
+ lookup_in_entry.original_index = field.original_index;
135
+ lookup_in_entry.opcode = field.opcode;
136
+ res.fields.emplace_back(lookup_in_entry);
137
+ }
138
+ return local_handler(res);
139
+ }
140
+ });
141
+ }
142
+ core->execute(lookup_in_request{ id, {}, {}, false, specs, timeout }, [ctx](lookup_in_response&& resp) {
143
+ handler_type local_handler{};
144
+ {
145
+ std::scoped_lock lock(ctx->mutex_);
146
+ if (ctx->done_) {
147
+ return;
148
+ }
149
+ --ctx->expected_responses_;
150
+ if (resp.ctx.ec()) {
151
+ if (ctx->expected_responses_ > 0) {
152
+ // just ignore the response
153
+ return;
154
+ }
155
+ // consider document irretrievable and give up
156
+ resp.ctx.override_ec(errc::key_value::document_irretrievable);
157
+ }
158
+ ctx->done_ = true;
159
+ std::swap(local_handler, ctx->handler_);
160
+ }
161
+ if (local_handler) {
162
+ auto res = response_type{};
163
+ res.ctx = resp.ctx;
164
+ res.cas = resp.cas;
165
+ res.deleted = resp.deleted;
166
+ res.is_replica = false;
167
+ for (auto& field : resp.fields) {
168
+ auto lookup_in_entry = lookup_in_any_replica_response::entry{};
169
+ lookup_in_entry.path = field.path;
170
+ lookup_in_entry.value = field.value;
171
+ lookup_in_entry.status = field.status;
172
+ lookup_in_entry.ec = field.ec;
173
+ lookup_in_entry.exists = field.exists;
174
+ lookup_in_entry.original_index = field.original_index;
175
+ lookup_in_entry.opcode = field.opcode;
176
+ res.fields.emplace_back(lookup_in_entry);
177
+ }
178
+ return local_handler(res);
179
+ }
180
+ });
181
+ });
182
+ }
183
+ };
184
+
185
+ template<>
186
+ struct is_compound_operation<lookup_in_any_replica_request> : public std::true_type {
187
+ };
188
+ } // namespace couchbase::core::operations
@@ -85,6 +85,17 @@ query_request::encode_to(query_request::encoded_request_type& encoded, http_cont
85
85
  case couchbase::query_profile::off:
86
86
  break;
87
87
  }
88
+ if (use_replica.has_value()) {
89
+ if (context.config.supports_read_from_replica()) {
90
+ if (use_replica.value()) {
91
+ body["use_replica"] = "on";
92
+ } else {
93
+ body["use_replica"] = "off";
94
+ }
95
+ } else {
96
+ return errc::common::feature_not_available;
97
+ }
98
+ }
88
99
  if (max_parallelism) {
89
100
  body["max_parallelism"] = std::to_string(max_parallelism.value());
90
101
  }
@@ -91,6 +91,7 @@ struct query_request {
91
91
  bool flex_index{ false };
92
92
  bool preserve_expiry{ false };
93
93
 
94
+ std::optional<bool> use_replica{};
94
95
  std::optional<std::uint64_t> max_parallelism{};
95
96
  std::optional<std::uint64_t> scan_cap{};
96
97
  std::optional<std::chrono::milliseconds> scan_wait{};
@@ -30,6 +30,8 @@
30
30
  #include "core/operations/document_increment.hxx"
31
31
  #include "core/operations/document_insert.hxx"
32
32
  #include "core/operations/document_lookup_in.hxx"
33
+ #include "core/operations/document_lookup_in_all_replicas.hxx"
34
+ #include "core/operations/document_lookup_in_any_replica.hxx"
33
35
  #include "core/operations/document_mutate_in.hxx"
34
36
  #include "core/operations/document_prepend.hxx"
35
37
  #include "core/operations/document_query.hxx"