[4.x] acquire data lock before set tx desc in session
This commit is contained in:
@ -160,6 +160,7 @@ int ObSqlTransControl::explicit_start_trans(ObExecContext &ctx, const bool read_
|
||||
OZ (get_tx_service(session, txs), tenant_id);
|
||||
|
||||
if (OB_SUCC(ret) && OB_NOT_NULL(session->get_tx_desc())) {
|
||||
ObSQLSessionInfo::LockGuard data_lock_guard(session->get_thread_data_lock());
|
||||
auto *tx_desc = session->get_tx_desc();
|
||||
if (tx_desc->get_tenant_id() != tenant_id) {
|
||||
LOG_ERROR("switch tenant but hold tx_desc", K(tenant_id), KPC(tx_desc));
|
||||
@ -175,6 +176,7 @@ int ObSqlTransControl::explicit_start_trans(ObExecContext &ctx, const bool read_
|
||||
OX (tx_id = session->get_tx_desc()->get_tx_id());
|
||||
|
||||
if (OB_FAIL(ret) && cleanup && OB_NOT_NULL(txs) && OB_NOT_NULL(session->get_tx_desc())) {
|
||||
ObSQLSessionInfo::LockGuard data_lock_guard(session->get_thread_data_lock());
|
||||
txs->release_tx(*session->get_tx_desc());
|
||||
session->get_tx_desc() = NULL;
|
||||
}
|
||||
@ -349,6 +351,7 @@ int ObSqlTransControl::kill_tx(ObSQLSessionInfo *session, int cause)
|
||||
const ObTransID tx_id = tx_desc->get_tx_id();
|
||||
auto tx_free_route_tmp = session->is_txn_free_route_temp();
|
||||
MTL_SWITCH(tx_tenant_id) {
|
||||
ObSQLSessionInfo::LockGuard data_lock_guard(session->get_thread_data_lock());
|
||||
if (tx_free_route_tmp) {
|
||||
// if XA-txn is on this server, we have acquired its ref, release ref
|
||||
// and disassocate with session
|
||||
@ -1112,6 +1115,7 @@ int ObSqlTransControl::reset_session_tx_state(ObBasicSessionInfo *session, bool
|
||||
int ret = OB_SUCCESS;
|
||||
LOG_DEBUG("reset session tx state", KPC(session->get_tx_desc()), K(lbt()));
|
||||
if (OB_NOT_NULL(session->get_tx_desc())) {
|
||||
ObSQLSessionInfo::LockGuard data_lock_guard(session->get_thread_data_lock());
|
||||
auto &tx_desc = *session->get_tx_desc();
|
||||
auto tx_id = tx_desc.get_tx_id();
|
||||
auto effect_tid = session->get_effective_tenant_id();
|
||||
@ -1321,6 +1325,7 @@ int ObSqlTransControl::check_ls_readable(const uint64_t tenant_id,
|
||||
int ObSqlTransControl::update_txn_##name##_state(ObSQLSessionInfo &session, const char* buf, const int64_t len, int64_t &pos) \
|
||||
{ \
|
||||
int ret = OB_SUCCESS; \
|
||||
ObSQLSessionInfo::LockGuard data_lock_guard(session.get_thread_data_lock()); \
|
||||
transaction::ObTransService *txs = NULL; \
|
||||
OZ (get_tx_service(&session, txs)); \
|
||||
auto &tx_desc = session.get_tx_desc(); \
|
||||
|
@ -1037,6 +1037,7 @@ int ObDynamicSampling::prepare_and_store_session(ObSQLSessionInfo *session,
|
||||
if (OB_FAIL(session->save_session(*session_value))) {
|
||||
LOG_WARN("failed to save session", K(ret));
|
||||
} else {
|
||||
ObSQLSessionInfo::LockGuard data_lock_guard(session->get_thread_data_lock());
|
||||
nested_count = session->get_nested_count();
|
||||
IS_NO_BACKSLASH_ESCAPES(session->get_sql_mode(), is_no_backslash_escapes);
|
||||
session->set_sql_mode(session->get_sql_mode() & ~SMO_NO_BACKSLASH_ESCAPES);
|
||||
@ -1068,6 +1069,7 @@ int ObDynamicSampling::restore_session(ObSQLSessionInfo *session,
|
||||
} else if (OB_FAIL(session->restore_session(*session_value))) {
|
||||
LOG_WARN("failed to restore session", K(ret));
|
||||
} else {
|
||||
ObSQLSessionInfo::LockGuard data_lock_guard(session->get_thread_data_lock());
|
||||
session->set_nested_count(nested_count);
|
||||
if (is_no_backslash_escapes) {
|
||||
session->set_sql_mode(session->get_sql_mode() | SMO_NO_BACKSLASH_ESCAPES);
|
||||
|
@ -5786,6 +5786,7 @@ int ObBasicSessionInfo::end_nested_session(StmtSavedValue &saved_value)
|
||||
int ObBasicSessionInfo::trans_save_session(TransSavedValue &saved_value)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
LockGuard lock_guard(thread_data_mutex_);
|
||||
OZ (base_save_session(saved_value, false));
|
||||
/*
|
||||
* save transaction context
|
||||
@ -5804,6 +5805,7 @@ int ObBasicSessionInfo::trans_save_session(TransSavedValue &saved_value)
|
||||
int ObBasicSessionInfo::trans_restore_session(TransSavedValue &saved_value)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
LockGuard lock_guard(thread_data_mutex_);
|
||||
OX (nested_count_ = saved_value.nested_count_);
|
||||
OX (trans_flags_ = saved_value.trans_flags_);
|
||||
/*
|
||||
|
Reference in New Issue
Block a user