couchbase 3.4.1 → 3.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/couchbase/CMakeLists.txt +2 -0
  4. data/ext/couchbase/cmake/ThirdPartyDependencies.cmake +4 -0
  5. data/ext/couchbase/core/cluster_options.hxx +0 -1
  6. data/ext/couchbase/core/config_profile.cxx +23 -1
  7. data/ext/couchbase/core/config_profile.hxx +2 -12
  8. data/ext/couchbase/core/impl/analytics.cxx +236 -0
  9. data/ext/couchbase/core/impl/cluster.cxx +0 -1
  10. data/ext/couchbase/core/impl/dns_srv_tracker.cxx +5 -3
  11. data/ext/couchbase/core/impl/query.cxx +5 -5
  12. data/ext/couchbase/core/io/dns_client.cxx +225 -0
  13. data/ext/couchbase/core/io/dns_client.hxx +19 -188
  14. data/ext/couchbase/core/transactions/active_transaction_record.hxx +2 -2
  15. data/ext/couchbase/core/transactions/attempt_context_impl.cxx +3 -0
  16. data/ext/couchbase/core/transactions/attempt_context_impl.hxx +1 -1
  17. data/ext/couchbase/core/transactions/internal/transaction_context.hxx +12 -12
  18. data/ext/couchbase/core/transactions/internal/transactions_cleanup.hxx +7 -1
  19. data/ext/couchbase/core/transactions/transaction_context.cxx +1 -0
  20. data/ext/couchbase/core/transactions/transactions_cleanup.cxx +144 -155
  21. data/ext/couchbase/core/utils/connection_string.cxx +10 -3
  22. data/ext/couchbase/core/utils/connection_string.hxx +3 -3
  23. data/ext/couchbase/couchbase/analytics_error_context.hxx +143 -0
  24. data/ext/couchbase/couchbase/analytics_meta_data.hxx +155 -0
  25. data/ext/couchbase/couchbase/analytics_metrics.hxx +163 -0
  26. data/ext/couchbase/couchbase/analytics_options.hxx +359 -0
  27. data/ext/couchbase/couchbase/analytics_result.hxx +102 -0
  28. data/ext/couchbase/couchbase/analytics_scan_consistency.hxx +46 -0
  29. data/ext/couchbase/couchbase/analytics_status.hxx +41 -0
  30. data/ext/couchbase/couchbase/analytics_warning.hxx +85 -0
  31. data/ext/couchbase/couchbase/cluster.hxx +33 -0
  32. data/ext/couchbase/couchbase/fmt/analytics_status.hxx +76 -0
  33. data/ext/couchbase/couchbase/query_options.hxx +0 -1
  34. data/ext/couchbase/couchbase/scope.hxx +33 -0
  35. data/ext/couchbase/couchbase/transactions/attempt_context.hxx +1 -1
  36. data/ext/couchbase/test/CMakeLists.txt +1 -2
  37. data/ext/couchbase/test/test_helper.hxx +1 -1
  38. data/ext/couchbase/test/test_integration_analytics.cxx +289 -13
  39. data/ext/couchbase/test/test_integration_crud.cxx +8 -1
  40. data/ext/couchbase/test/test_integration_examples.cxx +41 -0
  41. data/ext/couchbase/test/test_integration_management.cxx +15 -3
  42. data/ext/couchbase/test/test_integration_search.cxx +601 -0
  43. data/ext/couchbase/test/test_transaction_transaction_simple.cxx +73 -0
  44. data/ext/couchbase/test/test_unit_config_profiles.cxx +12 -12
  45. data/ext/couchbase/test/test_unit_connection_string.cxx +35 -0
  46. data/ext/couchbase/third_party/snappy/CMakeLists.txt +150 -27
  47. data/ext/couchbase/third_party/snappy/cmake/config.h.in +28 -24
  48. data/ext/couchbase/third_party/snappy/snappy-internal.h +189 -25
  49. data/ext/couchbase/third_party/snappy/snappy-sinksource.cc +26 -9
  50. data/ext/couchbase/third_party/snappy/snappy-sinksource.h +11 -11
  51. data/ext/couchbase/third_party/snappy/snappy-stubs-internal.cc +1 -1
  52. data/ext/couchbase/third_party/snappy/snappy-stubs-internal.h +227 -308
  53. data/ext/couchbase/third_party/snappy/snappy-stubs-public.h.in +0 -11
  54. data/ext/couchbase/third_party/snappy/snappy.cc +1176 -410
  55. data/ext/couchbase/third_party/snappy/snappy.h +19 -4
  56. data/ext/couchbase.cxx +27 -6
  57. data/ext/revisions.rb +3 -3
  58. data/lib/couchbase/cluster.rb +13 -9
  59. data/lib/couchbase/cluster_registry.rb +7 -2
  60. data/lib/couchbase/configuration.rb +3 -4
  61. data/lib/couchbase/options.rb +85 -2
  62. data/lib/couchbase/search_options.rb +158 -240
  63. data/lib/couchbase/version.rb +1 -1
  64. metadata +17 -6
  65. data/ext/couchbase/core/CMakeLists.txt +0 -0
