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,74 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-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 <couchbase/lookup_in_result.hxx>
21
+
22
+ #include <vector>
23
+
24
+ namespace couchbase
25
+ {
26
+
27
+ /**
28
+ * Represents result of lookup_in_replica operations.
29
+ *
30
+ * @since 1.0.0
31
+ * @committed
32
+ */
33
+ class lookup_in_replica_result : public lookup_in_result
34
+ {
35
+ public:
36
+ /**
37
+ * @since 1.0.0
38
+ * @internal
39
+ */
40
+ lookup_in_replica_result() = default;
41
+
42
+ /**
43
+ * Constructs result for lookup_in_replica operation
44
+ *
45
+ * @param cas
46
+ * @param entries list of the fields returned by the server
47
+ * @param is_deleted
48
+ * @param is_replica true if document originates from replica node
49
+ *
50
+ * @since 1.0.0
51
+ * @committed
52
+ */
53
+ lookup_in_replica_result(couchbase::cas cas, std::vector<entry> entries, bool is_deleted, bool is_replica)
54
+ : lookup_in_result{ cas, std::move(entries), is_deleted }
55
+ , is_replica_{ is_replica }
56
+ {
57
+ }
58
+
59
+ /**
60
+ * Returns whether this document originates from a replica node
61
+ *
62
+ * @return whether document originates from a replica node
63
+ *
64
+ * @since 1.0.0
65
+ */
66
+ [[nodiscard]] auto is_replica() const -> bool
67
+ {
68
+ return is_replica_;
69
+ }
70
+
71
+ private:
72
+ bool is_replica_{ false };
73
+ };
74
+ } // namespace couchbase
@@ -44,6 +44,7 @@ class lookup_in_result : public result
44
44
  codec::binary value;
45
45
  std::size_t original_index;
46
46
  bool exists;
47
+ std::error_code ec;
47
48
  };
48
49
 
49
50
  /**
@@ -84,6 +85,11 @@ class lookup_in_result : public result
84
85
  {
85
86
  for (const entry& e : entries_) {
86
87
  if (e.original_index == index) {
88
+ if (e.ec) {
89
+ throw std::system_error(
90
+ e.ec, "error getting result for spec at index " + std::to_string(index) + ", path \"" + e.path + "\"");
91
+ }
92
+
87
93
  return codec::tao_json_serializer::deserialize<Document>(e.value);
88
94
  }
89
95
  }
@@ -105,6 +111,10 @@ class lookup_in_result : public result
105
111
  {
106
112
  for (const entry& e : entries_) {
107
113
  if (e.path == path) {
114
+ if (e.ec) {
115
+ throw std::system_error(e.ec, "error getting result for path \"" + e.path + "\"");
116
+ }
117
+
108
118
  return codec::tao_json_serializer::deserialize<Document>(e.value);
109
119
  }
110
120
  }
@@ -127,6 +137,10 @@ class lookup_in_result : public result
127
137
  const auto& macro_string = subdoc::to_string(macro);
128
138
  for (const entry& e : entries_) {
129
139
  if (e.path == macro_string) {
140
+ if (e.ec) {
141
+ throw std::system_error(e.ec, "error getting result for macro \"" + macro_string + "\"");
142
+ }
143
+
130
144
  return codec::tao_json_serializer::deserialize<Document>(e.value);
131
145
  }
132
146
  }
@@ -147,6 +161,10 @@ class lookup_in_result : public result
147
161
  {
148
162
  for (const entry& e : entries_) {
149
163
  if (e.original_index == index) {
164
+ if (e.ec && e.ec != couchbase::errc::key_value::path_not_found) {
165
+ throw std::system_error(e.ec, "error getting result for path \"" + e.path + "\"");
166
+ }
167
+
150
168
  return e.exists;
151
169
  }
152
170
  }
@@ -167,6 +185,10 @@ class lookup_in_result : public result
167
185
  const auto& macro_string = subdoc::to_string(macro);
168
186
  for (const entry& e : entries_) {
169
187
  if (e.path == macro_string) {
188
+ if (e.ec && e.ec != couchbase::errc::key_value::path_not_found) {
189
+ throw std::system_error(e.ec, "error getting result for macro \"" + macro_string + "\"");
190
+ }
191
+
170
192
  return e.exists;
171
193
  }
172
194
  }
@@ -186,6 +208,10 @@ class lookup_in_result : public result
186
208
  {
187
209
  for (const entry& e : entries_) {
188
210
  if (e.path == path) {
211
+ if (e.ec && e.ec != couchbase::errc::key_value::path_not_found) {
212
+ throw std::system_error(e.ec, "error getting result for path \"" + e.path + "\"");
213
+ }
214
+
189
215
  return e.exists;
190
216
  }
191
217
  }
@@ -0,0 +1,116 @@
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 <couchbase/durability_level.hxx>
21
+
22
+ #include <map>
23
+ #include <optional>
24
+ #include <string>
25
+ #include <vector>
26
+
27
+ namespace couchbase::management::cluster
28
+ {
29
+ enum class bucket_type { unknown, couchbase, memcached, ephemeral };
30
+ enum class bucket_compression { unknown, off, active, passive };
31
+ enum class bucket_eviction_policy {
32
+ unknown,
33
+
34
+ /**
35
+ * During ejection, everything (including key, metadata, and value) will be ejected.
36
+ *
37
+ * Full Ejection reduces the memory overhead requirement, at the cost of performance.
38
+ *
39
+ * This value is only valid for buckets of type COUCHBASE.
40
+ */
41
+ full,
42
+
43
+ /**
44
+ * During ejection, only the value will be ejected (key and metadata will remain in memory).
45
+ *
46
+ * Value Ejection needs more system memory, but provides better performance than Full Ejection.
47
+ *
48
+ * This value is only valid for buckets of type COUCHBASE.
49
+ */
50
+ value_only,
51
+
52
+ /**
53
+ * Couchbase Server keeps all data until explicitly deleted, but will reject
54
+ * any new data if you reach the quota (dedicated memory) you set for your bucket.
55
+ *
56
+ * This value is only valid for buckets of type EPHEMERAL.
57
+ */
58
+ no_eviction,
59
+
60
+ /**
61
+ * When the memory quota is reached, Couchbase Server ejects data that has not been used recently.
62
+ *
63
+ * This value is only valid for buckets of type EPHEMERAL.
64
+ */
65
+ not_recently_used,
66
+ };
67
+ enum class bucket_conflict_resolution {
68
+ unknown,
69
+ /**
70
+ * Use timestamp conflict resolution.
71
+ *
72
+ * Timestamp-based conflict resolution (often referred to as Last Write Wins, or LWW) uses the document
73
+ * timestamp (stored in the CAS) to resolve conflicts. The timestamps associated with the most recent
74
+ * updates of source and target documents are compared. The document whose update has the more recent
75
+ * timestamp prevails.
76
+ */
77
+ timestamp,
78
+
79
+ /**
80
+ * Use sequence number conflict resolution
81
+ *
82
+ * Conflicts can be resolved by referring to documents' sequence numbers. Sequence numbers are maintained
83
+ * per document, and are incremented on every document-update. The sequence numbers of source and
84
+ * target documents are compared; and the document with the higher sequence number prevails.
85
+ */
86
+ sequence_number,
87
+
88
+ /**
89
+ * VOLATILE: This API is subject to change at any time.
90
+ *
91
+ * In Couchbase Server 7.1, this feature is only available in "developer-preview" mode. See the UI XDCR settings.
92
+ */
93
+ custom,
94
+ };
95
+ enum class bucket_storage_backend { unknown, couchstore, magma };
96
+
97
+ struct bucket_settings {
98
+
99
+ std::string name;
100
+ cluster::bucket_type bucket_type{ cluster::bucket_type::unknown };
101
+ std::uint64_t ram_quota_mb{ 100 };
102
+ std::uint32_t max_expiry{ 0 };
103
+ bucket_compression compression_mode{ bucket_compression::unknown };
104
+ std::optional<couchbase::durability_level> minimum_durability_level{};
105
+ std::uint32_t num_replicas{ 1 };
106
+ bool replica_indexes{ false };
107
+ bool flush_enabled{ false };
108
+ bucket_eviction_policy eviction_policy{ bucket_eviction_policy::unknown };
109
+ bucket_conflict_resolution conflict_resolution_type{ bucket_conflict_resolution::unknown };
110
+
111
+ /**
112
+ * UNCOMMITTED: This API may change in the future
113
+ */
114
+ bucket_storage_backend storage_backend{ bucket_storage_backend::unknown };
115
+ };
116
+ } // namespace couchbase::management::cluster
@@ -17,14 +17,20 @@
17
17
 
18
18
  #pragma once
19
19
 
20
+ #include "core/impl/internal_manager_error_context.hxx"
20
21
  #include <couchbase/error_context.hxx>
21
22
 
22
23
  #include <cstdint>
24
+ #include <memory>
23
25
  #include <optional>
24
26
  #include <string>
25
27
 
26
28
  namespace couchbase
27
29
  {
30
+ #ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
31
+ class internal_manager_error_context;
32
+ #endif
33
+
28
34
  /**
29
35
  * The error context returned with manager operations.
30
36
  *
@@ -40,40 +46,25 @@ class manager_error_context : public error_context
40
46
  * @since 1.0.0
41
47
  * @committed
42
48
  */
43
- manager_error_context() = default;
49
+ manager_error_context();
50
+ explicit manager_error_context(internal_manager_error_context ctx);
51
+ manager_error_context(manager_error_context&& other);
52
+ manager_error_context& operator=(manager_error_context&& other);
53
+ manager_error_context(const manager_error_context& other) = delete;
54
+ manager_error_context& operator=(const manager_error_context& other) = delete;
55
+ ~manager_error_context() override;
44
56
 
45
- /**
46
- * Creates and initializes error context with given parameters.
47
- *
48
- * @param ec
49
- * @param last_dispatched_to
50
- * @param last_dispatched_from
51
- * @param retry_attempts
52
- * @param retry_reasons
53
- * @param client_context_id
54
- * @param http_status
55
- * @param content
56
- * @param path
57
- *
58
- * @since 1.0.0
59
- * @internal
60
- */
61
- manager_error_context(std::error_code ec,
62
- std::optional<std::string> last_dispatched_to,
63
- std::optional<std::string> last_dispatched_from,
64
- std::size_t retry_attempts,
65
- std::set<retry_reason> retry_reasons,
66
- std::string client_context_id,
67
- std::uint32_t http_status,
68
- std::string content,
69
- std::string path)
70
- : error_context{ ec, std::move(last_dispatched_to), std::move(last_dispatched_from), retry_attempts, std::move(retry_reasons) }
71
- , client_context_id_{ std::move(client_context_id) }
72
- , http_status_{ http_status }
73
- , content_{ std::move(content) }
74
- , path_{ std::move(path) }
75
- {
76
- }
57
+ [[nodiscard]] auto ec() const -> std::error_code override;
58
+
59
+ [[nodiscard]] auto last_dispatched_to() const -> const std::optional<std::string>& override;
60
+
61
+ [[nodiscard]] auto last_dispatched_from() const -> const std::optional<std::string>& override;
62
+
63
+ [[nodiscard]] auto retry_attempts() const -> std::size_t override;
64
+
65
+ [[nodiscard]] auto retry_reasons() const -> const std::set<retry_reason>& override;
66
+
67
+ [[nodiscard]] auto retried_because_of(retry_reason reason) const -> bool override;
77
68
 
78
69
  /**
79
70
  * Returns request path.
@@ -83,10 +74,7 @@ class manager_error_context : public error_context
83
74
  * @since 1.0.0
84
75
  * @uncommitted
85
76
  */
86
- [[nodiscard]] auto path() const -> const std::string&
87
- {
88
- return path_;
89
- }
77
+ [[nodiscard]] auto path() const -> const std::string&;
90
78
 
91
79
  /**
92
80
  * Returns response body.
@@ -96,10 +84,7 @@ class manager_error_context : public error_context
96
84
  * @since 1.0.0
97
85
  * @committed
98
86
  */
99
- [[nodiscard]] auto content() const -> const std::string&
100
- {
101
- return content_;
102
- }
87
+ [[nodiscard]] auto content() const -> const std::string&;
103
88
 
104
89
  /**
105
90
  * Returns the unique
@@ -109,10 +94,7 @@ class manager_error_context : public error_context
109
94
  * @since 1.0.0
110
95
  * @uncommitted
111
96
  */
112
- [[nodiscard]] auto client_context_id() const -> const std::string&
113
- {
114
- return client_context_id_;
115
- }
97
+ [[nodiscard]] auto client_context_id() const -> const std::string&;
116
98
 
117
99
  /**
118
100
  * Returns HTTP status of response
@@ -122,15 +104,9 @@ class manager_error_context : public error_context
122
104
  * @since 1.0.0
123
105
  * @committed
124
106
  */
125
- [[nodiscard]] auto http_status() const -> std::uint32_t
126
- {
127
- return http_status_;
128
- }
107
+ [[nodiscard]] auto http_status() const -> std::uint32_t;
129
108
 
130
109
  private:
131
- std::string client_context_id_{};
132
- std::uint32_t http_status_{};
133
- std::string content_{};
134
- std::string path_{};
110
+ std::unique_ptr<internal_manager_error_context> internal_;
135
111
  };
