Commit 4b334320 authored by Marko Mäkelä's avatar Marko Mäkelä

Revert "MDEV-21452: Amend HEAD^"

This reverts commit d32ff4ff.
The code around suspending and resuming threads is rather convoluted.
In particular, que_thr_stop_for_mysql() and
lock_wait_suspend_thread() are separated from each other,
and the trx->mutex is being acquired and released multiple times
while a lock wait is being registered. Also, there are multiple
state fields related to lock waits, both in que_thr_t and trx_t.
parent ca0c5f96
......@@ -642,7 +642,6 @@ inline void lock_reset_lock_and_trx_wait(lock_t* lock)
{
ut_ad(lock_get_wait(lock));
mysql_mutex_assert_owner(&lock_sys.mutex);
mysql_mutex_assert_owner(&lock->trx->mutex);
ut_ad(lock->trx->lock.wait_lock == NULL
|| lock->trx->lock.wait_lock == lock);
lock->trx->lock.wait_lock = NULL;
......
......@@ -2021,11 +2021,12 @@ static void lock_grant_after_reset(lock_t* lock)
}
/** Grant a lock to a waiting lock request and release the waiting transaction. */
static void lock_grant(lock_t *lock)
static void lock_grant(lock_t* lock)
{
mysql_mutex_lock(&lock->trx->mutex);
lock_grant_have_trx_mutex(lock);
mysql_mutex_unlock(&lock->trx->mutex);
lock_reset_lock_and_trx_wait(lock);
mysql_mutex_lock(&lock->trx->mutex);
lock_grant_after_reset(lock);
mysql_mutex_unlock(&lock->trx->mutex);
}
/*************************************************************//**
......@@ -2046,14 +2047,14 @@ lock_rec_cancel(
/* Reset the bit (there can be only one set bit) in the lock bitmap */
lock_rec_reset_nth_bit(lock, lock_rec_find_set_bit(lock));
mysql_mutex_lock(&lock->trx->mutex);
/* Reset the wait flag and the back pointer to lock in trx */
lock_reset_lock_and_trx_wait(lock);
/* The following function releases the trx from lock wait */
mysql_mutex_lock(&lock->trx->mutex);
thr = que_thr_end_lock_wait(lock->trx);
if (thr != NULL) {
......@@ -2402,9 +2403,7 @@ lock_rec_move_low(
lock_rec_reset_nth_bit(lock, donator_heap_no);
if (type_mode & LOCK_WAIT) {
mysql_mutex_lock(&lock->trx->mutex);
lock_reset_lock_and_trx_wait(lock);
mysql_mutex_unlock(&lock->trx->mutex);
}
/* Note that we FIRST reset the bit, and then set the lock:
......@@ -2521,9 +2520,8 @@ lock_move_reorganize_page(
lock_rec_bitmap_reset(lock);
if (lock_get_wait(lock)) {
mysql_mutex_lock(&lock->trx->mutex);
lock_reset_lock_and_trx_wait(lock);
mysql_mutex_unlock(&lock->trx->mutex);
}
lock = lock_rec_get_next_on_page(lock);
......@@ -2699,9 +2697,7 @@ lock_move_rec_list_end(
ut_ad(!page_rec_is_metadata(orec));
if (type_mode & LOCK_WAIT) {
mysql_mutex_lock(&lock->trx->mutex);
lock_reset_lock_and_trx_wait(lock);
mysql_mutex_unlock(&lock->trx->mutex);
}
lock_rec_add_to_queue(
......@@ -2799,9 +2795,7 @@ lock_move_rec_list_start(
ut_ad(!page_rec_is_metadata(prev));
if (type_mode & LOCK_WAIT) {
mysql_mutex_lock(&lock->trx->mutex);
lock_reset_lock_and_trx_wait(lock);
mysql_mutex_unlock(&lock->trx->mutex);
}
lock_rec_add_to_queue(
......@@ -2897,9 +2891,7 @@ lock_rtr_move_rec_list(
if (rec1_heap_no < lock->un_member.rec_lock.n_bits
&& lock_rec_reset_nth_bit(lock, rec1_heap_no)) {
if (type_mode & LOCK_WAIT) {
mysql_mutex_lock(&lock->trx->mutex);
lock_reset_lock_and_trx_wait(lock);
mysql_mutex_unlock(&lock->trx->mutex);
}
lock_rec_add_to_queue(
......
......@@ -326,11 +326,11 @@ lock_wait_suspend_thread(
thd_wait_begin(trx->mysql_thd, THD_WAIT_TABLE_LOCK);
}
mysql_mutex_lock(&trx->mutex);
mysql_mutex_lock(&lock_sys.mutex);
while (trx->lock.wait_lock) {
mysql_cond_wait(&slot->cond, &trx->mutex);
mysql_cond_wait(&slot->cond, &lock_sys.mutex);
}
mysql_mutex_unlock(&trx->mutex);
mysql_mutex_unlock(&lock_sys.mutex);
thd_wait_end(trx->mysql_thd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment