From e85267bf0403a05f3c82fd5d782e63c11c84a4fe Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Wed, 18 Aug 2021 19:26:01 +0300 Subject: MDEV-26206 gap lock is not set if implicit lock exists Post-push fix for 10.5+. The fix influence MDEV-14479. Before the fix lock_rec_convert_impl_to_expl() did not create explicit lock if caller's transaction owns found implicit lock(see MDEV-14479 for details). After the fix lock_rec_convert_impl_to_expl() can create explicit lock under the above conditions if the requested lock mode is not LOCK_REC_NOT_GAP. And that is why we need to check if the table is X-locked before lock_rec_convert_impl_to_expl() call. --- storage/innobase/lock/lock0lock.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index e46a0a91ac5..d7ec5736826 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -5640,7 +5640,9 @@ lock_sec_rec_read_check_and_lock( if the max trx id for the page >= min trx id for the trx list or a database recovery is running. */ - if (!page_rec_is_supremum(rec) + trx_t *trx = thr_get_trx(thr); + if (!lock_table_has(trx, index->table, LOCK_X) + && !page_rec_is_supremum(rec) && page_get_max_trx_id(block->frame) >= trx_sys.get_min_trx_id() && lock_rec_convert_impl_to_expl(thr_get_trx(thr), block, rec, index, offsets) @@ -5650,7 +5652,6 @@ lock_sec_rec_read_check_and_lock( } #ifdef WITH_WSREP - trx_t *trx= thr_get_trx(thr); /* If transaction scanning an unique secondary key is wsrep high priority thread (brute force) this scanning may involve GAP-locking in the index. As this locking happens also when @@ -5724,8 +5725,10 @@ lock_clust_rec_read_check_and_lock( heap_no = page_rec_get_heap_no(rec); - if (heap_no != PAGE_HEAP_NO_SUPREMUM - && lock_rec_convert_impl_to_expl(thr_get_trx(thr), block, rec, + trx_t *trx = thr_get_trx(thr); + if (!lock_table_has(trx, index->table, LOCK_X) + && heap_no != PAGE_HEAP_NO_SUPREMUM + && lock_rec_convert_impl_to_expl(trx, block, rec, index, offsets) && gap_mode == LOCK_REC_NOT_GAP) { /* We already hold an implicit exclusive lock. */ -- cgit v1.2.1