136
112
  } // namespace couchbase
@@ -225,8 +225,8 @@ initiate_mutate_in_operation(std::shared_ptr<couchbase::core::cluster> core,
225
225
  std::string collection_name,
226
226
  std::string document_key,
227
227
  const std::vector<couchbase::core::impl::subdoc::command>& specs,
228
- mutate_in_options::built options,
229
- mutate_in_handler&& handler);
228
+ couchbase::mutate_in_options::built options,
229
+ couchbase::mutate_in_handler&& handler);
230
230
  #endif
231
231
  } // namespace impl
232
232
  } // namespace core
@@ -57,7 +57,7 @@ class query_error_context : public error_context
57
57
  std::string http_body,
58
58
  std::string hostname,
59
59
  std::uint16_t port)
60
- : error_context{ ec, std::move(last_dispatched_to), std::move(last_dispatched_from), retry_attempts, std::move(retry_reasons) }
60
+ : error_context{ {}, ec, std::move(last_dispatched_to), std::move(last_dispatched_from), retry_attempts, std::move(retry_reasons) }
61
61
  , first_error_code_{ first_error_code }
62
62
  , first_error_message_{ std::move(first_error_message) }
63
63
  , client_context_id_{ std::move(client_context_id) }
@@ -127,6 +127,8 @@ class query_error_context : public error_context
127
127
  return port_;
128
128
  }
129
129
 
130
+ [[nodiscard]] auto to_json() const -> std::string;
131
+
130
132
  private:
131
133
  std::uint64_t first_error_code_{};
132
134
  std::string first_error_message_{};
@@ -61,19 +61,11 @@ class query_index_manager
61
61
  */
62
62
  void get_all_indexes(std::string bucket_name,
63
63
  const get_all_query_indexes_options& options,
64
- get_all_query_indexes_handler&& handler) const
65
- {
66
- return core::impl::initiate_get_all_query_indexes(
67
- core_, std::move(bucket_name), options.build(), std::forward<get_all_query_indexes_handler>(handler));
68
- }
64
+ get_all_query_indexes_handler&& handler) const;
65
+
69
66
  [[nodiscard]] auto get_all_indexes(std::string bucket_name, const get_all_query_indexes_options& options) const
70
- -> std::future<std::pair<manager_error_context, std::vector<couchbase::management::query::index>>>
71
- {
72
- auto barrier = std::make_shared<std::promise<std::pair<manager_error_context, std::vector<couchbase::management::query::index>>>>();
73
- auto future = barrier->get_future();
74
- get_all_indexes(std::move(bucket_name), options, [barrier](auto ctx, auto resp) { barrier->set_value({ ctx, resp }); });
75
- return future;
76
- }
67
+ -> std::future<std::pair<manager_error_context, std::vector<couchbase::management::query::index>>>;
68
+
77
69
  /**
78
70
  * Create an index on a bucket.
79
71
  *
@@ -90,23 +82,12 @@ class query_index_manager
90
82
  std::string index_name,
91
83
  std::vector<std::string> fields,
92
84
  const create_query_index_options& options,
93
- create_query_index_handler&& handler) const
94
- {
95
- core::impl::initiate_create_query_index(
96
- core_, std::move(bucket_name), std::move(index_name), std::move(fields), options.build(), std::move(handler));
97
- }
85
+ create_query_index_handler&& handler) const;
98
86
 
99
87
  [[nodiscard]] auto create_index(std::string bucket_name,
100
88
  std::string index_name,
101
89
  std::vector<std::string> fields,
102
- const create_query_index_options& options) const -> std::future<manager_error_context>
103
- {
104
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
105
- auto future = barrier->get_future();
106
- create_index(
107
- std::move(bucket_name), std::move(index_name), std::move(fields), options, [barrier](auto ctx) { barrier->set_value(ctx); });
108
- return future;
109
- }
90
+ const create_query_index_options& options) const -> std::future<manager_error_context>;
110
91
 
111
92
  /**
112
93
  * Create a primary index on a bucket.
@@ -120,19 +101,10 @@ class query_index_manager
120
101
  */
