/Users/deen/code/yugabyte-db/src/yb/client/txn-test-base.h
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // Copyright (c) YugaByte, Inc. |
3 | | // |
4 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
5 | | // in compliance with the License. You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
10 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
11 | | // or implied. See the License for the specific language governing permissions and limitations |
12 | | // under the License. |
13 | | // |
14 | | // |
15 | | |
16 | | #ifndef YB_CLIENT_TXN_TEST_BASE_H |
17 | | #define YB_CLIENT_TXN_TEST_BASE_H |
18 | | |
19 | | #include <stdint.h> |
20 | | |
21 | | #include <functional> |
22 | | #include <set> |
23 | | #include <string> |
24 | | #include <type_traits> |
25 | | #include <unordered_set> |
26 | | #include <utility> |
27 | | |
28 | | #include <boost/range/iterator_range.hpp> |
29 | | |
30 | | #include "yb/client/ql-dml-test-base.h" |
31 | | #include "yb/client/transaction_manager.h" |
32 | | |
33 | | #include "yb/common/entity_ids.h" |
34 | | |
35 | | #include "yb/server/hybrid_clock.h" |
36 | | #include "yb/server/skewed_clock.h" |
37 | | |
38 | | #include "yb/util/enums.h" |
39 | | #include "yb/util/math_util.h" |
40 | | |
41 | | namespace yb { |
42 | | namespace client { |
43 | | |
44 | | constexpr size_t kNumRows = 5; |
45 | | extern const MonoDelta kTransactionApplyTime; |
46 | | extern const MonoDelta kIntentsCleanupTime; |
47 | | |
48 | | // We use different sign to distinguish inserted and updated values for testing. |
49 | | int32_t GetMultiplier(const WriteOpType op_type); |
50 | | |
51 | | int32_t KeyForTransactionAndIndex(size_t transaction, size_t index); |
52 | | |
53 | | int32_t ValueForTransactionAndIndex(size_t transaction, size_t index, const WriteOpType op_type); |
54 | | |
55 | | void SetIgnoreApplyingProbability(double value); |
56 | | |
57 | | void SetDisableHeartbeatInTests(bool value); |
58 | | |
59 | | void DisableApplyingIntents(); |
60 | | |
61 | | void CommitAndResetSync(YBTransactionPtr *txn); |
62 | | |
63 | | void DisableTransactionTimeout(); |
64 | | |
65 | 0 | #define VERIFY_ROW(...) ASSERT_NO_FATAL_FAILURE(VerifyRow(__LINE__, __VA_ARGS__)) |
66 | | |
67 | | YB_STRONGLY_TYPED_BOOL(SetReadTime); |
68 | | |
69 | | |
70 | | template <class MiniClusterType> |
71 | | class TransactionTestBase : public KeyValueTableTest<MiniClusterType> { |
72 | | protected: |
73 | | void SetUp() override; |
74 | | |
75 | | void CreateTable(); |
76 | | CHECKED_STATUS CreateTable(const Schema& schema); |
77 | | |
78 | | virtual uint64_t log_segment_size_bytes() const; |
79 | | |
80 | | CHECKED_STATUS WriteRows( |
81 | | const YBSessionPtr& session, size_t transaction = 0, |
82 | | const WriteOpType op_type = WriteOpType::INSERT, |
83 | | Flush flush = Flush::kTrue); |
84 | | |
85 | | void VerifyRow(int line, const YBSessionPtr& session, int32_t key, int32_t value, |
86 | | const std::string& column = KeyValueTableTest<MiniClusterType>::kValueColumn); |
87 | | |
88 | | void WriteData(const WriteOpType op_type = WriteOpType::INSERT, size_t transaction = 0); |
89 | | |
90 | | void WriteDataWithRepetition(); |
91 | | |
92 | | // Create a new transaction using transaction_manager_. |
93 | | YBTransactionPtr CreateTransaction(SetReadTime set_read_time = SetReadTime::kFalse); |
94 | | |
95 | | // Create a new transaction using transaction_manager2_. |
96 | | YBTransactionPtr CreateTransaction2(SetReadTime set_read_time = SetReadTime::kFalse); |
97 | | |
98 | | void VerifyRows(const YBSessionPtr& session, |
99 | | size_t transaction = 0, |
100 | | const WriteOpType op_type = WriteOpType::INSERT, |
101 | | const std::string& column = KeyValueTableTest<MiniClusterType>::kValueColumn); |
102 | | |
103 | | YBqlReadOpPtr ReadRow( |
104 | | const YBSessionPtr& session, |
105 | | int32_t key, |
106 | | const std::string& column = kValueColumn); |
107 | | |
108 | | void VerifyData( |
109 | | size_t num_transactions = 1, const WriteOpType op_type = WriteOpType::INSERT, |
110 | | const std::string& column = KeyValueTableTest<MiniClusterType>::kValueColumn); |
111 | | |
112 | | void VerifyData( |
113 | | const WriteOpType op_type, |
114 | 0 | const std::string& column = kValueColumn) { |
115 | 0 | VerifyData(/* num_transactions= */ 1, op_type, column); |
116 | 0 | } Unexecuted instantiation: _ZN2yb6client19TransactionTestBaseINS_11MiniClusterEE10VerifyDataENS0_11WriteOpTypeERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE Unexecuted instantiation: _ZN2yb6client19TransactionTestBaseINS_19ExternalMiniClusterEE10VerifyDataENS0_11WriteOpTypeERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE |
117 | | |
118 | | bool HasTransactions(); |
119 | | |
120 | | size_t CountRunningTransactions(); |
121 | | |
122 | | void AssertNoRunningTransactions(); |
123 | | |
124 | | bool CheckAllTabletsRunning(); |
125 | | |
126 | | IsolationLevel GetIsolationLevel(); |
127 | | |
128 | | void SetIsolationLevel(IsolationLevel isolation_level); |
129 | | |
130 | | using KeyValueTableTest<MiniClusterType>::kKeyColumn; |
131 | | using KeyValueTableTest<MiniClusterType>::kValueColumn; |
132 | | using KeyValueTableTest<MiniClusterType>::cluster_; |
133 | | using KeyValueTableTest<MiniClusterType>::client_; |
134 | | using KeyValueTableTest<MiniClusterType>::table_; |
135 | | |
136 | | std::shared_ptr<server::SkewedClock> skewed_clock_{ |
137 | | std::make_shared<server::SkewedClock>(WallClock())}; |
138 | | server::ClockPtr clock_{new server::HybridClock(skewed_clock_)}; |
139 | | boost::optional<TransactionManager> transaction_manager_; |
140 | | boost::optional<TransactionManager> transaction_manager2_; |
141 | | |
142 | | bool create_table_ = true; |
143 | | IsolationLevel isolation_level_ = IsolationLevel::SNAPSHOT_ISOLATION; |
144 | | }; |
145 | | |
146 | | template <uint64_t LogSizeBytes, class Base> |
147 | | class TransactionCustomLogSegmentSizeTest : public Base { |
148 | | // We need multiple log segments in this test. |
149 | 30 | uint64_t log_segment_size_bytes() const override { |
150 | 30 | return LogSizeBytes; |
151 | 30 | } _ZNK2yb6client35TransactionCustomLogSegmentSizeTestILy0ENS0_17QLTransactionTestEE22log_segment_size_bytesEv Line | Count | Source | 149 | 7 | uint64_t log_segment_size_bytes() const override { | 150 | 7 | return LogSizeBytes; | 151 | 7 | } |
_ZNK2yb6client35TransactionCustomLogSegmentSizeTestILy4096ENS0_17QLTransactionTestEE22log_segment_size_bytesEv Line | Count | Source | 149 | 2 | uint64_t log_segment_size_bytes() const override { | 150 | 2 | return LogSizeBytes; | 151 | 2 | } |
_ZNK2yb6client35TransactionCustomLogSegmentSizeTestILy0ENS0_19TransactionTestBaseINS_11MiniClusterEEEE22log_segment_size_bytesEv Line | Count | Source | 149 | 19 | uint64_t log_segment_size_bytes() const override { | 150 | 19 | return LogSizeBytes; | 151 | 19 | } |
_ZNK2yb6client35TransactionCustomLogSegmentSizeTestILy128ENS0_15SnapshotTxnTestEE22log_segment_size_bytesEv Line | Count | Source | 149 | 2 | uint64_t log_segment_size_bytes() const override { | 150 | 2 | return LogSizeBytes; | 151 | 2 | } |
|
152 | | }; |
153 | | |
154 | | } // namespace client |
155 | | } // namespace yb |
156 | | |
157 | | #endif // YB_CLIENT_TXN_TEST_BASE_H |