From 2879a89a338e83c9a09f76216f078e89dd22cb34 Mon Sep 17 00:00:00 2001 From: GongYusen <986957406@qq.com> Date: Wed, 12 Feb 2025 03:16:06 +0000 Subject: [PATCH] Fix the issue of inner SQL execution not being locked on the session. --- src/observer/ob_inner_sql_connection.cpp | 33 +++++++++++++++++++++++- src/observer/ob_inner_sql_connection.h | 3 +++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/observer/ob_inner_sql_connection.cpp b/src/observer/ob_inner_sql_connection.cpp index ee1def62fc..3700b89b6b 100644 --- a/src/observer/ob_inner_sql_connection.cpp +++ b/src/observer/ob_inner_sql_connection.cpp @@ -132,7 +132,8 @@ ObInnerSQLConnection::ObInnerSQLConnection() use_external_session_(false), group_id_(0), user_timeout_(0), - diagnostic_info_(nullptr) + diagnostic_info_(nullptr), + inner_sess_query_locked_(false) { free_session_ctx_.sessid_ = ObSQLSessionInfo::INVALID_SESSID; @@ -222,6 +223,7 @@ int ObInnerSQLConnection::init(ObInnerSQLConnectionPool *pool, int ObInnerSQLConnection::destroy() { int ret = OB_SUCCESS; + try_release_query_lock(); // uninited connection can be destroy too if (inited_) { if (0 < ref_cnt_) { @@ -285,6 +287,31 @@ void ObInnerSQLConnection::unref() } } +int ObInnerSQLConnection::try_acquire_query_lock() +{ + int ret = OB_SUCCESS; + if (!inner_sess_query_locked_) { + if (OB_FAIL(inner_session_->get_query_lock().lock())) { + LOG_WARN("fail to acquire query lock", K(ret), KPC(inner_session_)); + } else { + inner_sess_query_locked_ = true; + } + } + return ret; +} + +void ObInnerSQLConnection::try_release_query_lock() +{ + int ret = OB_SUCCESS; + if (inner_sess_query_locked_) { + if (OB_FAIL(inner_session_->get_query_lock().unlock())) { + LOG_WARN("fail to release query lock", K(ret), KPC(inner_session_)); + } else { + inner_sess_query_locked_ = false; + } + } +} + int ObInnerSQLConnection::set_ddl_info(const void *ddl_info) { int ret = OB_SUCCESS; @@ -474,6 +501,9 @@ int ObInnerSQLConnection::init_session(sql::ObSQLSessionInfo* extern_session, co } } } + if (OB_SUCC(ret) && OB_FAIL(try_acquire_query_lock())) { + LOG_WARN("failed to acquire inner session query lock", K(ret)); + } } else { extern_session_ = extern_session; } @@ -2291,6 +2321,7 @@ int ObInnerSQLConnection::destroy_inner_session() int ret = OB_SUCCESS; LOG_DEBUG("begin destroying inner session", K(ret), KP(inner_session_), K(free_session_ctx_), K(lbt())); if (NULL != inner_session_) { + try_release_query_lock(); if (INNER_SQL_SESS_ID == free_session_ctx_.sessid_) { inner_session_->set_session_sleep(); inner_session_->~ObSQLSessionInfo(); diff --git a/src/observer/ob_inner_sql_connection.h b/src/observer/ob_inner_sql_connection.h index 89786e5f7a..e22ee9deef 100644 --- a/src/observer/ob_inner_sql_connection.h +++ b/src/observer/ob_inner_sql_connection.h @@ -194,6 +194,8 @@ public: bool is_nested_conn(); virtual void set_user_timeout(int64_t timeout) { user_timeout_ = timeout; } virtual int64_t get_user_timeout() const { return user_timeout_; } + int try_acquire_query_lock(); + void try_release_query_lock(); void ref(); // when ref count decrease to zero, revert connection to connection pool. void unref(); @@ -434,6 +436,7 @@ private: int64_t user_timeout_; sql::ObFreeSessionCtx free_session_ctx_; ObDiagnosticInfo *diagnostic_info_; + bool inner_sess_query_locked_; DISABLE_COPY_ASSIGN(ObInnerSQLConnection); };