121
102
  void create_primary_index(std::string bucket_name,
122
103
  const create_primary_query_index_options& options,
123
- create_query_index_handler&& handler)
124
- {
125
- return core::impl::initiate_create_primary_query_index(core_, std::move(bucket_name), options.build(), std::move(handler));
126
- }
104
+ create_query_index_handler&& handler);
127
105
 
128
106
  [[nodiscard]] auto create_primary_index(std::string bucket_name, const create_primary_query_index_options& options)
129
- -> std::future<manager_error_context>
130
- {
131
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
132
- auto future = barrier->get_future();
133
- create_primary_index(std::move(bucket_name), options, [barrier](auto ctx) { barrier->set_value(ctx); });
134
- return future;
135
- }
107
+ -> std::future<manager_error_context>;
136
108
  /**
137
109
  * Drop primary index on a bucket.
138
110
  *
@@ -143,19 +115,10 @@ class query_index_manager
143
115
  * @since 1.0.0
144
116
  * @committed
145
117
  */
146
- void drop_primary_index(std::string bucket_name, const drop_primary_query_index_options& options, drop_query_index_handler&& handler)
147
- {
148
- return core::impl::initiate_drop_primary_query_index(core_, std::move(bucket_name), options.build(), std::move(handler));
149
- }
118
+ void drop_primary_index(std::string bucket_name, const drop_primary_query_index_options& options, drop_query_index_handler&& handler);
150
119
 
151
120
  [[nodiscard]] auto drop_primary_index(std::string bucket_name, const drop_primary_query_index_options& options)
152
- -> std::future<manager_error_context>
153
- {
154
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
155
- auto future = barrier->get_future();
156
- drop_primary_index(std::move(bucket_name), options, [barrier](auto ctx) { barrier->set_value(ctx); });
157
- return future;
158
- }
121
+ -> std::future<manager_error_context>;
159
122
 
160
123
  /**
161
124
  *
@@ -170,20 +133,10 @@ class query_index_manager
170
133
  void drop_index(std::string bucket_name,
171
134
  std::string index_name,
172
135
  const drop_query_index_options& options,
173
- drop_query_index_handler&& handler)
174
- {
175
- return core::impl::initiate_drop_query_index(
176
- core_, std::move(bucket_name), std::move(index_name), options.build(), std::move(handler));
177
- }
136
+ drop_query_index_handler&& handler);
178
137
 
179
138
  [[nodiscard]] auto drop_index(std::string bucket_name, std::string index_name, const drop_query_index_options& options)
180
- -> std::future<manager_error_context>
181
- {
182
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
183
- auto future = barrier->get_future();
184
- drop_index(std::move(bucket_name), std::move(index_name), options, [barrier](auto ctx) { barrier->set_value(ctx); });
185
- return future;
186
- }
139
+ -> std::future<manager_error_context>;
187
140
  /**
188
141
  * Builds all currently deferred indexes.
189
142
  *
@@ -198,20 +151,10 @@ class query_index_manager
198
151
  */
199
152
  void build_deferred_indexes(std::string bucket_name,
200
153
  const build_query_index_options& options,
201
- build_deferred_query_indexes_handler&& handler) const
202
- {
203
- return core::impl::initiate_build_deferred_indexes(
204
- core_, std::move(bucket_name), options.build(), std::forward<build_deferred_query_indexes_handler>(handler));
205
- }
154
+ build_deferred_query_indexes_handler&& handler) const;
206
155
 
207
156
  [[nodiscard]] auto build_deferred_indexes(std::string bucket_name, const build_query_index_options& options) const
208
- -> std::future<manager_error_context>
209
- {
210
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
211
- auto future = barrier->get_future();
212
- build_deferred_indexes(std::move(bucket_name), options, [barrier](auto ctx) { barrier->set_value(std::move(ctx)); });
213
- return future;
214
- }
157
+ -> std::future<manager_error_context>;
215
158
 
