异常问题

原因分析
- 这个问题发生在开发环境,怀疑是提交事务时终止项目运行,没有提交该事务,造成死锁
- 调试该事务时时间太长,为什么说有这个原因呢,因为通过查找日志显示
The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.

问题排查
# 当前运行的所有事务 select * from information_schema.innodb_trx; # 查看锁的持有和请求情况 MySQL8.0 select * from performance_schema.data_locks; # 查看锁的等待情况 MySQL8.0 select * from performance_schema.data_lock_waits; # 当前线程详情 show full processlist;
- 1.发现事务id176602一直在运行状态

- 锁的持有和请求情况


- kill 掉事务关联的mysql线程ID (trx_mysql_thread_id)
KILL 362
trx_mysql_thread_id = 0 无法Kill 接着排查
确认 trx_mysql_thread_id = 0 为XA(分布式)事务
- 执行回滚操作
#查看XA事务信息 xa recover; #执行报错可能没有权限 GRANT XA_RECOVER_ADMIN ON *.* TO root@'%' ;
得到

回滚XA事务操作
# XA事务回滚命令的格式: xa rollback 'left(data,gtrid_length)','substr(data,gtrid_length+1,bqual_length)', formatID; #示列 SELECT left('55f3cdd8-4f45-49c8-bbca-2738fa5a1514:35',38); SELECT substr('55f3cdd8-4f45-49c8-bbca-2738fa5a1514:35',39,1); xa rollback '55f3cdd8-4f45-49c8-bbca-2738fa5a1514:3', '5',1;