From 2decc39f5e2bc8418c8cfeea74d51ea11cbb47f0 Mon Sep 17 00:00:00 2001 From: chinaxing Date: Thu, 26 Oct 2023 02:13:32 +0000 Subject: [PATCH] [CP] fix inner sql hang in rollback-stmt when tenant is dropping --- src/storage/tx/ob_trans_define.h | 1 - src/storage/tx/ob_trans_part_ctx.cpp | 1 + src/storage/tx/ob_tx_api.cpp | 12 +++++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/storage/tx/ob_trans_define.h b/src/storage/tx/ob_trans_define.h index a6a08e70b..9234f89e7 100644 --- a/src/storage/tx/ob_trans_define.h +++ b/src/storage/tx/ob_trans_define.h @@ -1720,7 +1720,6 @@ public: bool is_sub2pc_; }; -static const int64_t GET_GTS_AHEAD_INTERVAL = 300; static const int64_t USEC_PER_SEC = 1000 * 1000; struct ObMulSourceDataNotifyArg diff --git a/src/storage/tx/ob_trans_part_ctx.cpp b/src/storage/tx/ob_trans_part_ctx.cpp index 786d95ef4..ef2717b07 100755 --- a/src/storage/tx/ob_trans_part_ctx.cpp +++ b/src/storage/tx/ob_trans_part_ctx.cpp @@ -1149,6 +1149,7 @@ int ObPartTransCtx::get_gts_callback(const MonotonicTs srr, } else { TRANS_LOG(ERROR, "unexpected sub state", K(*this)); } + const int64_t GET_GTS_AHEAD_INTERVAL = GCONF._ob_get_gts_ahead_interval; set_trans_need_wait_wrap_(receive_gts_ts, GET_GTS_AHEAD_INTERVAL); // the same as before prepare mt_ctx_.set_trans_version(gts); diff --git a/src/storage/tx/ob_tx_api.cpp b/src/storage/tx/ob_tx_api.cpp index 83449dc22..ffeb9234f 100644 --- a/src/storage/tx/ob_tx_api.cpp +++ b/src/storage/tx/ob_tx_api.cpp @@ -18,6 +18,7 @@ #include "storage/tx/wrs/ob_weak_read_service.h" #include "storage/tx/wrs/ob_weak_read_util.h" #include "ob_xa_service.h" +#include "observer/omt/ob_tenant.h" // ------------------------------------------------------------------------------------------ // Implimentation notes: // there are two relation we need care: @@ -1635,6 +1636,12 @@ inline int ObTransService::sync_rollback_savepoint__(ObTxDesc &tx, retries = 0; int64_t min_retry_intval = 10 * 1000; // 10 ms expire_ts = std::max(ObTimeUtility::current_time() + MIN_WAIT_TIME, expire_ts); + share::ObTenantBase *tenant_base = MTL_CTX(); + omt::ObTenant *tenant = static_cast(tenant_base); + if (OB_ISNULL(tenant_base)) { + ret = OB_ERR_UNEXPECTED; + TRANS_LOG(WARN, "get tenant is null", K(ret)); + } while (OB_SUCC(ret)) { int64_t retry_intval = std::min(min_retry_intval * (1 + retries), max_retry_intval); int64_t waittime = std::min(expire_ts - ObTimeUtility::current_time(), retry_intval); @@ -1665,7 +1672,7 @@ inline int ObTransService::sync_rollback_savepoint__(ObTxDesc &tx, int rpc_ret = OB_SUCCESS; if (OB_FAIL(tx.rpc_cond_.wait(waittime, rpc_ret))) { TRANS_LOG(WARN, "tx rpc condition wakeup", K(ret), - K(waittime), K(rpc_ret), K(expire_ts), K(remain), K(remain_cnt), K(retries), + K(tx.tx_id_), K(waittime), K(rpc_ret), K(expire_ts), K(remain), K(remain_cnt), K(retries), K_(tx.state)); // if trans is terminated, rollback savepoint should be terminated // NOTE that this case is only for xa trans @@ -1675,6 +1682,9 @@ inline int ObTransService::sync_rollback_savepoint__(ObTxDesc &tx, // 3. branch 1 receives callback of rollback savepoint if (tx.is_terminated()) { ret = OB_TRANS_HAS_DECIDED; + } else if (retries > 10 && tenant->has_stopped()) { + ret = OB_TENANT_NOT_IN_SERVER; + TRANS_LOG(WARN, "tenant has been stopped", K(ret)); } else { ret = OB_SUCCESS; }