216
159
  /**
217
160
  * Polls the state of a set of indexes, until they all are online.
@@ -227,21 +170,11 @@ class query_index_manager
227
170
  void watch_indexes(std::string bucket_name,
228
171
  std::vector<std::string> index_names,
229
172
  const watch_query_indexes_options& options,
230
- watch_query_indexes_handler&& handler)
231
- {
232
- return core::impl::initiate_watch_query_indexes(
233
- core_, std::move(bucket_name), std::move(index_names), options.build(), std::move(handler));
234
- }
173
+ watch_query_indexes_handler&& handler);
235
174
 
236
175
  [[nodiscard]] auto watch_indexes(std::string bucket_name,
237
176
  std::vector<std::string> index_names,
238
- const watch_query_indexes_options& options)
239
- {
240
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
241
- auto future = barrier->get_future();
242
- watch_indexes(std::move(bucket_name), std::move(index_names), options, [barrier](auto ctx) { barrier->set_value(ctx); });
243
- return future;
244
- }
177
+ const watch_query_indexes_options& options) -> std::future<manager_error_context>;
245
178
 
246
179
  private:
247
180
  friend class cluster;
@@ -51,6 +51,7 @@ struct query_options : public common_options<query_options> {
51
51
  const bool readonly;
52
52
  const bool flex_index;
53
53
  const bool preserve_expiry;
54
+ std::optional<bool> use_replica;
54
55
  std::optional<std::uint64_t> max_parallelism;
55
56
  std::optional<std::uint64_t> scan_cap;
56
57
  std::optional<std::chrono::milliseconds> scan_wait;
@@ -84,6 +85,7 @@ struct query_options : public common_options<query_options> {
84
85
  readonly_,
85
86
  flex_index_,
86
87
  preserve_expiry_,
88
+ use_replica_,
87
89
  max_parallelism_,
88
90
  scan_cap_,
89
91
  scan_wait_,
@@ -225,6 +227,21 @@ struct query_options : public common_options<query_options> {
225
227
  return self();
226
228
  }
227
229
 
230
+ /**
231
+ * Specifies that the query engine should use replica nodes for KV fetches if the active node is down.
232
+ *
233
+ * @param use_replica whether replica nodes should be used if the active node is down. If not provided, the server default will be used.
234
+ * @return the options builder for chaining purposes.
235
+ *
236
+ * @since 1.0.0
237
+ * @committed
238
+ */
239
+ auto use_replica(bool use_replica) -> query_options&
240
+ {
241
+ use_replica_ = use_replica;
242
+ return self();
243
+ }
244
+
228
245
  /**
229
246
  * Allows overriding the default maximum parallelism for the query execution on the server side.
230
247
  *
@@ -529,6 +546,7 @@ struct query_options : public common_options<query_options> {
529
546
  bool readonly_{ false };
530
547
  bool flex_index_{ false };
531
548
  bool preserve_expiry_{ false };
549
+ std::optional<bool> use_replica_{};
532
550
  std::optional<std::uint64_t> max_parallelism_{};
533
551
  std::optional<std::uint64_t> scan_cap_{};
534
552
  std::optional<std::uint64_t> pipeline_batch_{};
@@ -115,8 +115,8 @@ initiate_remove_operation(std::shared_ptr<couchbase::core::cluster> core,
115
115
  std::string scope_name,
116
116
  std::string collection_name,
117
117
  std::string document_key,
118
- remove_options::built options,
119
- remove_handler&& handler);
118
+ couchbase::remove_options::built options,
119
+ couchbase::remove_handler&& handler);
120
120
  #endif
121
121
  } // namespace impl
122
122
  } // namespace core
@@ -175,9 +175,9 @@ initiate_replace_operation(std::shared_ptr<couchbase::core::cluster> core,
175
175
  std::string scope_name,
176
176
  std::string collection_name,
177
177
  std::string document_key,
178
- codec::encoded_value encoded,
179
- replace_options::built options,
180
- replace_handler&& handler);
178
+ couchbase::codec::encoded_value encoded,
179
+ couchbase::replace_options::built options,
180
+ couchbase::replace_handler&& handler);
181
181
  #endif
182
182
  } // namespace impl
183
183
  } // namespace core