Skip to content

Commit

Permalink
[#3989] Disable transaction timeout in SealTxnTest.NumBatchesDisable
Browse files Browse the repository at this point in the history
Summary:
During SealTxnTest.NumBatchesDisable we perform cluster restart right after writing data.
Sometimes it causes transaction to expire.
While it is expected, we could avoid handling this scenario in this particular test by disabling transaction timeouts.

Test Plan: ybd debug --gtest_filter SealTxnTest.NumBatchesDisable -n 100 -- -p 8

Reviewers: bogdan

Reviewed By: bogdan

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D8151
  • Loading branch information
spolitov committed Mar 19, 2020
1 parent f99f062 commit 323fa8d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/yb/client/seal-txn-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

using namespace std::literals;

DECLARE_int32(TEST_write_rejection_percentage);
DECLARE_bool(TEST_fail_on_replicated_batch_idx_set_in_txn_record);
DECLARE_bool(enable_load_balancing);
DECLARE_bool(enable_transaction_sealing);
DECLARE_bool(TEST_fail_on_replicated_batch_idx_set_in_txn_record);
DECLARE_int32(TEST_write_rejection_percentage);
DECLARE_int64(transaction_rpc_timeout_ms);

namespace yb {
namespace client {
Expand Down Expand Up @@ -97,6 +98,9 @@ TEST_F(SealTxnTest, NumBatchesWithRejection) {
// Check that we could disable writing information about the number of batches,
// since it is required for backward compatibility.
TEST_F(SealTxnTest, NumBatchesDisable) {
DisableTransactionTimeout();
// Should be enough for the restarted servers to be back online
FLAGS_transaction_rpc_timeout_ms = 20000 * kTimeMultiplier;
FLAGS_enable_transaction_sealing = false;
FLAGS_TEST_fail_on_replicated_batch_idx_set_in_txn_record = true;

Expand Down
24 changes: 17 additions & 7 deletions src/yb/client/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -807,10 +807,17 @@ class YBTransaction::Impl final {
return;
}

if (status != TransactionStatus::CREATED &&
GetAtomicFlag(&FLAGS_transaction_disable_heartbeat_in_tests)) {
HeartbeatDone(Status::OK(), tserver::UpdateTransactionResponsePB(), status, transaction);
return;
VLOG_WITH_PREFIX(4) << __func__ << "(" << TransactionStatus_Name(status) << ")";

MonoDelta timeout;
if (status != TransactionStatus::CREATED) {
if (GetAtomicFlag(&FLAGS_transaction_disable_heartbeat_in_tests)) {
HeartbeatDone(Status::OK(), tserver::UpdateTransactionResponsePB(), status, transaction);
return;
}
timeout = std::chrono::microseconds(FLAGS_transaction_heartbeat_usec);
} else {
timeout = TransactionRpcTimeout();
}

tserver::UpdateTransactionRequestPB req;
Expand All @@ -821,7 +828,7 @@ class YBTransaction::Impl final {
state.set_status(status);
manager_->rpcs().RegisterAndStart(
UpdateTransaction(
TransactionRpcDeadline(),
CoarseMonoClock::now() + timeout,
status_tablet_.get(),
manager_->client(),
&req,
Expand Down Expand Up @@ -850,14 +857,17 @@ class YBTransaction::Impl final {
UpdateClock(response, manager_);
manager_->rpcs().Unregister(&heartbeat_handle_);

VLOG_WITH_PREFIX(4) << __func__ << "(" << status << ", "
<< TransactionStatus_Name(transaction_status) << ")";

if (status.ok()) {
if (transaction_status == TransactionStatus::CREATED) {
NotifyWaiters(Status::OK());
}
std::weak_ptr<YBTransaction> weak_transaction(transaction);
manager_->client()->messenger()->scheduler().Schedule(
[this, weak_transaction](const Status&) {
SendHeartbeat(TransactionStatus::PENDING, metadata_.transaction_id, weak_transaction);
[this, weak_transaction, id = metadata_.transaction_id](const Status&) {
SendHeartbeat(TransactionStatus::PENDING, id, weak_transaction);
},
std::chrono::microseconds(FLAGS_transaction_heartbeat_usec));
} else {
Expand Down

0 comments on commit 323fa8d

Please sign in to comment.