@@ -0,0 +1,102 @@
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/analytics_meta_data.hxx>
21
+ #include <couchbase/codec/tao_json_serializer.hxx>
22
+
23
+ #include <chrono>
24
+ #include <cinttypes>
25
+ #include <optional>
26
+ #include <vector>
27
+
28
+ namespace couchbase
29
+ {
30
+
31
+ /**
32
+ * Represents result of @ref cluster#analytics_query() and @ref scope#analytics_query() calls.
33
+ *
34
+ * @since 1.0.0
35
+ * @committed
36
+ */
37
+ class analytics_result
38
+ {
39
+ public:
40
+ /**
41
+ * @since 1.0.0
42
+ * @internal
43
+ */
44
+ analytics_result() = default;
45
+
46
+ /**
47
+ * @since 1.0.0
48
+ * @volatile
49
+ */
50
+ analytics_result(analytics_meta_data meta_data, std::vector<codec::binary> rows)
51
+ : meta_data_{ std::move(meta_data) }
52
+ , rows_{ std::move(rows) }
53
+ {
54
+ }
55
+
56
+ /**
57
+ * Returns the {@link analytics_meta_data} giving access to the additional metadata associated with this analytics query.
58
+ *
59
+ * @return response metadata
60
+ *
61
+ * @since 1.0.0
62
+ * @committed
63
+ */
64
+ [[nodiscard]] auto meta_data() const -> const analytics_meta_data&
65
+ {
66
+ return meta_data_;
67
+ }
68
+
69
+ /**
70
+ * @return list of analytics results as binary strings
71
+ *
72
+ * @since 1.0.0
73
+ * @internal
74
+ */
75
+ [[nodiscard]] auto rows_as_binary() const -> const std::vector<codec::binary>&
76
+ {
77
+ return rows_;
78
+ }
79
+
80
+ template<typename Serializer,
81
+ typename Document = typename Serializer::document_type,
82
+ std::enable_if_t<codec::is_serializer_v<Serializer>, bool> = true>
83
+ [[nodiscard]] auto rows_as() const -> std::vector<Document>
84
+ {
85
+ std::vector<Document> rows;
86
+ rows.reserve(rows_.size());
87
+ for (const auto& row : rows_) {
88
+ rows.emplace_back(Serializer::template deserialize<Document>(row));
89
+ }
90
+ return rows;
91
+ }
92
+
93
+ [[nodiscard]] auto rows_as_json() const -> std::vector<codec::tao_json_serializer::document_type>
94
+ {
95
+ return rows_as<codec::tao_json_serializer>();
96
+ }
97
+
98
+ private:
99
+ analytics_meta_data meta_data_{};
100
+ std::vector<codec::binary> rows_{};
101
+ };
102
+ } // namespace couchbase
@@ -0,0 +1,46 @@
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
+ namespace couchbase
21
+ {
22
+ enum class analytics_scan_consistency {
23
+ /**
24
+ * The indexer will return whatever state it has to the query engine at the time of query.
25
+ *
26
+ * This is the default (for single-statement requests). No timestamp vector is used in the index scan. This is also the fastest mode,
27
+ * because we avoid the cost of obtaining the vector, and we also avoid any wait for the index to catch up to the vector.
28
+ *
29
+ * @since 1.0.0
30
+ * @committed
31
+ */
32
+ not_bounded = 0,
33
+
34
+ /**
35
+ * The indexer will wait until all mutations have been processed at the time of request before returning to the query engine.
36
+ *
37
+ * This implements strong consistency per request. Before processing the request, a current vector is obtained. The vector is used as a
38
+ * lower bound for the statements in the request. If there are DML statements in the request, RYOW ("read your own write") is also
39
+ * applied within the request.
40
+ *
41
+ * @since 1.0.0
42
+ * @committed
43
+ */
44
+ request_plus,
45
+ };
46
+ } // namespace couchbase
@@ -0,0 +1,41 @@
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
+ namespace couchbase
21
+ {
22
+ /**
23
+ * Status of the Analytics Query
24
+ *
25
+ * @since 1.0.0
26
+ * @committed
27
+ */
28
+ enum class analytics_status {
29
+ running,
30
+ success,
31
+ errors,
32
+ completed,
33
+ stopped,
34
+ timeout,
35
+ closed,
36
+ fatal,
37
+ aborted,
38
+ unknown,
39
+ };
40
+
41
+ } // namespace couchbase
@@ -0,0 +1,85 @@
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 <cstdint>
21
+ #include <optional>
22
+ #include <string>
23
+
24
+ namespace couchbase
25
+ {
26
+
27
+ /**
28
+ * Represents a single warning returned from the analytics engine.
29
+ *
30
+ * @note warnings are not terminal errors but hints from the engine that something was not as expected.
31
+ *
32
+ * @since 1.0.0
33
+ * @committed
34
+ */
35
+ class analytics_warning
36
+ {
37
+ public:
38
+ /**
39
+ * @since 1.0.0
40
+ * @internal
41
+ */
42
+ analytics_warning() = default;
43
+
44
+ /**
45
+ * @since 1.0.0
46
+ * @volatile
47
+ */
48
+ analytics_warning(std::uint64_t code, std::string message)
49
+ : code_{ code }
50
+ , message_{ std::move(message) }
51
+ {
52
+ }
53
+
54
+ /**
55
+ * Error code.
56
+ *
57
+ * @return error code
58
+ *
59
+ * @since 1.0.0
60
+ * @committed
61
+ */
62
+ [[nodiscard]] auto code() const -> std::uint64_t
63
+ {
64
+ return code_;
65
+ }
66
+
67
+ /**
68
+ * Error message.
69
+ *
70
+ * @return human readable explanation
71
+ *
72
+ * @since 1.0.0
73
+ * @committed
74
+ */
75
+ [[nodiscard]] auto message() const -> const std::string&
76
+ {
77
+ return message_;
78
+ }
79
+
80
+ private:
81
+ std::uint64_t code_{};
82
+ std::string message_{};
83
+ };
84
+
85
+ } // namespace couchbase
@@ -17,6 +17,7 @@
17
17
 
