[MDEV-31017] gap lock while INSERT ... ON DUPLICATE in READ-COMMITTED Created: 2023-04-06  Updated: 2023-05-07

Status: Open
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.6.10
Fix Version/s: 10.6

Type: Bug Priority: Major
Reporter: Andrii Assignee: Vladislav Lesin
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Current documentation https://mariadb.com/kb/en/innodb-lock-modes/#intention-locks :

Gap locks are disabled if ... the isolation level is set to READ COMMITTED.

I am pretty sure all connections below use READ-COMMITTED and no binlogging enabled - still observe several times per day deadlocks because of ` gap before rec insert intention waiting` while inserting rows into a small table:

LATEST DETECTED DEADLOCK
------------------------
2023-04-06 07:59:31 0x7f8d4bed3700
*** (1) TRANSACTION:
TRANSACTION 6942075065, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1128, 4 row lock(s), undo log entries 1
MariaDB thread id 6036630, OS thread handle 140244840953600, query id 1967907196 192.168.xx.xx mirrorcache Update
insert into mojo_pubsub_subscribe (pid, channel) values ('6036637', 'minion.job') on duplicate key update ts=current_timestamp
*** WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 31 page no 4 n bits 648 index subs_idx of table `mirrorcache`.`mojo_pubsub_subscribe` trx id 6942075065 lock_mode X locks gap before rec insert intention waiting
Record lock, heap no 237 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 805c1ce0; asc  \  ;;
 1: len 10; hex 6d696e696f6e2e6a6f62; asc minion.job;;
 2: len 4; hex 886f6a12; asc  oj ;;
 
*** CONFLICTING WITH:
RECORD LOCKS space id 31 page no 4 n bits 648 index subs_idx of table `mirrorcache`.`mojo_pubsub_subscribe` trx id 6942075065 lock_mode X
Record lock, heap no 237 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 805c1ce0; asc  \  ;;
 1: len 10; hex 6d696e696f6e2e6a6f62; asc minion.job;;
 2: len 4; hex 886f6a12; asc  oj ;;
 
Record lock, heap no 313 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 805c1c9d; asc  \  ;;
 1: len 10; hex 6d696e696f6e2e6a6f62; asc minion.job;;
 2: len 4; hex 886f692d; asc  oi-;;
 
Record lock, heap no 591 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 805c1c9d; asc  \  ;;
 1: len 10; hex 6d696e696f6e2e6a6f62; asc minion.job;;
 2: len 4; hex 886f6a40; asc  oj@;;
 
*** (2) TRANSACTION:
TRANSACTION 6942075066, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 1128, 1 row lock(s), undo log entries 1
MariaDB thread id 6036732, OS thread handle 140245429069568, query id 1967907198 192.168.xx.yy mirrorcache Update
insert into mojo_pubsub_subscribe (pid, channel) values ('6036704', 'minion.job') on duplicate key update ts=current_timestamp
*** WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 31 page no 4 n bits 648 index subs_idx of table `mirrorcache`.`mojo_pubsub_subscribe` trx id 6942075066 lock_mode X waiting
Record lock, heap no 237 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 805c1ce0; asc  \  ;;
 1: len 10; hex 6d696e696f6e2e6a6f62; asc minion.job;;
 2: len 4; hex 886f6a12; asc  oj ;;
 
*** CONFLICTING WITH:
RECORD LOCKS space id 31 page no 4 n bits 648 index subs_idx of table `mirrorcache`.`mojo_pubsub_subscribe` trx id 6942075065 lock_mode X
Record lock, heap no 237 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 805c1ce0; asc  \  ;;
 1: len 10; hex 6d696e696f6e2e6a6f62; asc minion.job;;
 2: len 4; hex 886f6a12; asc  oj ;;
 
Record lock, heap no 313 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 805c1c9d; asc  \  ;;
 1: len 10; hex 6d696e696f6e2e6a6f62; asc minion.job;;
 2: len 4; hex 886f692d; asc  oi-;;
 
Record lock, heap no 591 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 805c1c9d; asc  \  ;;
 1: len 10; hex 6d696e696f6e2e6a6f62; asc minion.job;;
 2: len 4; hex 886f6a40; asc  oj@;;
 
*** WE ROLL BACK TRANSACTION (2)

Table structure:
https://github.com/jhthorsen/mojo-mysql/blob/a558cb6e6316b270cf61d0d394a8a4a0b556928b/lib/Mojo/mysql/PubSub.pm#L276

MariaDB [mirrorcache]> show global variables like 'tx_i%';
+---------------+----------------+
| Variable_name | Value          |
+---------------+----------------+
| tx_isolation  | READ-COMMITTED |
+---------------+----------------+
1 row in set (0.001 sec)
 
MariaDB [mirrorcache]> select version();
+-----------------+
| version()       |
+-----------------+
| 10.6.10-MariaDB |
+-----------------+
1 row in set (0.000 sec)


Generated at Thu Feb 08 10:20:39 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.