From 323fa8d28326f4d5cd4d3d558d806ede9358ff01 Mon Sep 17 00:00:00 2001 From: Sergei Politov Date: Thu, 19 Mar 2020 08:47:14 +0300 Subject: [PATCH] [#3989] Disable transaction timeout in SealTxnTest.NumBatchesDisable 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 --- src/yb/client/seal-txn-test.cc | 8 ++++++-- src/yb/client/transaction.cc | 24 +++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/yb/client/seal-txn-test.cc b/src/yb/client/seal-txn-test.cc index d89f5bfaa44e..20806f030a55 100644 --- a/src/yb/client/seal-txn-test.cc +++ b/src/yb/client/seal-txn-test.cc @@ -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 { @@ -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; diff --git a/src/yb/client/transaction.cc b/src/yb/client/transaction.cc index b38426f0dbc8..f1c6026f9947 100644 --- a/src/yb/client/transaction.cc +++ b/src/yb/client/transaction.cc @@ -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; @@ -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, @@ -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 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 {