diff --git a/src/storage/tx/ob_xa_ctx.cpp b/src/storage/tx/ob_xa_ctx.cpp index c9c12faa48..35b3c0505c 100644 --- a/src/storage/tx/ob_xa_ctx.cpp +++ b/src/storage/tx/ob_xa_ctx.cpp @@ -1776,11 +1776,18 @@ int ObXACtx::start_stmt(const ObXATransID &xid, const uint32_t session_id) } else if (OB_ISNULL(tx_desc_)) { ret = OB_ERR_UNEXPECTED; TRANS_LOG(WARN, "trans desc is null", K(ret), K(*this)); - } else if (OB_FAIL(create_xa_savepoint_if_need_(xid, session_id))) { - TRANS_LOG(WARN, "check xa savepoint fail", K(ret), K(xid), K(session_id), K(*this)); + } else if (is_exiting_) { + ret = OB_ERR_UNEXPECTED; + TRANS_LOG(WARN, "xa ctx is exiting", K(ret), K(*this)); + } else if (is_terminated_) { + // NOTE that anohter error code maybe required for loosely coupled mode + ret = OB_TRANS_XA_BRANCH_FAIL; + TRANS_LOG(INFO, "xa trans has terminated", K(ret), K(xid), K(*this)); } else if (!is_tightly_coupled_) { // loosely coupled mode - // do nothing + if (OB_FAIL(create_xa_savepoint_if_need_(xid, session_id))) { + TRANS_LOG(WARN, "check xa savepoint fail", K(ret), K(xid), K(session_id), K(*this)); + } } else { // tightly coupled mode if (is_executing_) { @@ -1924,6 +1931,9 @@ int ObXACtx::end_stmt(const ObXATransID &xid) } else if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; TRANS_LOG(WARN, "xa ctx not inited", K(ret), K(*this)); + } else if (is_exiting_) { + ret = OB_ERR_UNEXPECTED; + TRANS_LOG(WARN, "xa ctx is exiting", K(ret), K(*this)); } else if (!is_tightly_coupled_) { // do nothing } else if (OB_UNLIKELY(!is_executing_)) { @@ -2269,7 +2279,7 @@ bool ObXACtx::check_response_(const int64_t response_id, // wait the result of start stmt // this function is called only when SUCCESS is returned by start_stmt (local/remote) -int ObXACtx::wait_start_stmt() +int ObXACtx::wait_start_stmt(const uint32_t session_id) { int ret = OB_SUCCESS; int result = OB_SUCCESS; @@ -2311,8 +2321,12 @@ int ObXACtx::wait_start_stmt() TRANS_LOG(WARN, "fail to wait start stmt", K(ret), K(*this)); is_executing_ = false; executing_xid_.reset(); + } else if (OB_FAIL(create_xa_savepoint_if_need_(executing_xid_, session_id))) { + TRANS_LOG(WARN, "check xa savepoint fail", K(ret), K(session_id), K(*this)); + } else { + // do nothing } - } + } return ret; } diff --git a/src/storage/tx/ob_xa_ctx.h b/src/storage/tx/ob_xa_ctx.h index c79fc999f7..9881462aa8 100644 --- a/src/storage/tx/ob_xa_ctx.h +++ b/src/storage/tx/ob_xa_ctx.h @@ -106,7 +106,7 @@ public: ObTxDesc *&tx_desc); int xa_end(const ObXATransID &xid, const int64_t flags, ObTxDesc *&tx_desc); int start_stmt(const ObXATransID &xid, const uint32_t session_id); - int wait_start_stmt(); + int wait_start_stmt(const uint32_t session_id); int end_stmt(const ObXATransID &xid); const ObXATransID &get_executing_xid() const { return executing_xid_; } int one_phase_end_trans(const ObXATransID &xid, diff --git a/src/storage/tx/ob_xa_service.cpp b/src/storage/tx/ob_xa_service.cpp index 54388f55c7..018ce8378e 100644 --- a/src/storage/tx/ob_xa_service.cpp +++ b/src/storage/tx/ob_xa_service.cpp @@ -1428,7 +1428,7 @@ int ObXAService::start_stmt(const ObXATransID &xid, const uint32_t session_id, O TRANS_LOG(WARN, "unexpected trans descriptor", K(ret), K(tx_id), K(xid)); } else if (OB_FAIL(xa_ctx->start_stmt(xid, session_id))) { TRANS_LOG(WARN, "xa trans start stmt failed", K(ret), K(tx_id), K(xid)); - } else if (OB_FAIL(xa_ctx->wait_start_stmt())) { + } else if (OB_FAIL(xa_ctx->wait_start_stmt(session_id))) { TRANS_LOG(WARN, "fail to wait start stmt", K(ret), K(tx_id), K(xid)); } else { TRANS_LOG(INFO, "xa trans start stmt", K(ret), K(tx_id), K(xid));