couchbase 3.4.2 → 3.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/couchbase/CMakeLists.txt +57 -7
- data/ext/couchbase/cmake/Documentation.cmake +0 -1
- data/ext/couchbase/cmake/OpenSSL.cmake +98 -3
- data/ext/couchbase/cmake/Testing.cmake +12 -4
- data/ext/couchbase/cmake/build_config.hxx.in +3 -0
- data/ext/couchbase/core/bucket.cxx +3 -2
- data/ext/couchbase/core/bucket.hxx +9 -0
- data/ext/couchbase/core/cluster.hxx +17 -0
- data/ext/couchbase/core/cluster_options.cxx +2 -2
- data/ext/couchbase/core/cluster_options.hxx +4 -6
- data/ext/couchbase/core/cluster_options_fwd.hxx +26 -0
- data/ext/couchbase/core/config_profile.hxx +1 -54
- data/ext/couchbase/core/config_profiles.cxx +79 -0
- data/ext/couchbase/core/config_profiles.hxx +56 -0
- data/ext/couchbase/core/error_context/search.hxx +1 -1
- data/ext/couchbase/core/impl/analytics.cxx +1 -0
- data/ext/couchbase/core/impl/boolean_field_query.cxx +40 -0
- data/ext/couchbase/core/impl/boolean_query.cxx +62 -0
- data/ext/couchbase/core/impl/cluster.cxx +2 -0
- data/ext/couchbase/core/impl/conjunction_query.cxx +51 -0
- data/ext/couchbase/core/impl/date_range.cxx +89 -0
- data/ext/couchbase/core/impl/date_range_facet.cxx +54 -0
- data/ext/couchbase/core/impl/date_range_facet_result.cxx +64 -0
- data/ext/couchbase/core/impl/date_range_query.cxx +125 -0
- data/ext/couchbase/core/impl/disjunction_query.cxx +51 -0
- data/ext/couchbase/core/impl/encoded_search_facet.hxx +29 -0
- data/ext/couchbase/core/impl/encoded_search_query.hxx +29 -0
- data/ext/couchbase/core/impl/encoded_search_sort.hxx +29 -0
- data/ext/couchbase/core/impl/geo_bounding_box_query.cxx +46 -0
- data/ext/couchbase/core/impl/geo_distance_query.cxx +43 -0
- data/ext/couchbase/core/impl/geo_polygon_query.cxx +46 -0
- data/ext/couchbase/core/impl/internal_date_range_facet_result.cxx +80 -0
- data/ext/couchbase/core/impl/internal_date_range_facet_result.hxx +48 -0
- data/ext/couchbase/core/impl/internal_numeric_range_facet_result.cxx +80 -0
- data/ext/couchbase/core/impl/internal_numeric_range_facet_result.hxx +48 -0
- data/ext/couchbase/core/impl/internal_search_error_context.cxx +141 -0
- data/ext/couchbase/core/impl/internal_search_error_context.hxx +61 -0
- data/ext/couchbase/core/impl/internal_search_meta_data.cxx +60 -0
- data/ext/couchbase/core/impl/internal_search_meta_data.hxx +41 -0
- data/ext/couchbase/core/impl/internal_search_result.cxx +84 -0
- data/ext/couchbase/core/impl/internal_search_result.hxx +43 -0
- data/ext/couchbase/core/impl/internal_search_row.cxx +82 -0
- data/ext/couchbase/core/impl/internal_search_row.hxx +56 -0
- data/ext/couchbase/core/impl/internal_search_row_location.hxx +32 -0
- data/ext/couchbase/core/impl/internal_search_row_locations.cxx +137 -0
- data/ext/couchbase/core/impl/internal_search_row_locations.hxx +45 -0
- data/ext/couchbase/core/impl/internal_term_facet_result.cxx +80 -0
- data/ext/couchbase/core/impl/internal_term_facet_result.hxx +48 -0
- data/ext/couchbase/core/impl/match_all_query.cxx +35 -0
- data/ext/couchbase/core/impl/match_none_query.cxx +35 -0
- data/ext/couchbase/core/impl/match_phrase_query.cxx +43 -0
- data/ext/couchbase/core/impl/match_query.cxx +59 -0
- data/ext/couchbase/core/impl/numeric_range.cxx +49 -0
- data/ext/couchbase/core/impl/numeric_range_facet.cxx +54 -0
- data/ext/couchbase/core/impl/numeric_range_facet_result.cxx +64 -0
- data/ext/couchbase/core/impl/numeric_range_query.cxx +56 -0
- data/ext/couchbase/core/impl/phrase_query.cxx +42 -0
- data/ext/couchbase/core/impl/prefix_query.cxx +40 -0
- data/ext/couchbase/core/impl/query_string_query.cxx +37 -0
- data/ext/couchbase/core/impl/regexp_query.cxx +40 -0
- data/ext/couchbase/core/impl/search.cxx +191 -0
- data/ext/couchbase/core/impl/search_error_context.cxx +147 -0
- data/ext/couchbase/core/impl/search_meta_data.cxx +46 -0
- data/ext/couchbase/core/impl/search_result.cxx +66 -0
- data/ext/couchbase/core/impl/search_row.cxx +74 -0
- data/ext/couchbase/core/impl/search_row_location.cxx +64 -0
- data/ext/couchbase/core/impl/search_row_locations.cxx +66 -0
- data/ext/couchbase/core/impl/search_sort_field.cxx +104 -0
- data/ext/couchbase/core/impl/search_sort_id.cxx +43 -0
- data/ext/couchbase/core/impl/search_sort_score.cxx +43 -0
- data/ext/couchbase/core/impl/term_facet.cxx +36 -0
- data/ext/couchbase/core/impl/term_facet_result.cxx +64 -0
- data/ext/couchbase/core/impl/term_query.cxx +56 -0
- data/ext/couchbase/core/impl/term_range_query.cxx +57 -0
- data/ext/couchbase/core/impl/wildcard_query.cxx +40 -0
- data/ext/couchbase/core/io/http_context.hxx +1 -1
- data/ext/couchbase/core/io/http_session.hxx +10 -0
- data/ext/couchbase/core/io/http_session_manager.hxx +5 -3
- data/ext/couchbase/core/io/mcbp_session.cxx +28 -1
- data/ext/couchbase/core/io/retry_orchestrator.hxx +3 -2
- data/ext/couchbase/core/json_string.hxx +5 -0
- data/ext/couchbase/core/meta/version.cxx +18 -4
- data/ext/couchbase/core/mozilla_ca_bundle.hxx +39 -0
- data/ext/couchbase/core/operations/document_analytics.cxx +1 -0
- data/ext/couchbase/core/operations/document_analytics.hxx +1 -0
- data/ext/couchbase/core/operations/document_append.hxx +1 -1
- data/ext/couchbase/core/operations/document_decrement.hxx +1 -1
- data/ext/couchbase/core/operations/document_exists.hxx +1 -1
- data/ext/couchbase/core/operations/document_get.hxx +1 -1
- data/ext/couchbase/core/operations/document_get_and_lock.hxx +1 -1
- data/ext/couchbase/core/operations/document_get_and_touch.hxx +1 -1
- data/ext/couchbase/core/operations/document_get_projected.hxx +1 -1
- data/ext/couchbase/core/operations/document_increment.hxx +1 -1
- data/ext/couchbase/core/operations/document_insert.hxx +1 -1
- data/ext/couchbase/core/operations/document_lookup_in.hxx +1 -1
- data/ext/couchbase/core/operations/document_mutate_in.hxx +1 -1
- data/ext/couchbase/core/operations/document_prepend.hxx +1 -1
- data/ext/couchbase/core/operations/document_query.cxx +2 -0
- data/ext/couchbase/core/operations/document_query.hxx +6 -0
- data/ext/couchbase/core/operations/document_remove.hxx +1 -1
- data/ext/couchbase/core/operations/document_replace.hxx +1 -1
- data/ext/couchbase/core/operations/document_search.cxx +4 -1
- data/ext/couchbase/core/operations/document_search.hxx +2 -1
- data/ext/couchbase/core/operations/document_touch.hxx +1 -1
- data/ext/couchbase/core/operations/document_unlock.hxx +1 -1
- data/ext/couchbase/core/operations/document_upsert.hxx +1 -1
- data/ext/couchbase/core/operations/document_view.hxx +1 -0
- data/ext/couchbase/core/protocol/client_request.hxx +11 -2
- data/ext/couchbase/core/public_fwd.hxx +21 -0
- data/ext/couchbase/core/tls_verify_mode.hxx +26 -0
- data/ext/couchbase/core/topology/configuration.cxx +15 -2
- data/ext/couchbase/core/topology/configuration.hxx +5 -1
- data/ext/couchbase/core/transactions/attempt_context_testing_hooks.cxx +93 -0
- data/ext/couchbase/core/transactions/attempt_context_testing_hooks.hxx +48 -75
- data/ext/couchbase/core/transactions/cleanup_testing_hooks.cxx +52 -0
- data/ext/couchbase/core/transactions/cleanup_testing_hooks.hxx +17 -31
- data/ext/couchbase/core/transactions/exceptions.hxx +12 -9
- data/ext/couchbase/core/utils/connection_string.cxx +17 -0
- data/ext/couchbase/core/utils/json.cxx +4 -1
- data/ext/couchbase/couchbase/behavior_options.hxx +10 -1
- data/ext/couchbase/couchbase/boolean_field_query.hxx +77 -0
- data/ext/couchbase/couchbase/boolean_query.hxx +223 -0
- data/ext/couchbase/couchbase/cluster.hxx +42 -1
- data/ext/couchbase/couchbase/conjunction_query.hxx +88 -0
- data/ext/couchbase/couchbase/date_range.hxx +69 -0
- data/ext/couchbase/couchbase/date_range_facet.hxx +56 -0
- data/ext/couchbase/couchbase/date_range_facet_result.hxx +55 -0
- data/ext/couchbase/couchbase/date_range_query.hxx +265 -0
- data/ext/couchbase/couchbase/disjunction_query.hxx +109 -0
- data/ext/couchbase/couchbase/doc_id_query.hxx +111 -0
- data/ext/couchbase/couchbase/error_context.hxx +7 -6
- data/ext/couchbase/couchbase/fmt/analytics_scan_consistency.hxx +52 -0
- data/ext/couchbase/couchbase/fmt/search_scan_consistency.hxx +49 -0
- data/ext/couchbase/couchbase/geo_bounding_box_query.hxx +107 -0
- data/ext/couchbase/couchbase/geo_distance_query.hxx +109 -0
- data/ext/couchbase/couchbase/geo_point.hxx +32 -0
- data/ext/couchbase/couchbase/geo_polygon_query.hxx +85 -0
- data/ext/couchbase/couchbase/highlight_style.hxx +45 -0
- data/ext/couchbase/couchbase/match_all_query.hxx +43 -0
- data/ext/couchbase/couchbase/match_none_query.hxx +43 -0
- data/ext/couchbase/couchbase/match_operator.hxx +45 -0
- data/ext/couchbase/couchbase/match_phrase_query.hxx +108 -0
- data/ext/couchbase/couchbase/match_query.hxx +163 -0
- data/ext/couchbase/couchbase/numeric_range.hxx +58 -0
- data/ext/couchbase/couchbase/numeric_range_facet.hxx +56 -0
- data/ext/couchbase/couchbase/numeric_range_facet_result.hxx +55 -0
- data/ext/couchbase/couchbase/numeric_range_query.hxx +143 -0
- data/ext/couchbase/couchbase/phrase_query.hxx +93 -0
- data/ext/couchbase/couchbase/prefix_query.hxx +82 -0
- data/ext/couchbase/couchbase/query_string_query.hxx +72 -0
- data/ext/couchbase/couchbase/regexp_query.hxx +82 -0
- data/ext/couchbase/couchbase/scope.hxx +40 -0
- data/ext/couchbase/couchbase/search_date_range.hxx +68 -0
- data/ext/couchbase/couchbase/search_error_context.hxx +138 -0
- data/ext/couchbase/couchbase/search_facet.hxx +60 -0
- data/ext/couchbase/couchbase/search_facet_result.hxx +50 -0
- data/ext/couchbase/couchbase/search_meta_data.hxx +85 -0
- data/ext/couchbase/couchbase/search_metrics.hxx +127 -0
- data/ext/couchbase/couchbase/search_numeric_range.hxx +69 -0
- data/ext/couchbase/couchbase/search_options.hxx +509 -0
- data/ext/couchbase/couchbase/search_query.hxx +69 -0
- data/ext/couchbase/couchbase/search_result.hxx +77 -0
- data/ext/couchbase/couchbase/search_row.hxx +104 -0
- data/ext/couchbase/couchbase/search_row_location.hxx +55 -0
- data/ext/couchbase/couchbase/search_row_locations.hxx +86 -0
- data/ext/couchbase/couchbase/search_scan_consistency.hxx +34 -0
- data/ext/couchbase/couchbase/search_sort.hxx +58 -0
- data/ext/couchbase/couchbase/search_sort_field.hxx +117 -0
- data/ext/couchbase/couchbase/search_sort_field_missing.hxx +26 -0
- data/ext/couchbase/couchbase/search_sort_field_mode.hxx +27 -0
- data/ext/couchbase/couchbase/search_sort_field_type.hxx +28 -0
- data/ext/couchbase/couchbase/search_sort_id.hxx +60 -0
- data/ext/couchbase/couchbase/search_sort_score.hxx +60 -0
- data/ext/couchbase/couchbase/search_term_range.hxx +51 -0
- data/ext/couchbase/couchbase/security_options.hxx +3 -0
- data/ext/couchbase/couchbase/term_facet.hxx +48 -0
- data/ext/couchbase/couchbase/term_facet_result.hxx +55 -0
- data/ext/couchbase/couchbase/term_query.hxx +151 -0
- data/ext/couchbase/couchbase/term_range_query.hxx +142 -0
- data/ext/couchbase/couchbase/tracing/request_span.hxx +63 -0
- data/ext/couchbase/couchbase/tracing/request_tracer.hxx +2 -40
- data/ext/couchbase/couchbase/transactions/async_attempt_context.hxx +83 -4
- data/ext/couchbase/couchbase/transactions/attempt_context.hxx +67 -0
- data/ext/couchbase/couchbase/transactions/transaction_get_result.hxx +2 -0
- data/ext/couchbase/couchbase/transactions/transaction_keyspace.hxx +11 -1
- data/ext/couchbase/couchbase/transactions/transaction_options.hxx +79 -8
- data/ext/couchbase/couchbase/transactions/transaction_query_options.hxx +128 -15
- data/ext/couchbase/couchbase/transactions/transaction_query_result.hxx +4 -0
- data/ext/couchbase/couchbase/transactions/transaction_result.hxx +1 -1
- data/ext/couchbase/couchbase/transactions/transactions_cleanup_config.hxx +5 -3
- data/ext/couchbase/couchbase/transactions/transactions_config.hxx +9 -5
- data/ext/couchbase/couchbase/transactions/transactions_query_config.hxx +6 -3
- data/ext/couchbase/couchbase/transactions.hxx +34 -1
- data/ext/couchbase/couchbase/wildcard_query.hxx +83 -0
- data/ext/couchbase/test/CMakeLists.txt +7 -5
- data/ext/couchbase/test/benchmark_helper_integration.hxx +2 -2
- data/ext/couchbase/test/test_helper.hxx +5 -5
- data/ext/couchbase/test/test_integration_analytics.cxx +28 -6
- data/ext/couchbase/test/test_integration_collections.cxx +7 -3
- data/ext/couchbase/test/test_integration_connect.cxx +7 -3
- data/ext/couchbase/test/test_integration_crud.cxx +13 -3
- data/ext/couchbase/test/test_integration_diagnostics.cxx +11 -5
- data/ext/couchbase/test/test_integration_durability.cxx +12 -7
- data/ext/couchbase/test/test_integration_examples.cxx +283 -11
- data/ext/couchbase/test/test_integration_management.cxx +147 -91
- data/ext/couchbase/test/test_integration_query.cxx +68 -10
- data/ext/couchbase/test/test_integration_range_scan.cxx +12 -12
- data/ext/couchbase/test/test_integration_read_replica.cxx +48 -11
- data/ext/couchbase/test/test_integration_search.cxx +22 -2
- data/ext/couchbase/test/test_integration_subdoc.cxx +62 -11
- data/ext/couchbase/test/test_integration_tracer.cxx +5 -0
- data/ext/couchbase/test/test_integration_transcoders.cxx +13 -5
- data/ext/couchbase/test/{test_transaction_transaction_context.cxx → test_transaction_context.cxx} +1 -1
- data/ext/couchbase/test/test_transaction_examples.cxx +195 -0
- data/ext/couchbase/test/{test_transaction_transaction_simple.cxx → test_transaction_simple.cxx} +17 -5
- data/ext/couchbase/test/{test_transaction_transaction_simple_async.cxx → test_transaction_simple_async.cxx} +19 -21
- data/ext/couchbase/test/test_unit_config_profiles.cxx +1 -1
- data/ext/couchbase/test/test_unit_json_transcoder.cxx +4 -0
- data/ext/couchbase/test/test_unit_search.cxx +427 -0
- data/ext/couchbase/test/test_unit_transaction_utils.cxx +10 -1
- data/ext/couchbase/test/test_unit_utils.cxx +8 -4
- data/ext/couchbase.cxx +58 -16
- data/ext/revisions.rb +3 -3
- data/lib/couchbase/authenticator.rb +0 -1
- data/lib/couchbase/cluster.rb +0 -4
- data/lib/couchbase/config_profiles.rb +1 -1
- data/lib/couchbase/json_transcoder.rb +12 -5
- data/lib/couchbase/management/collection_query_index_manager.rb +54 -15
- data/lib/couchbase/management/query_index_manager.rb +70 -5
- data/lib/couchbase/raw_binary_transcoder.rb +37 -0
- data/lib/couchbase/raw_json_transcoder.rb +38 -0
- data/lib/couchbase/raw_string_transcoder.rb +40 -0
- data/lib/couchbase/search_options.rb +5 -0
- data/lib/couchbase/transcoder_flags.rb +62 -0
- data/lib/couchbase/version.rb +1 -1
- metadata +139 -11
- data/ext/couchbase/core/config_profile.cxx +0 -47
- /data/ext/couchbase/test/{test_transaction_transaction_public_async_api.cxx → test_transaction_public_async_api.cxx} +0 -0
- /data/ext/couchbase/test/{test_transaction_transaction_public_blocking_api.cxx → test_transaction_public_blocking_api.cxx} +0 -0
@@ -17,51 +17,13 @@
|
|
17
17
|
|
18
18
|
#pragma once
|
19
19
|
|
20
|
+
#include "request_span.hxx"
|
21
|
+
|
20
22
|
#include <memory>
|
21
23
|
#include <string>
|
22
24
|
|
23
25
|
namespace couchbase::tracing
|
24
26
|
{
|
25
|
-
|
26
|
-
class request_span
|
27
|
-
{
|
28
|
-
public:
|
29
|
-
request_span() = default;
|
30
|
-
request_span(const request_span& other) = default;
|
31
|
-
request_span(request_span&& other) = default;
|
32
|
-
request_span& operator=(const request_span& other) = default;
|
33
|
-
request_span& operator=(request_span&& other) = default;
|
34
|
-
virtual ~request_span() = default;
|
35
|
-
|
36
|
-
explicit request_span(std::string name)
|
37
|
-
: name_(std::move(name))
|
38
|
-
, parent_(nullptr)
|
39
|
-
{
|
40
|
-
}
|
41
|
-
request_span(std::string name, std::shared_ptr<request_span> parent)
|
42
|
-
: name_(std::move(name))
|
43
|
-
, parent_(std::move(parent))
|
44
|
-
{
|
45
|
-
}
|
46
|
-
virtual void add_tag(const std::string& name, std::uint64_t value) = 0;
|
47
|
-
virtual void add_tag(const std::string& name, const std::string& value) = 0;
|
48
|
-
virtual void end() = 0;
|
49
|
-
|
50
|
-
[[nodiscard]] const std::string& name() const
|
51
|
-
{
|
52
|
-
return name_;
|
53
|
-
}
|
54
|
-
|
55
|
-
[[nodiscard]] std::shared_ptr<request_span> parent() const
|
56
|
-
{
|
57
|
-
return parent_;
|
58
|
-
}
|
59
|
-
|
60
|
-
private:
|
61
|
-
std::string name_{};
|
62
|
-
std::shared_ptr<request_span> parent_{ nullptr };
|
63
|
-
};
|
64
|
-
|
65
27
|
class request_tracer
|
66
28
|
{
|
67
29
|
public:
|
@@ -15,6 +15,7 @@
|
|
15
15
|
*/
|
16
16
|
#pragma once
|
17
17
|
|
18
|
+
#include <couchbase/scope.hxx>
|
18
19
|
#include <couchbase/transactions/transaction_get_result.hxx>
|
19
20
|
#include <couchbase/transactions/transaction_query_options.hxx>
|
20
21
|
#include <couchbase/transactions/transaction_query_result.hxx>
|
@@ -24,52 +25,130 @@ namespace couchbase::transactions
|
|
24
25
|
using async_result_handler = std::function<void(transaction_op_error_context, transaction_get_result)>;
|
25
26
|
using async_query_handler = std::function<void(transaction_op_error_context, transaction_query_result)>;
|
26
27
|
using async_err_handler = std::function<void(transaction_op_error_context)>;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* The async_attempt_context is used for all asynchronous transaction operations
|
31
|
+
*
|
32
|
+
* In the example below, we get 3 documents in parallel, and update each when the get returns the document:
|
33
|
+
*
|
34
|
+
* @snippet test/test_transaction_examples.cxx simple-async-txn
|
35
|
+
*/
|
27
36
|
class async_attempt_context
|
28
37
|
{
|
29
38
|
|
30
39
|
public:
|
40
|
+
/**
|
41
|
+
* Get document from a collection.
|
42
|
+
*
|
43
|
+
* Fetch the document contents, in the form of a @ref transaction_get_result. This can be used in subsequent calls
|
44
|
+
* to @ref async_attempt_context::replace or @ref async_attempt_context::remove
|
45
|
+
*
|
46
|
+
* @param coll The collection which contains the document.
|
47
|
+
* @param id The document id which is used to uniquely identify it.
|
48
|
+
* @param handler The handler which implements @ref async_result_handler
|
49
|
+
*/
|
31
50
|
virtual void get(const collection& coll, std::string id, async_result_handler&& handler) = 0;
|
51
|
+
/**
|
52
|
+
* Remove a document from a collection.
|
53
|
+
*
|
54
|
+
* Removes a document from a collection, where the document was gotten from a previous call to @ref async_attempt_context::get
|
55
|
+
*
|
56
|
+
* @param doc The document to remove.
|
57
|
+
* @param handler The handler which implements @ref async_err_handler
|
58
|
+
*/
|
32
59
|
virtual void remove(transaction_get_result doc, async_err_handler&& handler) = 0;
|
33
60
|
|
61
|
+
/**
|
62
|
+
* Insert a document into a collection.
|
63
|
+
*
|
64
|
+
* Given an id and the content, this inserts a new document into a collection. Note that currently this content can be either a
|
65
|
+
* <std::vector<std::byte>> or an object which can be serialized with the @ref codec::tao_json_serializer.
|
66
|
+
*
|
67
|
+
* @tparam Content type of the document.
|
68
|
+
* @param coll Collection to insert the document into.
|
69
|
+
* @param id The document id.
|
70
|
+
* @param content The content of the document.
|
71
|
+
* @param handler The handler which implements @ref async_result_handler
|
72
|
+
*/
|
34
73
|
template<typename Content>
|
35
74
|
void insert(const collection& coll, std::string id, Content&& content, async_result_handler&& handler)
|
36
75
|
{
|
37
76
|
if constexpr (std::is_same_v<Content, std::vector<std::byte>>) {
|
38
77
|
return insert_raw(std::forward<std::vector<std::byte>>(content), std::move(id), content, std::move(handler));
|
39
78
|
} else {
|
79
|
+
// TODO: transcoder support
|
40
80
|
return insert_raw(coll, std::move(id), codec::tao_json_serializer::serialize(content), std::move(handler));
|
41
81
|
}
|
42
82
|
}
|
43
|
-
|
83
|
+
/**
|
84
|
+
* Replace the contents of a document in a collection.
|
85
|
+
*
|
86
|
+
* Replaces the contents of an existing document. Note that currently this content can be either a
|
87
|
+
* <std::vector<std::byte>> or an object which can be serialized with the @ref codec::tao_json_serializer.
|
88
|
+
*
|
89
|
+
* @tparam Content type of the document
|
90
|
+
* @param doc Document whose content will be replaced. This is gotten from a call to @ref async_attempt_context::get
|
91
|
+
* @param content New content of the document
|
92
|
+
* @param handler The handler which implements @ref async_result_handler
|
93
|
+
*/
|
44
94
|
template<typename Content>
|
45
95
|
void replace(transaction_get_result doc, Content&& content, async_result_handler&& handler)
|
46
96
|
{
|
47
97
|
if constexpr (std::is_same_v<Content, std::vector<std::byte>>) {
|
48
98
|
return replace_raw(std::move(doc), std::forward<std::vector<std::byte>>(content), std::move(handler));
|
49
99
|
} else {
|
100
|
+
// TODO: transcoder support
|
50
101
|
return replace_raw(std::move(doc), codec::tao_json_serializer::serialize(content), std::move(handler));
|
51
102
|
}
|
52
103
|
}
|
53
|
-
|
104
|
+
/**
|
105
|
+
* Perform a query, within a scope.
|
106
|
+
*
|
107
|
+
* Performs a query given a specific scope. Note that all subsequent transaction operations will be handled by the query service.
|
108
|
+
*
|
109
|
+
* @param scope Scope for the query.
|
110
|
+
* @param statement The query statement
|
111
|
+
* @param opts Options for the query
|
112
|
+
* @param handler Handler which implements @ref async_query_handler.
|
113
|
+
*/
|
54
114
|
void query(const scope& scope, std::string statement, transaction_query_options opts, async_query_handler&& handler)
|
55
115
|
{
|
56
116
|
return query(std::move(statement), std::move(opts), fmt::format("{}.{}", scope.bucket_name(), scope.name()), std::move(handler));
|
57
117
|
}
|
58
|
-
|
118
|
+
/**
|
119
|
+
* Perform a query.
|
120
|
+
*
|
121
|
+
* Performs an unscoped query.
|
122
|
+
*
|
123
|
+
* @param statement The query statement.
|
124
|
+
* @param opts Options for the query.
|
125
|
+
* @param handler Handler which implements @ref async_query_handler.
|
126
|
+
*/
|
59
127
|
void query(std::string statement, transaction_query_options opts, async_query_handler&& handler)
|
60
128
|
{
|
61
129
|
return query(statement, opts, {}, std::move(handler));
|
62
130
|
};
|
63
|
-
|
131
|
+
/**
|
132
|
+
* Perform a query.
|
133
|
+
*
|
134
|
+
* Performs an unscoped query.
|
135
|
+
*
|
136
|
+
* @param statement The query statement.
|
137
|
+
* @param handler Handler which implements @ref async_query_handler
|
138
|
+
*/
|
64
139
|
void query(std::string statement, async_query_handler&& handler)
|
65
140
|
{
|
66
141
|
return query(std::move(statement), {}, std::move(handler));
|
67
142
|
}
|
143
|
+
|
68
144
|
virtual ~async_attempt_context() = default;
|
69
145
|
|
70
146
|
protected:
|
147
|
+
/** @private */
|
71
148
|
virtual void insert_raw(const collection& coll, std::string id, std::vector<std::byte> content, async_result_handler&& handler) = 0;
|
149
|
+
/** @private */
|
72
150
|
virtual void replace_raw(transaction_get_result doc, std::vector<std::byte> content, async_result_handler&& handler) = 0;
|
151
|
+
/** @private */
|
73
152
|
virtual void query(std::string statement,
|
74
153
|
transaction_query_options opts,
|
75
154
|
std::optional<std::string> query_context,
|
@@ -21,12 +21,42 @@
|
|
21
21
|
|
22
22
|
namespace couchbase::transactions
|
23
23
|
{
|
24
|
+
/**
|
25
|
+
* The attempt_context is used for all synchronous transaction operations
|
26
|
+
*
|
27
|
+
* In the example below, we get a document then replace its content:
|
28
|
+
*
|
29
|
+
* @snippet test/test_transaction_examples.cxx simple-blocking-txn
|
30
|
+
*/
|
31
|
+
|
24
32
|
class attempt_context
|
25
33
|
{
|
26
34
|
public:
|
35
|
+
/**
|
36
|
+
* Get a document from a collection.
|
37
|
+
*
|
38
|
+
* Fetch the document contents, in the form of a @ref transaction_get_result. This can be used in subsequent calls
|
39
|
+
* to @ref attempt_context::replace or @ref attempt_context::remove
|
40
|
+
*
|
41
|
+
* @param coll The collection which contains the document.
|
42
|
+
* @param id The unique id of the document.
|
43
|
+
* @return The result of the operation, which is an @ref transaction_op_error_context and a @ref transaction_get_result.
|
44
|
+
*/
|
27
45
|
virtual std::pair<transaction_op_error_context, transaction_get_result> get(const couchbase::collection& coll,
|
28
46
|
const std::string& id) = 0;
|
29
47
|
|
48
|
+
/**
|
49
|
+
* Insert a document into a collection.
|
50
|
+
*
|
51
|
+
* Given an id and the content, this inserts a new document into a collection. Note that currently this content can be either a
|
52
|
+
* <std::vector<std::byte>> or an object which can be serialized with the @ref codec::tao_json_serializer.
|
53
|
+
*
|
54
|
+
* @tparam Content Type of the contents of the document.
|
55
|
+
* @param coll Collection in which to insert document.
|
56
|
+
* @param id The unique id of the document.
|
57
|
+
* @param content The content of the document.
|
58
|
+
* @return The result of the operation, which is an @ref transaction_op_error_context and a @ref transaction_get_result.
|
59
|
+
*/
|
30
60
|
template<typename Content>
|
31
61
|
std::pair<transaction_op_error_context, transaction_get_result> insert(const couchbase::collection& coll,
|
32
62
|
const std::string& id,
|
@@ -39,6 +69,17 @@ class attempt_context
|
|
39
69
|
}
|
40
70
|
}
|
41
71
|
|
72
|
+
/**
|
73
|
+
* Replace the contents of a document in a collection.
|
74
|
+
*
|
75
|
+
* Replaces the contents of an existing document. Note that currently this content can be either a
|
76
|
+
* <std::vector<std::byte>> or an object which can be serialized with the @ref codec::tao_json_serializer.
|
77
|
+
|
78
|
+
* @tparam Content Type of the contents of the document.
|
79
|
+
* @param doc Document whose content will be replaced. This is gotten from a call to @ref attempt_context::get
|
80
|
+
* @param content New content of the document.
|
81
|
+
* @return The result of the operation, which is an @ref transaction_op_error_context and a @ref transaction_get_result.
|
82
|
+
*/
|
42
83
|
template<typename Content>
|
43
84
|
std::pair<transaction_op_error_context, transaction_get_result> replace(const transaction_get_result& doc, const Content& content)
|
44
85
|
{
|
@@ -49,14 +90,37 @@ class attempt_context
|
|
49
90
|
}
|
50
91
|
}
|
51
92
|
|
93
|
+
/**
|
94
|
+
* Remove a document.
|
95
|
+
*
|
96
|
+
* Removes a document from a collection, where the document was gotten from a previous call to @ref attempt_context::get
|
97
|
+
*
|
98
|
+
* @param doc The document to remove.
|
99
|
+
* @return The result of the operation.
|
100
|
+
*/
|
52
101
|
virtual transaction_op_error_context remove(const transaction_get_result& doc) = 0;
|
53
102
|
|
103
|
+
/**
|
104
|
+
* Perform an unscoped query.
|
105
|
+
*
|
106
|
+
* @param statement The query statement.
|
107
|
+
* @param options Options for the query.
|
108
|
+
* @return The result of the operation, with is an @ref transaction_op_error_context and a @ref transaction_query_result.
|
109
|
+
*/
|
54
110
|
std::pair<transaction_op_error_context, transaction_query_result> query(const std::string& statement,
|
55
111
|
const transaction_query_options& options = {})
|
56
112
|
{
|
57
113
|
return do_public_query(statement, options, {});
|
58
114
|
}
|
59
115
|
|
116
|
+
/**
|
117
|
+
* Perform a scoped query.
|
118
|
+
*
|
119
|
+
* @param scope Scope for the query.
|
120
|
+
* @param statement The query statement.
|
121
|
+
* @param opts Options for the query.
|
122
|
+
* @return The result of the operation, with is an @ref transaction_op_error_context and a @ref transaction_query_result.
|
123
|
+
*/
|
60
124
|
std::pair<transaction_op_error_context, transaction_query_result> query(const scope& scope,
|
61
125
|
const std::string& statement,
|
62
126
|
const transaction_query_options& opts = {})
|
@@ -67,11 +131,14 @@ class attempt_context
|
|
67
131
|
virtual ~attempt_context() = default;
|
68
132
|
|
69
133
|
protected:
|
134
|
+
/** @private */
|
70
135
|
virtual std::pair<transaction_op_error_context, transaction_get_result> replace_raw(const transaction_get_result& doc,
|
71
136
|
std::vector<std::byte> content) = 0;
|
137
|
+
/** @private */
|
72
138
|
virtual std::pair<transaction_op_error_context, transaction_get_result> insert_raw(const couchbase::collection& coll,
|
73
139
|
const std::string& id,
|
74
140
|
std::vector<std::byte> content) = 0;
|
141
|
+
/** @private */
|
75
142
|
virtual std::pair<transaction_op_error_context, transaction_query_result> do_public_query(const std::string& statement,
|
76
143
|
const transaction_query_options& options,
|
77
144
|
std::optional<std::string> query_context) = 0;
|
@@ -66,12 +66,20 @@ struct transaction_keyspace {
|
|
66
66
|
: transaction_keyspace{ bucket_name, couchbase::scope::default_name, couchbase::collection::default_name }
|
67
67
|
{
|
68
68
|
}
|
69
|
-
|
69
|
+
/**
|
70
|
+
* Check if a keyspace is valid.
|
71
|
+
*
|
72
|
+
* A valid transaction_keyspace must have the bucket, scope, and collection all set. Note that both the scope and collection default
|
73
|
+
* to _default, but there is no default for the bucket so it must be set.
|
74
|
+
*
|
75
|
+
* @return true if valid.
|
76
|
+
*/
|
70
77
|
bool valid()
|
71
78
|
{
|
72
79
|
return !bucket.empty() && !scope.empty() && !collection.empty();
|
73
80
|
}
|
74
81
|
|
82
|
+
/** @private */
|
75
83
|
template<typename OStream>
|
76
84
|
friend OStream& operator<<(OStream& os, const transaction_keyspace& keyspace)
|
77
85
|
{
|
@@ -84,6 +92,8 @@ struct transaction_keyspace {
|
|
84
92
|
}
|
85
93
|
};
|
86
94
|
} // namespace couchbase::transactions
|
95
|
+
|
96
|
+
/** @private */
|
87
97
|
template<>
|
88
98
|
struct fmt::formatter<couchbase::transactions::transaction_keyspace> {
|
89
99
|
public:
|
@@ -24,44 +24,91 @@
|
|
24
24
|
|
25
25
|
namespace couchbase::transactions
|
26
26
|
{
|
27
|
+
/**
|
28
|
+
* The transaction_options can be passed in to override some elements of the global @ref transactions_config.
|
29
|
+
*/
|
27
30
|
class transaction_options
|
28
31
|
{
|
29
32
|
public:
|
30
33
|
transaction_options() = default;
|
31
34
|
|
35
|
+
/**
|
36
|
+
* Set durability for this transaction.
|
37
|
+
*
|
38
|
+
* @see couchbase::durability_level for details.
|
39
|
+
*
|
40
|
+
* @param level Durability level for this transaction.
|
41
|
+
* @return reference to this object, convenient for chaining operations.
|
42
|
+
*/
|
32
43
|
transaction_options& durability_level(durability_level level)
|
33
44
|
{
|
34
45
|
durability_ = level;
|
35
46
|
return *this;
|
36
47
|
}
|
37
|
-
|
48
|
+
/**
|
49
|
+
* Get the durability if it has been set.
|
50
|
+
*
|
51
|
+
* @see couchbase::durability_level for details.
|
52
|
+
*
|
53
|
+
* @return durability if set.
|
54
|
+
*/
|
38
55
|
std::optional<couchbase::durability_level> durability_level()
|
39
56
|
{
|
40
57
|
return durability_;
|
41
58
|
}
|
42
|
-
|
59
|
+
/**
|
60
|
+
* Set the @ref query_scan_consistency for this transaction.
|
61
|
+
*
|
62
|
+
* @see query_options::scan_consistency for details.
|
63
|
+
*
|
64
|
+
* @param scan_consistency The desired @ref query_scan_consistency for this transaction.
|
65
|
+
* @return reference to this object, convenient for chaining operations.
|
66
|
+
*/
|
43
67
|
transaction_options& scan_consistency(query_scan_consistency scan_consistency)
|
44
68
|
{
|
45
69
|
scan_consistency_ = scan_consistency;
|
46
70
|
return *this;
|
47
71
|
}
|
48
|
-
|
72
|
+
/**
|
73
|
+
* Get the scan_consistency if it has been set.
|
74
|
+
*
|
75
|
+
* @see query_options::scan_consistency for details.
|
76
|
+
*
|
77
|
+
* @return The scan_consistency, if set.
|
78
|
+
*/
|
49
79
|
std::optional<query_scan_consistency> scan_consistency()
|
50
80
|
{
|
51
81
|
return scan_consistency_;
|
52
82
|
}
|
53
|
-
|
83
|
+
/**
|
84
|
+
* Set the timeout for key-value operations for this transaction.
|
85
|
+
*
|
86
|
+
* @param kv_timeout Desired key-value timeout.
|
87
|
+
* @return reference to this object, convenient for chaining operations.
|
88
|
+
*/
|
54
89
|
transaction_options& kv_timeout(std::chrono::milliseconds kv_timeout)
|
55
90
|
{
|
56
91
|
kv_timeout_ = kv_timeout;
|
57
92
|
return *this;
|
58
93
|
}
|
59
94
|
|
95
|
+
/**
|
96
|
+
* Get the key-value timeout if it has been set.
|
97
|
+
*
|
98
|
+
* @return The key-value timeout, if set.
|
99
|
+
*/
|
60
100
|
std::optional<std::chrono::milliseconds> kv_timeout()
|
61
101
|
{
|
62
102
|
return kv_timeout_;
|
63
103
|
}
|
64
104
|
|
105
|
+
/**
|
106
|
+
* Set the expiration time for this transaction.
|
107
|
+
*
|
108
|
+
* @tparam T expiration time type, e.g. @ref std::chrono::milliseconds, or similar
|
109
|
+
* @param expiration_time Desired expiration time.
|
110
|
+
* @return reference to this object, convenient for chaining operations.
|
111
|
+
*/
|
65
112
|
template<typename T>
|
66
113
|
transaction_options& expiration_time(T expiration_time)
|
67
114
|
{
|
@@ -69,29 +116,53 @@ class transaction_options
|
|
69
116
|
return *this;
|
70
117
|
}
|
71
118
|
|
119
|
+
/**
|
120
|
+
* Get the expiration time, if set.
|
121
|
+
*
|
122
|
+
* @return the expiration time, if set.
|
123
|
+
*/
|
72
124
|
std::optional<std::chrono::nanoseconds> expiration_time()
|
73
125
|
{
|
74
126
|
return expiration_time_;
|
75
127
|
}
|
76
128
|
|
129
|
+
/**
|
130
|
+
* Set the metadata collection to use for this transaction
|
131
|
+
*
|
132
|
+
* Transactions involve a the creation and use of some metadata documents, which by default are placed in the default collection of
|
133
|
+
* scope which the first document in the that has a mutating operation performed on it. However, you can set this to a specific
|
134
|
+
* collection to isolate these documents from your documents, if desired.
|
135
|
+
*
|
136
|
+
* @param coll The desired collection to use.
|
137
|
+
* @return reference to this object, convenient for chaining operations.
|
138
|
+
*/
|
77
139
|
transaction_options& metadata_collection(const couchbase::collection& coll)
|
78
140
|
{
|
79
141
|
metadata_collection_.emplace(coll.bucket_name(), coll.scope_name(), coll.name());
|
80
142
|
return *this;
|
81
143
|
}
|
82
|
-
|
144
|
+
/**
|
145
|
+
* Set metadata collection to use for this transaction
|
146
|
+
*
|
147
|
+
* @param keyspace The desired collection to use
|
148
|
+
* @return reference to this object, convenient for chaining operations.
|
149
|
+
*/
|
83
150
|
transaction_options& metadata_collection(const couchbase::transactions::transaction_keyspace& keyspace)
|
84
151
|
{
|
85
152
|
metadata_collection_.emplace(keyspace);
|
86
153
|
return *this;
|
87
154
|
}
|
88
|
-
|
155
|
+
/**
|
156
|
+
* Get the metadata collection, if set.
|
157
|
+
*
|
158
|
+
* @return the metadata collection, as a @ref transaction_keyspace, if set.
|
159
|
+
*/
|
89
160
|
std::optional<transaction_keyspace> metadata_collection()
|
90
161
|
{
|
91
162
|
return metadata_collection_;
|
92
163
|
}
|
93
164
|
|
94
|
-
/** @
|
165
|
+
/** @private */
|
95
166
|
transaction_options& test_factories(std::shared_ptr<core::transactions::attempt_context_testing_hooks> hooks,
|
96
167
|
std::shared_ptr<core::transactions::cleanup_testing_hooks> cleanup_hooks)
|
97
168
|
{
|
@@ -99,7 +170,7 @@ class transaction_options
|
|
99
170
|
cleanup_hooks_ = cleanup_hooks;
|
100
171
|
return *this;
|
101
172
|
}
|
102
|
-
|
173
|
+
/** @private */
|
103
174
|
[[nodiscard]] transactions_config::built apply(const transactions_config::built& conf) const;
|
104
175
|
|
105
176
|
private:
|