记一次生产环境死锁问题

insert into table (shop_id, homework_status, content_id, `index`, homework_type, creator_id,
prepare_homework_time_point, proceed_time_point, finished_time_point,creator_name, updated_at, created_at) values
(10013,'0',9352,1,'0',412,null,null,null,'test','2021-06-30 15:03:00.914','2021-06-30 15:03:00.914')

LockRequest:
RECORD LOCKS space id 725 page no 18 n bits 80 index idx_content_id of
table `test_table`.`table` trx id 847546440 lock_mode X insert intention waiting

insert into table (shop_id, homework_status,content_id, `index`, homework_type, creator_id,
prepare_homework_time_point, proceed_time_point, finished_time_point,creator_name, updated_at, created_at) values
(10013,'0',9352,1,'0',412,null,null,null,'test','2021-06-30 15:03:00.914','2021-06-30 15:03:00.914')

LockRequest:
RECORD LOCKS space id 725 page no 18 n bits 80 index idx_content_id of
table `test_table`.`table` trx id 847546439 lock_mode X insert intention waiting

LockHold:
RECORD LOCKS space id 725 page no 18 n bits 80 index idx_content_id of
table `test_table`.`table` trx id 847546439 lock_mode X

查看上诉日志可得:

  • 在同一时间事务插入id为847546440 正在等待的插入意向排他锁,而它所持有的间隙锁正被事务插入id为847546439 的持有
  • 事务B持有间隙锁,正在等待插入意向排它锁
  • 所以导致锁互相等待死锁,此时需要根据业务,排除锁竞争条件

你可能感兴趣的:(mysql,mysql)