18
18
  #pragma once
19
19
 
20
+ #include <couchbase/analytics_options.hxx>
20
21
  #include <couchbase/bucket.hxx>
21
22
  #include <couchbase/cluster_options.hxx>
22
23
  #include <couchbase/query_index_manager.hxx>
@@ -165,6 +166,38 @@ class cluster
165
166
  return future;
166
167
  }
167
168
 
169
+ /**
170
+ * Performs a query against the analytics services.
171
+ *
172
+ * @param statement the query statement.
173
+ * @param options options to customize the query request.
174
+ * @param handler the handler that implements @ref query_handler
175
+ *
176
+ * @exception errc::common::ambiguous_timeout
177
+ * @exception errc::common::unambiguous_timeout
178
+ *
179
+ * @see https://docs.couchbase.com/server/current/analytics/introduction.html
180
+ *
181
+ * @since 1.0.0
182
+ * @committed
183
+ */
184
+ void analytics_query(std::string statement, const analytics_options& options, analytics_handler&& handler) const;
185
+
186
+ /**
187
+ * Performs a query against the analytics services.
188
+ *
189
+ * @param statement the query statement.
190
+ * @param options options to customize the query request.
191
+ * @return future object that carries result of the operation
192
+ *
193
+ * @see https://docs.couchbase.com/server/current/analytics/introduction.html
194
+ *
195
+ * @since 1.0.0
196
+ * @committed
197
+ */
198
+ [[nodiscard]] auto analytics_query(std::string statement, const analytics_options& options = {}) const
199
+ -> std::future<std::pair<analytics_error_context, analytics_result>>;
200
+
168
201
  /**
169
202
  * Provides access to the N1QL index management services.
170
203
  *
@@ -0,0 +1,76 @@
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/analytics_status.hxx>
21
+
22
+ #include <fmt/core.h>
23
+
24
+ /**
25
+ * Helper for fmtlib to format @ref couchbase::analytics_status objects.
26
+ *
27
+ * @since 1.0.0
28
+ * @committed
29
+ */
30
+ template<>
31
+ struct fmt::formatter<couchbase::analytics_status> {
32
+ template<typename ParseContext>
33
+ constexpr auto parse(ParseContext& ctx)
34
+ {
35
+ return ctx.begin();
36
+ }
37
+
38
+ template<typename FormatContext>
39
+ auto format(couchbase::analytics_status status, FormatContext& ctx) const
40
+ {
41
+ string_view name = "unknown";
42
+ switch (status) {
43
+ case couchbase::analytics_status::running:
44
+ name = "running";
45
+ break;
46
+ case couchbase::analytics_status::success:
47
+ name = "success";
48
+ break;
49
+ case couchbase::analytics_status::errors:
50
+ name = "errors";
51
+ break;
52
+ case couchbase::analytics_status::completed:
53
+ name = "completed";
54
+ break;
55
+ case couchbase::analytics_status::stopped:
56
+ name = "stopped";
57
+ break;
58
+ case couchbase::analytics_status::timeout:
59
+ name = "timeout";
60
+ break;
61
+ case couchbase::analytics_status::closed:
62
+ name = "closed";
63
+ break;
64
+ case couchbase::analytics_status::fatal:
65
+ name = "fatal";
66
+ break;
67
+ case couchbase::analytics_status::aborted:
68
+ name = "aborted";
69
+ break;
70
+ case couchbase::analytics_status::unknown:
71
+ name = "unknown";
72
+ break;
73
+ }
74
+ return format_to(ctx.out(), "{}", name);
75
+ }
76
+ };
@@ -19,7 +19,6 @@
19
19
 
