死鎖分析(三)
阿新 • • 發佈:2019-02-13
死鎖產生操作:
事物一先獲取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鎖即不會阻塞