Couchbase C++ SDK 1.4.0 (rev. 59aa900)
Loading...
Searching...
No Matches
transactions_config.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2021-Present Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#pragma once
18
23
24#include <chrono>
25#include <memory>
26#include <optional>
27
29{
31struct attempt_context_testing_hooks;
32
34struct cleanup_testing_hooks;
35} // namespace couchbase::core::transactions
36
38{
43{
44public:
46
48
50
52
53 // No move operations are declared: they fall back to the copy operations, which is sufficient for
54 // this configuration object (copied once during transaction setup) and keeps a moved-from source
55 // valid -- the hook accessors dereference their pointers, so a nulled-out source would be unsafe.
56
64 [[nodiscard]] auto durability_level() const -> couchbase::durability_level
65 {
66 return level_;
67 }
68
78 {
79 level_ = level;
80 return *this;
81 }
82
92 [[nodiscard]] auto timeout() const -> std::chrono::nanoseconds
93 {
94 return timeout_;
95 }
96
102 template<typename T>
103 auto timeout(T duration) -> transactions_config&
104 {
105 timeout_ = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
106 return *this;
107 }
108
117 {
118 metadata_collection_ = keyspace;
119 return *this;
120 }
121
122 [[nodiscard]] auto metadata_collection() const
124 {
125 return metadata_collection_;
126 }
127
133 [[nodiscard]] auto query_config() const -> const transactions_query_config&
134 {
135 return query_config_;
136 }
137
144 {
145 return query_config_;
146 }
147
155 {
156 query_config_ = config;
157 return *this;
158 }
159
165 [[nodiscard]] auto cleanup_config() const -> const transactions_cleanup_config&
166 {
167 return cleanup_config_;
168 }
169
176 {
177 return cleanup_config_;
178 }
179
187 {
188 cleanup_config_ = cleanup_config;
189 return *this;
190 }
191
193 auto test_factories(std::shared_ptr<core::transactions::attempt_context_testing_hooks> hooks,
194 std::shared_ptr<core::transactions::cleanup_testing_hooks> cleanup_hooks)
196 {
197 attempt_context_hooks_ = hooks;
198 cleanup_hooks_ = cleanup_hooks;
199 return *this;
200 }
201
203 [[nodiscard]] auto attempt_context_hooks() const
204 -> core::transactions::attempt_context_testing_hooks&
205 {
206 return *attempt_context_hooks_;
207 }
208
210 [[nodiscard]] auto cleanup_hooks() const -> core::transactions::cleanup_testing_hooks&
211 {
212 return *cleanup_hooks_;
213 }
214
216 struct built {
218 std::chrono::nanoseconds timeout;
219 std::shared_ptr<core::transactions::attempt_context_testing_hooks> attempt_context_hooks;
220 std::shared_ptr<core::transactions::cleanup_testing_hooks> cleanup_hooks;
221 std::optional<couchbase::transactions::transaction_keyspace> metadata_collection;
222 transactions_query_config::built query_config;
223 transactions_cleanup_config::built cleanup_config;
224 };
225
227 [[nodiscard]] auto build() const -> built;
228
229private:
231 std::chrono::nanoseconds timeout_{ std::chrono::seconds(15) };
232 std::shared_ptr<core::transactions::attempt_context_testing_hooks> attempt_context_hooks_;
233 std::shared_ptr<core::transactions::cleanup_testing_hooks> cleanup_hooks_;
234 std::optional<couchbase::transactions::transaction_keyspace> metadata_collection_;
235 transactions_query_config query_config_{};
236 transactions_cleanup_config cleanup_config_{};
237};
238} // namespace couchbase::transactions
Configuration parameters for the background transaction cleanup threads.
Definition transactions_cleanup_config.hxx:29
Configuration parameters for transactions.
Definition transactions_config.hxx:43
auto query_config() const -> const transactions_query_config &
Get the query config values.
Definition transactions_config.hxx:133
auto cleanup_config() const -> const transactions_cleanup_config &
Get the cleanup configuration for transactions.
Definition transactions_config.hxx:165
auto metadata_collection() const -> std::optional< couchbase::transactions::transaction_keyspace >
Definition transactions_config.hxx:122
auto metadata_collection(const couchbase::transactions::transaction_keyspace &keyspace) -> transactions_config &
Set the transaction's metadata collection.
Definition transactions_config.hxx:115
auto operator=(const transactions_config &c) -> transactions_config &
auto timeout(T duration) -> transactions_config &
Set the timeout for transactions.
Definition transactions_config.hxx:103
auto durability_level(enum couchbase::durability_level level) -> transactions_config &
Set the default durability level for all transaction operations.
Definition transactions_config.hxx:77
auto query_config(const transactions_query_config &config) -> transactions_config &
Set the query configuration for transactions.
Definition transactions_config.hxx:154
transactions_config(const transactions_config &c)
auto cleanup_config() -> transactions_cleanup_config &
Get the cleanup configuration for transactions.
Definition transactions_config.hxx:175
auto cleanup_config(const transactions_cleanup_config &cleanup_config) -> transactions_config &
Set the cleanup configuration.
Definition transactions_config.hxx:186
auto durability_level() const -> couchbase::durability_level
Get the default durability level for all transaction operations.
Definition transactions_config.hxx:64
auto query_config() -> transactions_query_config &
Get the query config values.
Definition transactions_config.hxx:143
auto timeout() const -> std::chrono::nanoseconds
Get the timeout for transactions.
Definition transactions_config.hxx:92
The transactions_query_config sets the defaults for all queries in the transactions.
Definition transactions_query_config.hxx:26
The transactions object is used to initiate a transaction.
Definition transactions.hxx:52
Definition transaction_get_multi_options.hxx:23
Definition expiry.hxx:24
Definition transactions.hxx:43
Represents a single item from the result of scan().
Definition allow_querying_search_index_options.hxx:28
durability_level
Specifies enhanced durability options for the mutation.
Definition durability_level.hxx:30
@ majority
The mutation must be replicated to a majority of the Data Service nodes (that is, held in the memory ...
Definition durability_level.hxx:46
Offline, serializable representation of a bucket, scope, and collection.
Definition transaction_keyspace.hxx:25