20
20
  #include <couchbase/codec/tao_json_serializer.hxx>
21
21
  #include <couchbase/common_options.hxx>
22
- #include <couchbase/key_value_error_context.hxx>
23
22
  #include <couchbase/mutation_state.hxx>
24
23
  #include <couchbase/query_error_context.hxx>
25
24
  #include <couchbase/query_profile.hxx>
@@ -17,6 +17,7 @@
17
17
 
18
18
  #pragma once
19
19
 
20
+ #include <couchbase/analytics_options.hxx>
20
21
  #include <couchbase/query_options.hxx>
21
22
 
22
23
  #include <memory>
@@ -132,6 +133,38 @@ class scope
132
133
  return future;
133
134
  }
134
135
 
136
+ /**
137
+ * Performs a query against the analytics services.
138
+ *
139
+ * @param statement the query statement.
140
+ * @param options options to customize the query request.
141
+ * @param handler the handler that implements @ref query_handler
142
+ *
143
+ * @exception errc::common::ambiguous_timeout
144
+ * @exception errc::common::unambiguous_timeout
145
+ *
146
+ * @see https://docs.couchbase.com/server/current/analytics/introduction.html
147
+ *
148
+ * @since 1.0.0
149
+ * @committed
150
+ */
151
+ void analytics_query(std::string statement, const analytics_options& options, analytics_handler&& handler) const;
152
+
153
+ /**
154
+ * Performs a query against the analytics services.
155
+ *
156
+ * @param statement the query statement.
157
+ * @param options options to customize the query request.
158
+ * @return future object that carries result of the operation
159
+ *
160
+ * @see https://docs.couchbase.com/server/current/analytics/introduction.html
161
+ *
162
+ * @since 1.0.0
163
+ * @committed
164
+ */
165
+ [[nodiscard]] auto analytics_query(std::string statement, const analytics_options& options = {}) const
166
+ -> std::future<std::pair<analytics_error_context, analytics_result>>;
167
+
135
168
  private:
136
169
  friend class bucket;
137
170
 
@@ -33,7 +33,7 @@ class attempt_context
33
33
  const Content& content)
34
34
  {
35
35
  if constexpr (std::is_same_v<Content, std::vector<std::byte>>) {
36
- return insert_raw(content, id, content);
36
+ return insert_raw(coll, id, content);
37
37
  } else {
38
38
  return insert_raw(coll, id, codec::tao_json_serializer::serialize(content));
39
39
  }
@@ -16,6 +16,7 @@ integration_test(tracer)
16
16
  integration_test(meter)
17
17
  integration_test(transcoders)
18
18
  integration_test(range_scan)
19
+ integration_test(search)
19
20
 
20
21
  unit_test(connection_string)
21
22
  unit_test(utils)
@@ -28,8 +29,6 @@ target_link_libraries(test_unit_jsonsl jsonsl)
28
29
 
29
30
  integration_benchmark(get)
30
31
 
31
- add_subdirectory(tools)
32
-
33
32
  transaction_test(transaction_context)
34
33
  transaction_test(transaction_simple)
35
34
  transaction_test(transaction_simple_async)
@@ -21,7 +21,7 @@
21
21
 
22
22
  #include "utils/binary.hxx"
23
23
  #include "utils/test_context.hxx"
24
- #include "utils/uniq_id.hxx"
24
+ #include "utils/test_data.hxx"
25
25
 
26
26
  #include <catch2/catch.hpp>
27
27