死锁分析(三)

死锁产生操作:

事物一先获取id=3的s锁, 然后事物二准备获取id=3的x锁,事物一再次准备获取x锁

 

死锁日志

LATEST DETECTED DEADLOCK
------------------------
2018-08-21 12:44:19 0x7f7090133700
*** (1) TRANSACTION:
TRANSACTION 2343, ACTIVE 23 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 1136, 1 row lock(s)
MySQL thread id 15, OS thread handle 140121430038272, query id 105 localhost root updating
delete from person where id = 3
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 25 page no 3 n bits 80 index PRIMARY of table `zy-test`.`person` trx id 2343 lock_mode X locks rec but not gap waiting
Record lock, heap no 7 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
 0: len 8; hex 8000000000000003; asc         ;;
 1: len 6; hex 000000000923; asc      #;;
 2: len 7; hex 37000001470110; asc 7   G  ;;
 3: len 3; hex 7a7932; asc zy2;;
 4: len 4; hex 8000000a; asc     ;;

*** (2) TRANSACTION:
TRANSACTION 2344, ACTIVE 58 sec starting index read
mysql tables in use 1, locked 1
4 lock struct(s), heap size 1136, 2 row lock(s)
MySQL thread id 14, OS thread handle 140121430243072, query id 106 localhost root updating
delete from person where id = 3
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 25 page no 3 n bits 80 index PRIMARY of table `zy-test`.`person` trx id 2344 lock mode S locks rec but not gap
Record lock, heap no 7 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
 0: len 8; hex 8000000000000003; asc         ;;
 1: len 6; hex 000000000923; asc      #;;
 2: len 7; hex 37000001470110; asc 7   G  ;;
 3: len 3; hex 7a7932; asc zy2;;
 4: len 4; hex 8000000a; asc     ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 25 page no 3 n bits 80 index PRIMARY of table `zy-test`.`person` trx id 2344 lock_mode X locks rec but not gap waiting
Record lock, heap no 7 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
 0: len 8; hex 8000000000000003; asc         ;;
 1: len 6; hex 000000000923; asc      #;;
 2: len 7; hex 37000001470110; asc 7   G  ;;
 3: len 3; hex 7a7932; asc zy2;;
 4: len 4; hex 8000000a; asc     ;;

*** WE ROLL BACK TRANSACTION (1)
------------
TRANSACTIONS

关于例子中死锁产生原因的官方解释

死锁产生原因:

事务一持有s锁, 事务二准备持有x锁时被阻塞, 事务一准备持有x锁被事务二的准备x锁阻塞???

如果事务一持有x锁,事务二准备持有x锁被阻塞,事务一继续持有x锁即不会阻塞

你可能感兴趣的:(mysql锁分析)