尽管没有其他交易持有锁,但仍未获得锁定

时间:2017-10-31 18:35:45

标签: transactions mariadb

在下面的innodb锁定日志的片段中,我有3个事务都在等待TABLE_C上的锁定才能插入行。有些事情阻止他们中的任何一个获得锁定,因此所有查询都会超时并且事务将被回滚。

Oct 31 17:23:40 QA mysqld: LIST OF TRANSACTIONS FOR EACH SESSION:
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233954056, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3441099, OS thread handle 0x7efa609fcb00, query id 40620122 engineer-desktop <redacted ip> DBA cleaning up
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 0, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3441098, OS thread handle 0x7efd5427cb00, query id 40620123 engineer-desktop <redacted ip> DBA cleaning up
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233958337, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428078, OS thread handle 0x7efd54232b00, query id 40647553 localhost 127.0.0.1 DBUSER cleaning up
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233953710, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428079, OS thread handle 0x7efd508ceb00, query id 40618305 localhost 127.0.0.1 DBUSER cleaning up
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233955212, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428058, OS thread handle 0x7efc18e46b00, query id 40625733 localhost 127.0.0.1 DBUSER cleaning up
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233942817, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428059, OS thread handle 0x7efd509acb00, query id 40321943 localhost 127.0.0.1 DBUSER cleaning up
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233955200, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428056, OS thread handle 0x7efc18d1eb00, query id 40625656 localhost 127.0.0.1 DBUSER cleaning up
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233954068, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428060, OS thread handle 0x7efd3ddf7b00, query id 40620311 localhost 127.0.0.1 DBUSER cleaning up
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233958779, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428055, OS thread handle 0x7efd3dc85b00, query id 40650598 localhost 127.0.0.1 DBUSER cleaning up
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233919171, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428077, OS thread handle 0x7efd543a4b00, query id 40154345 localhost 127.0.0.1 DBUSER cleaning up
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 228166659, not started
Oct 31 17:23:40 QA mysqld: MySQL thread id 3, OS thread handle 0x7efd9a435b00, query id 0 Waiting for background binlog tasks
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233958942, ACTIVE (PREPARED) 0 sec flushing log
Oct 31 17:23:40 QA mysqld: 3 lock struct(s), heap size 1184, 2 row lock(s), undo log entries 1
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428057, OS thread handle 0x7efd3ddadb00, query id 40651751 localhost 127.0.0.1 DBUSER init
Oct 31 17:23:40 QA mysqld: COMMIT
Oct 31 17:23:40 QA mysqld: Trx #rec lock waits 6222 #table lock waits 0
Oct 31 17:23:40 QA mysqld: Trx total rec lock wait time 110 SEC
Oct 31 17:23:40 QA mysqld: Trx total table lock wait time 0 SEC
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_A" trx id 233958942 lock mode IX lock hold time 0 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 81087 page no 4 n bits 88 index "TABLE_A_INDEX" of table "db"."TABLE_A" trx table locks 1 total table locks 1  trx id 233958942 lock_mode X locks rec but not gap lock hol    d time 0 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 81087 page no 3 n bits 88 index "PRIMARY" of table "db"."TABLE_A" trx table locks 1 total table locks 1  trx id 233958942 lock_mode X locks rec but not gap lock hold time 0 wait time before grant 0
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233955000, ACTIVE 40 sec
Oct 31 17:23:40 QA mysqld: 441 lock struct(s), heap size 63016, 983 row lock(s), undo log entries 1982
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428054, OS thread handle 0x7efd5419eb00, query id 40651737 localhost 127.0.0.1 DBUSER cleaning up
Oct 31 17:23:40 QA mysqld: Trx #rec lock waits 1514 #table lock waits 0
Oct 31 17:23:40 QA mysqld: Trx total rec lock wait time 24 SEC
Oct 31 17:23:40 QA mysqld: Trx total table lock wait time 0 SEC
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_B" trx id 233955000 lock mode IX lock hold time 40 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_C" trx id 233955000 lock mode IX lock hold time 39 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_D" trx id 233955000 lock mode IS lock hold time 39 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80862 page no 3 n bits 80 index "PRIMARY" of table "db"."TABLE_D" trx table locks 13 total table locks 4  trx id 233955000 lock mode S locks rec but not gap lock hold time  39 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_E" trx id 233955000 lock mode IS lock hold time 39 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 81053 page no 17 n bits 80 index "PRIMARY" of table "db"."TABLE_E" trx table locks 13 total table locks 4  trx id 233955000 lock mode S locks rec but not gap lock hold time  39 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_F" trx id 233955000 lock mode IX lock hold time 39 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_G" trx id 233955000 lock mode IS lock hold time 39 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80850 page no 3 n bits 96 index "PRIMARY" of table "db"."TABLE_G" trx table locks 13 total table locks 4  trx id 233955000 lock mode S locks rec but not gap lock hold time  39 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_H" trx id 233955000 lock mode IS lock hold time 39 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TOO MANY LOCKS PRINTED FOR THIS TRX: SUPPRESSING FURTHER PRINTS
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233954711, ACTIVE 41 sec inserting
Oct 31 17:23:40 QA mysqld: mysql tables in use 1, locked 1
Oct 31 17:23:40 QA mysqld: LOCK WAIT 19 lock struct(s), heap size 2936, 9 row lock(s), undo log entries 4
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428052, OS thread handle 0x7efd54076b00, query id 40623905 localhost 127.0.0.1 DBUSER
Oct 31 17:23:40 QA mysqld: insert into TABLE_C (<redacted columns>) values (<redacted values>
Oct 31 17:23:40 QA mysqld: Trx #rec lock waits 19 #table lock waits 0
Oct 31 17:23:40 QA mysqld: Trx total rec lock wait time 2 SEC
Oct 31 17:23:40 QA mysqld: Trx total table lock wait time 0 SEC
Oct 31 17:23:40 QA mysqld: ------- TRX HAS BEEN WAITING 41 SEC FOR THIS LOCK TO BE GRANTED:
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80947 page no 9930 n bits 72 index "PRIMARY" of table "db"."TABLE_C" trx table locks 10 total table locks 4  trx id 233954711 lock_mode X insert intention waiting lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: ------------------
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_B" trx id 233954711 lock mode IX lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_C" trx id 233954711 lock mode IX lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_D" trx id 233954711 lock mode IS lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80862 page no 3 n bits 80 index "PRIMARY" of table "db"."TABLE_D" trx table locks 10 total table locks 4  trx id 233954711 lock mode S locks rec but not gap lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_E" trx id 233954711 lock mode IS lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 81053 page no 17 n bits 80 index "PRIMARY" of table "db"."TABLE_E" trx table locks 10 total table locks 4  trx id 233954711 lock mode S locks rec but not gap lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_F" trx id 233954711 lock mode IX lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_G" trx id 233954711 lock mode IS lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80850 page no 3 n bits 96 index "PRIMARY" of table "db"."TABLE_G" trx table locks 10 total table locks 4  trx id 233954711 lock mode S locks rec but not gap lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_H" trx id 233954711 lock mode IS lock hold time 41 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TOO MANY LOCKS PRINTED FOR THIS TRX: SUPPRESSING FURTHER PRINTS
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233954594, ACTIVE 42 sec inserting
Oct 31 17:23:40 QA mysqld: mysql tables in use 1, locked 1
Oct 31 17:23:40 QA mysqld: LOCK WAIT 19 lock struct(s), heap size 2936, 9 row lock(s), undo log entries 4
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428053, OS thread handle 0x7efc18dfcb00, query id 40623090 localhost 127.0.0.1 DBUSER
Oct 31 17:23:40 QA mysqld: insert into TABLE_C (<redacted columns>) values (<redacted values>
Oct 31 17:23:40 QA mysqld: Trx #rec lock waits 5 #table lock waits 0
Oct 31 17:23:40 QA mysqld: Trx total rec lock wait time 15 SEC
Oct 31 17:23:40 QA mysqld: Trx total table lock wait time 0 SEC
Oct 31 17:23:40 QA mysqld: ------- TRX HAS BEEN WAITING 42 SEC FOR THIS LOCK TO BE GRANTED:
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80947 page no 9926 n bits 72 index "PRIMARY" of table "db"."TABLE_C" trx table locks 10 total table locks 4  trx id 233954594 lock_mode X insert intention waiting lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: ------------------
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_B" trx id 233954594 lock mode IX lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_C" trx id 233954594 lock mode IX lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_D" trx id 233954594 lock mode IS lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80862 page no 3 n bits 80 index "PRIMARY" of table "db"."TABLE_D" trx table locks 10 total table locks 4  trx id 233954594 lock mode S locks rec but not gap lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_E" trx id 233954594 lock mode IS lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 81053 page no 17 n bits 80 index "PRIMARY" of table "db"."TABLE_E" trx table locks 10 total table locks 4  trx id 233954594 lock mode S locks rec but not gap lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_F" trx id 233954594 lock mode IX lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_G" trx id 233954594 lock mode IS lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80850 page no 3 n bits 96 index "PRIMARY" of table "db"."TABLE_G" trx table locks 10 total table locks 4  trx id 233954594 lock mode S locks rec but not gap lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_H" trx id 233954594 lock mode IS lock hold time 42 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TOO MANY LOCKS PRINTED FOR THIS TRX: SUPPRESSING FURTHER PRINTS
Oct 31 17:23:40 QA mysqld: ---TRANSACTION 233954505, ACTIVE 43 sec inserting
Oct 31 17:23:40 QA mysqld: mysql tables in use 1, locked 1
Oct 31 17:23:40 QA mysqld: LOCK WAIT 54 lock struct(s), heap size 6544, 79 row lock(s), undo log entries 127
Oct 31 17:23:40 QA mysqld: MySQL thread id 3428049, OS thread handle 0x7efcab51eb00, query id 40625375 localhost 127.0.0.1 DBUSER
Oct 31 17:23:40 QA mysqld: insert into TABLE_C (<redacted columns>) values (<redacted values>
Oct 31 17:23:40 QA mysqld: Trx #rec lock waits 1 #table lock waits 0
Oct 31 17:23:40 QA mysqld: Trx total rec lock wait time 0 SEC
Oct 31 17:23:40 QA mysqld: Trx total table lock wait time 0 SEC
Oct 31 17:23:40 QA mysqld: ------- TRX HAS BEEN WAITING 39 SEC FOR THIS LOCK TO BE GRANTED:
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80947 page no 9936 n bits 72 index "PRIMARY" of table "db"."TABLE_C" trx table locks 13 total table locks 4  trx id 233954505 lock_mode X insert intention waiting lock hold time 39 wait time before grant 0
Oct 31 17:23:40 QA mysqld: ------------------
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_B" trx id 233954505 lock mode IX lock hold time 43 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_C" trx id 233954505 lock mode IX lock hold time 43 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_D" trx id 233954505 lock mode IS lock hold time 43 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80862 page no 3 n bits 80 index "PRIMARY" of table "db"."TABLE_D" trx table locks 13 total table locks 4  trx id 233954505 lock mode S locks rec but not gap lock hold time 43 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_E" trx id 233954505 lock mode IS lock hold time 43 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 81053 page no 17 n bits 80 index "PRIMARY" of table "db"."TABLE_E" trx table locks 13 total table locks 4  trx id 233954505 lock mode S locks rec but not gap lock hold time 43 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_F" trx id 233954505 lock mode IX lock hold time 43 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_G" trx id 233954505 lock mode IS lock hold time 43 wait time before grant 0
Oct 31 17:23:40 QA mysqld: RECORD LOCKS space id 80850 page no 3 n bits 96 index "PRIMARY" of table "db"."TABLE_G" trx table locks 13 total table locks 4  trx id 233954505 lock mode S locks rec but not gap lock hold time 43 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TABLE LOCK table "db"."TABLE_H" trx id 233954505 lock mode IS lock hold time 43 wait time before grant 0
Oct 31 17:23:40 QA mysqld: TOO MANY LOCKS PRINTED FOR THIS TRX: SUPPRESSING FURTHER PRINTS

但是,我看不到任何其他事务持有该表,意图或其他方面的锁定,所以我不知道是什么阻止了任何事务获得锁定。

是否有其他事务可以阻止获取锁定?

1 个答案:

答案 0 :(得分:0)

可能是间隙锁中出现死锁的情况。

TABLE_C有一个唯一键,每个事务都会在TABLE_C中插入多个值。每次插入行时,它都会获取间隙锁定,以确保没有其他事务违反唯一键约束。这可能会导致经典的僵局。

有人知道在innodb锁定日志记录中是否会出现间隙锁?

http://thushw.blogspot.co.uk/2010/11/mysql-deadlocks-with-concurrent-inserts.html