From 8e6d0bc4bf9c5cfec75dd20544d82b1b8688d2ef Mon Sep 17 00:00:00 2001 From: chinaxing Date: Mon, 20 May 2024 10:44:10 +0000 Subject: [PATCH] fix TxDesc release when tenant removed and fix txdesc debug link-list broken --- src/sql/session/ob_basic_session_info.cpp | 3 +++ src/storage/tx/ob_trans_define_v4.h | 18 ++++++++++++++++-- src/storage/tx/ob_trans_service_v4.cpp | 10 ++++++++++ src/storage/tx/ob_trans_service_v4.h | 5 +++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/sql/session/ob_basic_session_info.cpp b/src/sql/session/ob_basic_session_info.cpp index c562657af..82bf237de 100644 --- a/src/sql/session/ob_basic_session_info.cpp +++ b/src/sql/session/ob_basic_session_info.cpp @@ -334,6 +334,9 @@ void ObBasicSessionInfo::reset(bool skip_sys_var) MAKE_TENANT_SWITCH_SCOPE_GUARD(guard); if (OB_SUCC(guard.switch_to(tx_desc_->get_tenant_id(), false))) { MTL(transaction::ObTransService*)->release_tx(*tx_desc_); + } else { + LOG_WARN("tenant env not exist, force release tx", KP(tx_desc_), K(tx_desc_->get_tx_id())); + transaction::ObTransService::force_release_tx_when_session_destroy(*tx_desc_); } tx_desc_ = NULL; } diff --git a/src/storage/tx/ob_trans_define_v4.h b/src/storage/tx/ob_trans_define_v4.h index e0f1dba50..27ac0ec2c 100644 --- a/src/storage/tx/ob_trans_define_v4.h +++ b/src/storage/tx/ob_trans_define_v4.h @@ -854,13 +854,20 @@ public: , list_() #endif {} +#ifdef ENABLE_DEBUG_LOG + ~ObTxDescAlloc() + { + ObSpinLockGuard guard(lk_); + list_.remove(); + } +#endif ObTxDesc* alloc_value() { ATOMIC_INC(&alloc_cnt_); ObTxDesc *it = op_alloc(ObTxDesc); #ifdef ENABLE_DEBUG_LOG - ObSpinLockGuard guard(lk_); - list_.insert(it->alloc_link_); + ObSpinLockGuard guard(lk_); + list_.insert(it->alloc_link_); #endif return it; } @@ -875,6 +882,10 @@ public: op_free(v); } } + static void force_free(ObTxDesc *v) + { + op_free(v); + } int64_t get_alloc_cnt() const { return ATOMIC_LOAD(&alloc_cnt_); } #ifdef ENABLE_DEBUG_LOG template @@ -898,6 +909,9 @@ public: ObTxDesc::DLink list_; #endif }; + static void force_release(ObTxDesc &tx) { + ObTxDescAlloc::force_free(&tx); + } share::ObLightHashMap map_; std::function tx_id_allocator_; ObTransService &txs_; diff --git a/src/storage/tx/ob_trans_service_v4.cpp b/src/storage/tx/ob_trans_service_v4.cpp index 9faab0267..903769ef0 100644 --- a/src/storage/tx/ob_trans_service_v4.cpp +++ b/src/storage/tx/ob_trans_service_v4.cpp @@ -3932,5 +3932,15 @@ int ObTransService::handle_ask_tx_state_for_4377(const ObAskTxStateFor4377Msg &m TRANS_LOG(INFO, "handle ask tx state for 4377", K(ret), K(msg), K(is_alive)); return ret; } + +void ObTransService::force_release_tx_when_session_destroy(ObTxDesc &tx) +{ + { + ObSpinLockGuard guard(tx.lock_); + TRANS_LOG_RET(WARN, OB_SUCCESS, "txdesc will be released forcedly", K(tx)); + tx.print_trace_(); + } + ObTxDescMgr::force_release(tx); +} } // transaction } // ocenabase diff --git a/src/storage/tx/ob_trans_service_v4.h b/src/storage/tx/ob_trans_service_v4.h index a8a0614d9..7b425f23e 100644 --- a/src/storage/tx/ob_trans_service_v4.h +++ b/src/storage/tx/ob_trans_service_v4.h @@ -21,6 +21,11 @@ int remove_ls(const share::ObLSID &ls_id, */ int acquire_tx(const char* buf, const int64_t len, int64_t &pos, ObTxDesc *&tx); int release_tx_ref(ObTxDesc &tx); +/* + * used when session destroyed + * and TxDesc which referenced by session and the tenant unit has removed + */ +static void force_release_tx_when_session_destroy(ObTxDesc &tx); /* * interrupt any work in progress thread */