Skip to content

Commit a54abf0

Browse files
committed
innobase_kill_query(): Use lock_trx_handle_wait()
The caller of THD::awake() should never hold any InnoDB mutexes, so we can always acquire lock_sys->mutex and trx->mutex.
1 parent 4d24897 commit a54abf0

File tree

2 files changed

+24
-128
lines changed

2 files changed

+24
-128
lines changed

storage/innobase/handler/ha_innodb.cc

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,9 @@ innobase_close_connection(
11991199
THD* thd); /*!< in: MySQL thread handle for
12001200
which to close the connection */
12011201

1202-
static void innobase_kill_query(handlerton *hton, THD* thd, enum thd_kill_levels level);
1202+
/** Cancel any pending lock request associated with the current THD.
1203+
@sa THD::awake() @sa ha_kill_query() */
1204+
static void innobase_kill_query(handlerton*, THD* thd, enum thd_kill_levels);
12031205
static void innobase_commit_ordered(handlerton *hton, THD* thd, bool all);
12041206

12051207
/*****************************************************************//**
@@ -4891,21 +4893,11 @@ innobase_close_thd(
48914893

48924894
UNIV_INTERN void lock_cancel_waiting_and_release(lock_t* lock);
48934895

4894-
/*****************************************************************//**
4895-
Cancel any pending lock request associated with the current THD. */
4896-
static
4897-
void
4898-
innobase_kill_query(
4899-
/*======================*/
4900-
handlerton* hton, /*!< in: innobase handlerton */
4901-
THD* thd, /*!< in: MySQL thread being killed */
4902-
enum thd_kill_levels level) /*!< in: kill level */
4896+
/** Cancel any pending lock request associated with the current THD.
4897+
@sa THD::awake() @sa ha_kill_query() */
4898+
static void innobase_kill_query(handlerton*, THD* thd, enum thd_kill_levels)
49034899
{
4904-
trx_t* trx;
4905-
49064900
DBUG_ENTER("innobase_kill_query");
4907-
DBUG_ASSERT(hton == innodb_hton_ptr);
4908-
49094901
#ifdef WITH_WSREP
49104902
wsrep_thd_LOCK(thd);
49114903
if (wsrep_thd_get_conflict_state(thd) != NO_CONFLICT) {
@@ -4920,51 +4912,11 @@ innobase_kill_query(
49204912
}
49214913
wsrep_thd_UNLOCK(thd);
49224914
#endif /* WITH_WSREP */
4923-
trx = thd_to_trx(thd);
4924-
4925-
if (trx && trx->lock.wait_lock) {
4926-
/* In wsrep BF we have already took lock_sys and trx
4927-
mutex either on wsrep_abort_transaction() or
4928-
before wsrep_kill_victim(). In replication we
4929-
could own lock_sys mutex taken in
4930-
lock_deadlock_check_and_resolve(). */
4931-
4932-
WSREP_DEBUG("Killing victim trx %p BF %d trx BF %d trx_id " TRX_ID_FMT " ABORT %d thd %p"
4933-
" current_thd %p BF %d wait_lock_modes: %s\n",
4934-
trx, wsrep_thd_is_BF(trx->mysql_thd, FALSE),
4935-
wsrep_thd_is_BF(thd, FALSE),
4936-
trx->id, trx->abort_type,
4937-
trx->mysql_thd,
4938-
current_thd,
4939-
wsrep_thd_is_BF(current_thd, FALSE),
4940-
lock_get_info(trx->lock.wait_lock).c_str());
49414915

4942-
if (!wsrep_thd_is_BF(trx->mysql_thd, FALSE)
4943-
&& trx->abort_type == TRX_SERVER_ABORT) {
4944-
ut_ad(!lock_mutex_own());
4945-
lock_mutex_enter();
4946-
}
4947-
4948-
if (trx->abort_type != TRX_WSREP_ABORT) {
4949-
trx_mutex_enter(trx);
4950-
}
4951-
4952-
ut_ad(lock_mutex_own());
4953-
ut_ad(trx_mutex_own(trx));
4954-
4955-
/* Cancel a pending lock request. */
4956-
if (trx->lock.wait_lock) {
4957-
lock_cancel_waiting_and_release(trx->lock.wait_lock);
4958-
}
4959-
4960-
if (trx->abort_type != TRX_WSREP_ABORT) {
4961-
trx_mutex_exit(trx);
4962-
}
4963-
4964-
if (!wsrep_thd_is_BF(trx->mysql_thd, FALSE) &&
4965-
trx->abort_type == TRX_SERVER_ABORT) {
4966-
lock_mutex_exit();
4967-
}
4916+
if (trx_t* trx = thd_to_trx(thd)) {
4917+
ut_ad(trx->mysql_thd == thd);
4918+
/* Cancel a pending lock request if there are any */
4919+
lock_trx_handle_wait(trx);
49684920
}
49694921

49704922
DBUG_VOID_RETURN;
@@ -18759,7 +18711,7 @@ wsrep_innobase_kill_one_trx(
1875918711
thd_get_thread_id(thd)));
1876018712
WSREP_DEBUG("kill query for: %ld",
1876118713
thd_get_thread_id(thd));
18762-
/* Note that innobase_kill_connection will take lock_mutex
18714+
/* Note that innobase_kill_query will take lock_mutex
1876318715
and trx_mutex */
1876418716
wsrep_thd_UNLOCK(thd);
1876518717
wsrep_thd_awake(thd, signal);

storage/xtradb/handler/ha_innodb.cc

Lines changed: 13 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,19 +1423,12 @@ innobase_close_connection(
14231423
THD* thd); /*!< in: MySQL thread handle for
14241424
which to close the connection */
14251425

1426+
/** Cancel any pending lock request associated with the current THD.
1427+
@sa THD::awake() @sa ha_kill_query() */
1428+
static void innobase_kill_query(handlerton*, THD* thd, enum thd_kill_levels);
14261429
static void innobase_commit_ordered(handlerton *hton, THD* thd, bool all);
14271430
static void innobase_checkpoint_request(handlerton *hton, void *cookie);
14281431

1429-
/*****************************************************************//**
1430-
Cancel any pending lock request associated with the current THD. */
1431-
static
1432-
void
1433-
innobase_kill_connection(
1434-
/*======================*/
1435-
handlerton* hton, /*!< in: innobase handlerton */
1436-
THD* thd, /*!< in: handle to the MySQL thread being killed */
1437-
thd_kill_levels);
1438-
14391432
/*****************************************************************//**
14401433
Commits a transaction in an InnoDB database or marks an SQL statement
14411434
ended.
@@ -3886,7 +3879,7 @@ innobase_init(
38863879
innobase_hton->release_temporary_latches =
38873880
innobase_release_temporary_latches;
38883881

3889-
innobase_hton->kill_query = innobase_kill_connection;
3882+
innobase_hton->kill_query = innobase_kill_query;
38903883

38913884
if (srv_file_per_table)
38923885
innobase_hton->tablefile_extensions = ha_innobase_exts;
@@ -5496,20 +5489,11 @@ ha_innobase::get_row_type() const
54965489
return(ROW_TYPE_NOT_USED);
54975490
}
54985491

5499-
/*****************************************************************//**
5500-
Cancel any pending lock request associated with the current THD. */
5501-
static
5502-
void
5503-
innobase_kill_connection(
5504-
/*======================*/
5505-
handlerton* hton, /*!< in: innobase handlerton */
5506-
THD* thd, /*!< in: handle to the MySQL thread being killed */
5507-
thd_kill_levels)
5492+
/** Cancel any pending lock request associated with the current THD.
5493+
@sa THD::awake() @sa ha_kill_query() */
5494+
static void innobase_kill_query(handlerton*, THD* thd, enum thd_kill_levels)
55085495
{
5509-
trx_t* trx;
5510-
5511-
DBUG_ENTER("innobase_kill_connection");
5512-
DBUG_ASSERT(hton == innodb_hton_ptr);
5496+
DBUG_ENTER("innobase_kill_query");
55135497

55145498
#ifdef WITH_WSREP
55155499
wsrep_thd_LOCK(thd);
@@ -5525,50 +5509,10 @@ innobase_kill_connection(
55255509
}
55265510
wsrep_thd_UNLOCK(thd);
55275511
#endif /* WITH_WSREP */
5528-
trx = thd_to_trx(thd);
5529-
5530-
if (trx && trx->lock.wait_lock) {
5531-
/* In wsrep BF we have already took lock_sys and trx
5532-
mutex either on wsrep_abort_transaction() or
5533-
before wsrep_kill_victim(). In replication we
5534-
could own lock_sys mutex taken in
5535-
lock_deadlock_check_and_resolve().*/
5536-
5537-
WSREP_DEBUG("Killing victim trx %p BF %d trx BF %d trx_id " TRX_ID_FMT " ABORT %d thd %p"
5538-
" current_thd %p BF %d wait_lock_modes: %s\n",
5539-
trx, wsrep_thd_is_BF(trx->mysql_thd, FALSE),
5540-
wsrep_thd_is_BF(thd, FALSE),
5541-
trx->id, trx->abort_type,
5542-
trx->mysql_thd,
5543-
current_thd,
5544-
wsrep_thd_is_BF(current_thd, FALSE),
5545-
lock_get_info(trx->lock.wait_lock).c_str());
5546-
5547-
if (!wsrep_thd_is_BF(trx->mysql_thd, FALSE)
5548-
&& trx->abort_type == TRX_SERVER_ABORT) {
5549-
ut_ad(!lock_mutex_own());
5550-
lock_mutex_enter();
5551-
}
5552-
5553-
if (trx->abort_type != TRX_WSREP_ABORT) {
5554-
trx_mutex_enter(trx);
5555-
}
5556-
5557-
ut_ad(lock_mutex_own());
5558-
ut_ad(trx_mutex_own(trx));
5559-
5560-
if (trx->lock.wait_lock) {
5561-
lock_cancel_waiting_and_release(trx->lock.wait_lock);
5562-
}
5563-
5564-
if (trx->abort_type != TRX_WSREP_ABORT) {
5565-
trx_mutex_exit(trx);
5566-
}
5567-
5568-
if (!wsrep_thd_is_BF(trx->mysql_thd, FALSE) &&
5569-
trx->abort_type == TRX_SERVER_ABORT) {
5570-
lock_mutex_exit();
5571-
}
5512+
if (trx_t* trx = thd_to_trx(thd)) {
5513+
ut_ad(trx->mysql_thd == thd);
5514+
/* Cancel a pending lock request if there are any */
5515+
lock_trx_handle_wait(trx);
55725516
}
55735517

55745518
DBUG_VOID_RETURN;
@@ -19802,7 +19746,7 @@ wsrep_innobase_kill_one_trx(
1980219746
thd_get_thread_id(thd)));
1980319747
WSREP_DEBUG("kill query for: %ld",
1980419748
thd_get_thread_id(thd));
19805-
/* Note that innobase_kill_connection will take lock_mutex
19749+
/* Note that innobase_kill_query will take lock_mutex
1980619750
and trx_mutex */
1980719751
wsrep_thd_UNLOCK(thd);
1980819752
wsrep_thd_awake(thd, signal);

0 commit comments

Comments
 (0)