Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
transaction_config.hxx
1 /*
2  * Copyright 2021 Couchbase, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <boost/optional.hpp>
19 #include <chrono>
20 #include <couchbase/support.hxx>
21 #include <couchbase/transactions/durability_level.hxx>
22 #include <memory>
23 
24 namespace couchbase
25 {
26 namespace transactions
27 {
29  class attempt_context_testing_hooks;
30 
32  class cleanup_testing_hooks;
36  class transaction_config
37  {
38  public:
40 
42 
44 
45  transaction_config& operator=(const transaction_config& c);
46 
52  CB_NODISCARD couchbase::transactions::durability_level durability_level() const
53  {
54  return level_;
55  }
56 
62  void durability_level(enum couchbase::transactions::durability_level level)
63  {
64  level_ = level;
65  }
66 
79  CB_NODISCARD std::chrono::milliseconds cleanup_window() const
80  {
81  return cleanup_window_;
82  }
83 
90  template<typename T>
91  void cleanup_window(T duration)
92  {
93  cleanup_window_ = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
94  }
95 
102  template<typename T>
103  void kv_timeout(T duration)
104  {
105  kv_timeout_ = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
106  }
107 
116  CB_NODISCARD boost::optional<std::chrono::milliseconds> kv_timeout() const
117  {
118  return kv_timeout_;
119  }
120 
130  CB_NODISCARD std::chrono::nanoseconds expiration_time() const
131  {
132  return expiration_time_;
133  }
139  template<typename T>
140  void expiration_time(T duration)
141  {
142  expiration_time_ = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
143  }
144 
151  void cleanup_lost_attempts(bool value)
152  {
153  cleanup_lost_attempts_ = value;
154  }
161  CB_NODISCARD bool cleanup_lost_attempts() const
162  {
163  return cleanup_lost_attempts_;
164  }
165 
172  void cleanup_client_attempts(bool value)
173  {
174  cleanup_client_attempts_ = value;
175  }
176 
185  CB_NODISCARD bool cleanup_client_attempts() const
186  {
187  return cleanup_client_attempts_;
188  }
189 
191  void test_factories(attempt_context_testing_hooks& hooks, cleanup_testing_hooks& cleanup_hooks);
192 
194  attempt_context_testing_hooks& attempt_context_hooks() const
195  {
196  return *attempt_context_hooks_;
197  }
200  cleanup_testing_hooks& cleanup_hooks() const
201  {
202  return *cleanup_hooks_;
203  }
204 
205  protected:
206  couchbase::transactions::durability_level level_;
207  std::chrono::milliseconds cleanup_window_;
208  std::chrono::nanoseconds expiration_time_;
209  boost::optional<std::chrono::milliseconds> kv_timeout_;
210  bool cleanup_lost_attempts_;
211  bool cleanup_client_attempts_;
212  std::unique_ptr<attempt_context_testing_hooks> attempt_context_hooks_;
213  std::unique_ptr<cleanup_testing_hooks> cleanup_hooks_;
214  };
215 } // namespace transactions
216 } // namespace couchbase
Definition: bucket.hxx:33
attempt_context_testing_hooks & attempt_context_hooks() const
Definition: transaction_config.hxx:198
CB_NODISCARD std::chrono::milliseconds cleanup_window() const
Get cleanup window.
Definition: transaction_config.hxx:81
CB_NODISCARD couchbase::transactions::durability_level durability_level() const
Get the default durability level for all transaction operations.
Definition: transaction_config.hxx:54
Configuration parameters for transactions.
Definition: transaction_config.hxx:38
void test_factories(attempt_context_testing_hooks &hooks, cleanup_testing_hooks &cleanup_hooks)
CB_NODISCARD boost::optional< std::chrono::milliseconds > kv_timeout() const
Get kv_timeout.
Definition: transaction_config.hxx:118
cleanup_testing_hooks & cleanup_hooks() const
Definition: transaction_config.hxx:205
CB_NODISCARD bool cleanup_client_attempts() const
Get state of client attempts cleanup loop.
Definition: transaction_config.hxx:187
CB_NODISCARD std::chrono::nanoseconds expiration_time() const
Get expiration time for transactions.
Definition: transaction_config.hxx:132
CB_NODISCARD bool cleanup_lost_attempts() const
Get lost attempts cleanup loop status.
Definition: transaction_config.hxx:163