/Users/deen/code/yugabyte-db/src/yb/client/txn-test-base.cc
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 | | #include "yb/client/txn-test-base.h" |
17 | | |
18 | | #include "yb/client/session.h" |
19 | | #include "yb/client/transaction.h" |
20 | | #include "yb/client/yb_op.h" |
21 | | |
22 | | #include "yb/common/ql_value.h" |
23 | | #include "yb/common/schema.h" |
24 | | |
25 | | #include "yb/consensus/consensus.h" |
26 | | |
27 | | #include "yb/integration-tests/external_mini_cluster.h" |
28 | | #include "yb/integration-tests/mini_cluster_utils.h" |
29 | | |
30 | | #include "yb/tablet/tablet.h" |
31 | | #include "yb/tablet/tablet_peer.h" |
32 | | |
33 | | #include "yb/tserver/mini_tablet_server.h" |
34 | | #include "yb/tserver/tablet_server.h" |
35 | | #include "yb/tserver/ts_tablet_manager.h" |
36 | | |
37 | | #include "yb/util/tsan_util.h" |
38 | | |
39 | | #include "yb/yql/cql/ql/util/statement_result.h" |
40 | | |
41 | | using namespace std::literals; |
42 | | |
43 | | DECLARE_double(transaction_max_missed_heartbeat_periods); |
44 | | DECLARE_uint64(transaction_status_tablet_log_segment_size_bytes); |
45 | | DECLARE_int32(log_min_seconds_to_retain); |
46 | | DECLARE_bool(transaction_disable_heartbeat_in_tests); |
47 | | DECLARE_double(TEST_transaction_ignore_applying_probability); |
48 | | DECLARE_string(time_source); |
49 | | DECLARE_int32(intents_flush_max_delay_ms); |
50 | | DECLARE_int32(load_balancer_max_concurrent_adds); |
51 | | DECLARE_bool(TEST_combine_batcher_errors); |
52 | | DECLARE_bool(TEST_export_intentdb_metrics); |
53 | | |
54 | | namespace yb { |
55 | | namespace client { |
56 | | |
57 | | const MonoDelta kTransactionApplyTime = 6s * kTimeMultiplier; |
58 | | const MonoDelta kIntentsCleanupTime = 6s * kTimeMultiplier; |
59 | | |
60 | | // We use different sign to distinguish inserted and updated values for testing. |
61 | 0 | int32_t GetMultiplier(const WriteOpType op_type) { |
62 | 0 | switch (op_type) { |
63 | 0 | case WriteOpType::INSERT: |
64 | 0 | return 1; |
65 | 0 | case WriteOpType::UPDATE: |
66 | 0 | return -1; |
67 | 0 | case WriteOpType::DELETE: |
68 | 0 | return 0; // Value is not used in delete path. |
69 | 0 | } |
70 | 0 | FATAL_INVALID_ENUM_VALUE(WriteOpType, op_type); |
71 | 0 | } |
72 | | |
73 | 0 | int32_t KeyForTransactionAndIndex(size_t transaction, size_t index) { |
74 | 0 | return static_cast<int32_t>(transaction * 10 + index); |
75 | 0 | } |
76 | | |
77 | 0 | int32_t ValueForTransactionAndIndex(size_t transaction, size_t index, const WriteOpType op_type) { |
78 | 0 | return static_cast<int32_t>(transaction * 10 + index + 2) * GetMultiplier(op_type); |
79 | 0 | } |
80 | | |
81 | 0 | void SetIgnoreApplyingProbability(double value) { |
82 | 0 | SetAtomicFlag(value, &FLAGS_TEST_transaction_ignore_applying_probability); |
83 | 0 | } |
84 | | |
85 | 0 | void SetDisableHeartbeatInTests(bool value) { |
86 | 0 | SetAtomicFlag(value, &FLAGS_transaction_disable_heartbeat_in_tests); |
87 | 0 | } |
88 | | |
89 | 0 | void DisableApplyingIntents() { |
90 | 0 | SetIgnoreApplyingProbability(1.0); |
91 | 0 | } |
92 | | |
93 | 0 | void CommitAndResetSync(YBTransactionPtr *txn) { |
94 | 0 | CountDownLatch latch(1); |
95 | 0 | (*txn)->Commit(TransactionRpcDeadline(), [&latch](const Status& status) { |
96 | 0 | ASSERT_OK(status); |
97 | 0 | latch.CountDown(1); |
98 | 0 | }); |
99 | 0 | txn->reset(); |
100 | 0 | latch.Wait(); |
101 | 0 | } |
102 | | |
103 | 0 | void DisableTransactionTimeout() { |
104 | 0 | SetAtomicFlag(std::numeric_limits<double>::max(), |
105 | 0 | &FLAGS_transaction_max_missed_heartbeat_periods); |
106 | 0 | } |
107 | | |
108 | | template <class MiniClusterType> |
109 | 156 | void TransactionTestBase<MiniClusterType>::SetUp() { |
110 | 156 | FLAGS_TEST_combine_batcher_errors = true; |
111 | 156 | FLAGS_transaction_status_tablet_log_segment_size_bytes = log_segment_size_bytes(); |
112 | 156 | FLAGS_log_min_seconds_to_retain = 5; |
113 | 156 | FLAGS_intents_flush_max_delay_ms = 250; |
114 | 156 | FLAGS_TEST_export_intentdb_metrics = true; |
115 | | |
116 | 156 | server::SkewedClock::Register(); |
117 | 156 | FLAGS_time_source = server::SkewedClock::kName; |
118 | 156 | FLAGS_load_balancer_max_concurrent_adds = 100; |
119 | 156 | ASSERT_NO_FATALS(KeyValueTableTest<MiniClusterType>::SetUp()); |
120 | | |
121 | 8 | if (create_table_) { |
122 | 0 | CreateTable(); |
123 | 0 | } |
124 | | |
125 | 8 | HybridTime::TEST_SetPrettyToString(true); |
126 | | |
127 | 8 | ASSERT_OK(clock_->Init()); |
128 | 8 | transaction_manager_.emplace(client_.get(), clock_, client::LocalTabletFilter()); |
129 | | |
130 | 8 | server::ClockPtr clock2(new server::HybridClock(skewed_clock_)); |
131 | 8 | ASSERT_OK(clock2->Init()); |
132 | 8 | transaction_manager2_.emplace(client_.get(), clock2, client::LocalTabletFilter()); |
133 | 8 | } yb::client::TransactionTestBase<yb::MiniCluster>::SetUp() Line | Count | Source | 109 | 148 | void TransactionTestBase<MiniClusterType>::SetUp() { | 110 | 148 | FLAGS_TEST_combine_batcher_errors = true; | 111 | 148 | FLAGS_transaction_status_tablet_log_segment_size_bytes = log_segment_size_bytes(); | 112 | 148 | FLAGS_log_min_seconds_to_retain = 5; | 113 | 148 | FLAGS_intents_flush_max_delay_ms = 250; | 114 | 148 | FLAGS_TEST_export_intentdb_metrics = true; | 115 | | | 116 | 148 | server::SkewedClock::Register(); | 117 | 148 | FLAGS_time_source = server::SkewedClock::kName; | 118 | 148 | FLAGS_load_balancer_max_concurrent_adds = 100; | 119 | 148 | ASSERT_NO_FATALS(KeyValueTableTest<MiniClusterType>::SetUp()); | 120 | | | 121 | 0 | if (create_table_) { | 122 | 0 | CreateTable(); | 123 | 0 | } | 124 | |
| 125 | 0 | HybridTime::TEST_SetPrettyToString(true); | 126 | |
| 127 | 0 | ASSERT_OK(clock_->Init()); | 128 | 0 | transaction_manager_.emplace(client_.get(), clock_, client::LocalTabletFilter()); | 129 | |
| 130 | 0 | server::ClockPtr clock2(new server::HybridClock(skewed_clock_)); | 131 | 0 | ASSERT_OK(clock2->Init()); | 132 | 0 | transaction_manager2_.emplace(client_.get(), clock2, client::LocalTabletFilter()); | 133 | 0 | } |
yb::client::TransactionTestBase<yb::ExternalMiniCluster>::SetUp() Line | Count | Source | 109 | 8 | void TransactionTestBase<MiniClusterType>::SetUp() { | 110 | 8 | FLAGS_TEST_combine_batcher_errors = true; | 111 | 8 | FLAGS_transaction_status_tablet_log_segment_size_bytes = log_segment_size_bytes(); | 112 | 8 | FLAGS_log_min_seconds_to_retain = 5; | 113 | 8 | FLAGS_intents_flush_max_delay_ms = 250; | 114 | 8 | FLAGS_TEST_export_intentdb_metrics = true; | 115 | | | 116 | 8 | server::SkewedClock::Register(); | 117 | 8 | FLAGS_time_source = server::SkewedClock::kName; | 118 | 8 | FLAGS_load_balancer_max_concurrent_adds = 100; | 119 | 8 | ASSERT_NO_FATALS(KeyValueTableTest<MiniClusterType>::SetUp()); | 120 | | | 121 | 8 | if (create_table_) { | 122 | 0 | CreateTable(); | 123 | 0 | } | 124 | | | 125 | 8 | HybridTime::TEST_SetPrettyToString(true); | 126 | | | 127 | 8 | ASSERT_OK(clock_->Init()); | 128 | 8 | transaction_manager_.emplace(client_.get(), clock_, client::LocalTabletFilter()); | 129 | | | 130 | 8 | server::ClockPtr clock2(new server::HybridClock(skewed_clock_)); | 131 | 8 | ASSERT_OK(clock2->Init()); | 132 | 8 | transaction_manager2_.emplace(client_.get(), clock2, client::LocalTabletFilter()); | 133 | 8 | } |
|
134 | | |
135 | | template <class MiniClusterType> |
136 | 8 | void TransactionTestBase<MiniClusterType>::CreateTable() { |
137 | 8 | KeyValueTableTest<MiniClusterType>::CreateTable( |
138 | 8 | Transactional(GetIsolationLevel() != IsolationLevel::NON_TRANSACTIONAL)); |
139 | 8 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::CreateTable() yb::client::TransactionTestBase<yb::ExternalMiniCluster>::CreateTable() Line | Count | Source | 136 | 8 | void TransactionTestBase<MiniClusterType>::CreateTable() { | 137 | 8 | KeyValueTableTest<MiniClusterType>::CreateTable( | 138 | 8 | Transactional(GetIsolationLevel() != IsolationLevel::NON_TRANSACTIONAL)); | 139 | 8 | } |
|
140 | | |
141 | | template <class MiniClusterType> |
142 | 0 | CHECKED_STATUS TransactionTestBase<MiniClusterType>::CreateTable(const Schema& schema) { |
143 | 0 | Schema new_schema { schema }; |
144 | 0 | new_schema.mutable_table_properties()->SetTransactional( |
145 | 0 | GetIsolationLevel() != IsolationLevel::NON_TRANSACTIONAL); |
146 | 0 | return KeyValueTableTest<MiniClusterType>::CreateTable(new_schema); |
147 | 0 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::CreateTable(yb::Schema const&) Unexecuted instantiation: yb::client::TransactionTestBase<yb::ExternalMiniCluster>::CreateTable(yb::Schema const&) |
148 | | |
149 | | template <class MiniClusterType> |
150 | 126 | uint64_t TransactionTestBase<MiniClusterType>::log_segment_size_bytes() const { |
151 | 126 | return 128; |
152 | 126 | } yb::client::TransactionTestBase<yb::MiniCluster>::log_segment_size_bytes() const Line | Count | Source | 150 | 118 | uint64_t TransactionTestBase<MiniClusterType>::log_segment_size_bytes() const { | 151 | 118 | return 128; | 152 | 118 | } |
yb::client::TransactionTestBase<yb::ExternalMiniCluster>::log_segment_size_bytes() const Line | Count | Source | 150 | 8 | uint64_t TransactionTestBase<MiniClusterType>::log_segment_size_bytes() const { | 151 | 8 | return 128; | 152 | 8 | } |
|
153 | | |
154 | | template <class MiniClusterType> |
155 | | Status TransactionTestBase<MiniClusterType>::WriteRows( |
156 | 0 | const YBSessionPtr& session, size_t transaction, const WriteOpType op_type, Flush flush) { |
157 | 0 | for (size_t r = 0; r != kNumRows; ++r) { |
158 | 0 | RETURN_NOT_OK(this->WriteRow( |
159 | 0 | session, |
160 | 0 | KeyForTransactionAndIndex(transaction, r), |
161 | 0 | ValueForTransactionAndIndex(transaction, r, op_type), |
162 | 0 | op_type, |
163 | 0 | flush)); |
164 | 0 | } |
165 | 0 | return Status::OK(); |
166 | 0 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::WriteRows(std::__1::shared_ptr<yb::client::YBSession> const&, unsigned long, yb::client::WriteOpType, yb::StronglyTypedBool<yb::client::Flush_Tag>) Unexecuted instantiation: yb::client::TransactionTestBase<yb::ExternalMiniCluster>::WriteRows(std::__1::shared_ptr<yb::client::YBSession> const&, unsigned long, yb::client::WriteOpType, yb::StronglyTypedBool<yb::client::Flush_Tag>) |
167 | | |
168 | | template <class MiniClusterType> |
169 | | void TransactionTestBase<MiniClusterType>::VerifyRow( |
170 | | int line, const YBSessionPtr& session, int32_t key, int32_t value, |
171 | 0 | const std::string& column) { |
172 | 0 | VLOG(4) << "Calling SelectRow"; |
173 | 0 | auto row = this->SelectRow(session, key, column); |
174 | 0 | ASSERT_TRUE(row.ok()) << "Bad status: " << row << ", originator: " << __FILE__ << ":" << line; |
175 | 0 | VLOG(4) << "SelectRow returned: " << *row; |
176 | 0 | ASSERT_EQ(value, *row) << "Originator: " << __FILE__ << ":" << line; |
177 | 0 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::VerifyRow(int, std::__1::shared_ptr<yb::client::YBSession> const&, int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: yb::client::TransactionTestBase<yb::ExternalMiniCluster>::VerifyRow(int, std::__1::shared_ptr<yb::client::YBSession> const&, int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) |
178 | | |
179 | | template <class MiniClusterType> |
180 | | void TransactionTestBase<MiniClusterType>::WriteData( |
181 | 0 | const WriteOpType op_type, size_t transaction) { |
182 | 0 | auto txn = CreateTransaction(); |
183 | 0 | ASSERT_OK(WriteRows(this->CreateSession(txn), transaction, op_type)); |
184 | 0 | ASSERT_OK(txn->CommitFuture().get()); |
185 | 0 | LOG(INFO) << "Committed: " << txn->id(); |
186 | 0 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::WriteData(yb::client::WriteOpType, unsigned long) Unexecuted instantiation: yb::client::TransactionTestBase<yb::ExternalMiniCluster>::WriteData(yb::client::WriteOpType, unsigned long) |
187 | | |
188 | | template <class MiniClusterType> |
189 | 0 | void TransactionTestBase<MiniClusterType>::WriteDataWithRepetition() { |
190 | 0 | auto txn = CreateTransaction(); |
191 | 0 | auto session = this->CreateSession(txn); |
192 | 0 | for (size_t r = 0; r != kNumRows; ++r) { |
193 | 0 | for (int j = 10; j--;) { |
194 | 0 | ASSERT_OK(this->WriteRow( |
195 | 0 | session, |
196 | 0 | KeyForTransactionAndIndex(0, r), |
197 | 0 | ValueForTransactionAndIndex(0, r, WriteOpType::INSERT) + j)); |
198 | 0 | } |
199 | 0 | } |
200 | 0 | ASSERT_OK(txn->CommitFuture().get()); |
201 | 0 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::WriteDataWithRepetition() Unexecuted instantiation: yb::client::TransactionTestBase<yb::ExternalMiniCluster>::WriteDataWithRepetition() |
202 | | |
203 | | namespace { |
204 | | |
205 | | YBTransactionPtr CreateTransactionHelper( |
206 | | TransactionManager* transaction_manager, |
207 | | SetReadTime set_read_time, |
208 | 13 | IsolationLevel isolation_level) { |
209 | 13 | if (isolation_level == IsolationLevel::NON_TRANSACTIONAL) { |
210 | 0 | return nullptr; |
211 | 0 | } |
212 | 13 | auto result = std::make_shared<YBTransaction>(transaction_manager); |
213 | 13 | ReadHybridTime read_time; |
214 | 13 | if (set_read_time) { |
215 | 0 | read_time = ReadHybridTime::FromHybridTimeRange(transaction_manager->clock()->NowRange()); |
216 | 0 | } |
217 | 13 | EXPECT_OK(result->Init(isolation_level, read_time)); |
218 | 13 | return result; |
219 | 13 | } |
220 | | |
221 | | } // anonymous namespace |
222 | | |
223 | | template <class MiniClusterType> |
224 | | YBTransactionPtr TransactionTestBase<MiniClusterType>::CreateTransaction( |
225 | 13 | SetReadTime set_read_time) { |
226 | 13 | return CreateTransactionHelper( |
227 | 13 | transaction_manager_.get_ptr(), set_read_time, GetIsolationLevel()); |
228 | 13 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::CreateTransaction(yb::StronglyTypedBool<yb::client::SetReadTime_Tag>) yb::client::TransactionTestBase<yb::ExternalMiniCluster>::CreateTransaction(yb::StronglyTypedBool<yb::client::SetReadTime_Tag>) Line | Count | Source | 225 | 13 | SetReadTime set_read_time) { | 226 | 13 | return CreateTransactionHelper( | 227 | 13 | transaction_manager_.get_ptr(), set_read_time, GetIsolationLevel()); | 228 | 13 | } |
|
229 | | |
230 | | template <class MiniClusterType> |
231 | | YBTransactionPtr TransactionTestBase<MiniClusterType>::CreateTransaction2( |
232 | 0 | SetReadTime set_read_time) { |
233 | 0 | return CreateTransactionHelper( |
234 | 0 | transaction_manager2_.get_ptr(), set_read_time, GetIsolationLevel()); |
235 | 0 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::CreateTransaction2(yb::StronglyTypedBool<yb::client::SetReadTime_Tag>) Unexecuted instantiation: yb::client::TransactionTestBase<yb::ExternalMiniCluster>::CreateTransaction2(yb::StronglyTypedBool<yb::client::SetReadTime_Tag>) |
236 | | |
237 | | template <class MiniClusterType> |
238 | | void TransactionTestBase<MiniClusterType>::VerifyRows( |
239 | | const YBSessionPtr& session, size_t transaction, const WriteOpType op_type, |
240 | 0 | const std::string& column) { |
241 | 0 | std::vector<client::YBqlReadOpPtr> ops; |
242 | 0 | for (size_t r = 0; r != kNumRows; ++r) { |
243 | 0 | ops.push_back(ReadRow(session, KeyForTransactionAndIndex(transaction, r), column)); |
244 | 0 | } |
245 | 0 | ASSERT_OK(session->Flush()); |
246 | 0 | for (size_t r = 0; r != kNumRows; ++r) { |
247 | 0 | SCOPED_TRACE(Format("Row: $0, key: $1", r, KeyForTransactionAndIndex(transaction, r))); |
248 | 0 | auto& op = ops[r]; |
249 | 0 | ASSERT_EQ(op->response().status(), QLResponsePB::YQL_STATUS_OK) |
250 | 0 | << QLResponsePB_QLStatus_Name(op->response().status()); |
251 | 0 | auto rowblock = yb::ql::RowsResult(op.get()).GetRowBlock(); |
252 | 0 | ASSERT_EQ(rowblock->row_count(), 1); |
253 | 0 | const auto& first_column = rowblock->row(0).column(0); |
254 | 0 | ASSERT_EQ(InternalType::kInt32Value, first_column.type()); |
255 | 0 | ASSERT_EQ(first_column.int32_value(), ValueForTransactionAndIndex(transaction, r, op_type)); |
256 | 0 | } |
257 | 0 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::VerifyRows(std::__1::shared_ptr<yb::client::YBSession> const&, unsigned long, yb::client::WriteOpType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: yb::client::TransactionTestBase<yb::ExternalMiniCluster>::VerifyRows(std::__1::shared_ptr<yb::client::YBSession> const&, unsigned long, yb::client::WriteOpType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) |
258 | | |
259 | | template <class MiniClusterType> |
260 | | YBqlReadOpPtr TransactionTestBase<MiniClusterType>::ReadRow( |
261 | 0 | const YBSessionPtr& session, int32_t key, const std::string& column) { |
262 | 0 | auto op = table_.NewReadOp(); |
263 | 0 | auto* const req = op->mutable_request(); |
264 | 0 | QLAddInt32HashValue(req, key); |
265 | 0 | table_.AddColumns({column}, req); |
266 | 0 | session->Apply(op); |
267 | 0 | return op; |
268 | 0 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::ReadRow(std::__1::shared_ptr<yb::client::YBSession> const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: yb::client::TransactionTestBase<yb::ExternalMiniCluster>::ReadRow(std::__1::shared_ptr<yb::client::YBSession> const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) |
269 | | |
270 | | template <class MiniClusterType> |
271 | | void TransactionTestBase<MiniClusterType>::VerifyData( |
272 | 0 | size_t num_transactions, const WriteOpType op_type, const std::string& column) { |
273 | 0 | VLOG(4) << "Verifying data..." << std::endl; |
274 | 0 | auto session = this->CreateSession(); |
275 | 0 | for (size_t i = 0; i != num_transactions; ++i) { |
276 | 0 | VerifyRows(session, i, op_type, column); |
277 | 0 | } |
278 | 0 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::VerifyData(unsigned long, yb::client::WriteOpType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: yb::client::TransactionTestBase<yb::ExternalMiniCluster>::VerifyData(unsigned long, yb::client::WriteOpType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) |
279 | | |
280 | | template <> |
281 | 0 | bool TransactionTestBase<MiniCluster>::HasTransactions() { |
282 | 0 | for (size_t i = 0; i != cluster_->num_tablet_servers(); ++i) { |
283 | 0 | auto* tablet_manager = cluster_->mini_tablet_server(i)->server()->tablet_manager(); |
284 | 0 | auto peers = tablet_manager->GetTabletPeers(); |
285 | 0 | for (const auto& peer : peers) { |
286 | 0 | if (!peer->consensus()) { |
287 | 0 | return true; // Report true, since we could have transactions on this non ready peer. |
288 | 0 | } |
289 | 0 | if (peer->consensus()->GetLeaderStatus() != |
290 | 0 | consensus::LeaderStatus::NOT_LEADER && |
291 | 0 | peer->tablet()->transaction_coordinator() && |
292 | 0 | peer->tablet()->transaction_coordinator()->test_count_transactions()) { |
293 | 0 | return true; |
294 | 0 | } |
295 | 0 | } |
296 | 0 | } |
297 | 0 | return false; |
298 | 0 | } |
299 | | |
300 | | template <> |
301 | 0 | size_t TransactionTestBase<MiniCluster>::CountRunningTransactions() { |
302 | 0 | return yb::CountRunningTransactions(cluster_.get()); |
303 | 0 | } |
304 | | |
305 | | template <> |
306 | 0 | void TransactionTestBase<MiniCluster>::AssertNoRunningTransactions() { |
307 | 0 | yb::AssertNoRunningTransactions(cluster_.get()); |
308 | 0 | } |
309 | | |
310 | | template <> |
311 | 0 | bool TransactionTestBase<MiniCluster>::CheckAllTabletsRunning() { |
312 | 0 | bool result = true; |
313 | 0 | size_t count = 0; |
314 | 0 | for (size_t i = 0; i != cluster_->num_tablet_servers(); ++i) { |
315 | 0 | auto peers = cluster_->mini_tablet_server(i)->server()->tablet_manager()->GetTabletPeers(); |
316 | 0 | if (i == 0) { |
317 | 0 | count = peers.size(); |
318 | 0 | } else if (count != peers.size()) { |
319 | 0 | LOG(WARNING) << "Different number of tablets in tservers: " |
320 | 0 | << count << " vs " << peers.size() << " at " << i; |
321 | 0 | result = false; |
322 | 0 | } |
323 | 0 | for (const auto& peer : peers) { |
324 | 0 | auto status = peer->CheckRunning(); |
325 | 0 | if (!status.ok()) { |
326 | 0 | LOG(WARNING) << Format("T $0 P $1 is not running: $2", peer->tablet_id(), |
327 | 0 | peer->permanent_uuid(), status); |
328 | 0 | result = false; |
329 | 0 | } |
330 | 0 | } |
331 | 0 | } |
332 | 0 | return result; |
333 | 0 | } |
334 | | |
335 | | template <class MiniClusterType> |
336 | 21 | IsolationLevel TransactionTestBase<MiniClusterType>::GetIsolationLevel() { |
337 | 21 | return isolation_level_; |
338 | 21 | } Unexecuted instantiation: yb::client::TransactionTestBase<yb::MiniCluster>::GetIsolationLevel() yb::client::TransactionTestBase<yb::ExternalMiniCluster>::GetIsolationLevel() Line | Count | Source | 336 | 21 | IsolationLevel TransactionTestBase<MiniClusterType>::GetIsolationLevel() { | 337 | 21 | return isolation_level_; | 338 | 21 | } |
|
339 | | |
340 | | template <class MiniClusterType> |
341 | 96 | void TransactionTestBase<MiniClusterType>::SetIsolationLevel(IsolationLevel isolation_level) { |
342 | 96 | isolation_level_ = isolation_level; |
343 | 96 | } yb::client::TransactionTestBase<yb::MiniCluster>::SetIsolationLevel(yb::IsolationLevel) Line | Count | Source | 341 | 96 | void TransactionTestBase<MiniClusterType>::SetIsolationLevel(IsolationLevel isolation_level) { | 342 | 96 | isolation_level_ = isolation_level; | 343 | 96 | } |
Unexecuted instantiation: yb::client::TransactionTestBase<yb::ExternalMiniCluster>::SetIsolationLevel(yb::IsolationLevel) |
344 | | |
345 | | template class TransactionTestBase<MiniCluster>; |
346 | | template class TransactionTestBase<ExternalMiniCluster>; |
347 | | |
348 | | } // namespace client |
349 | | } // namespace yb |