MySQL5.6 + xtrabackup 死锁,Waiting for Commit Lock

发布时间:2020-08-07 10:22:32 作者:G8bao7
来源:ITPUB博客 阅读:267

http://www.ttlsa.com/mysql/mysql5-6-waiting-for-commit-lock/
http://bugs.mysql.com/bug.php?id=70307

MySQL5.6 + xtrabackup 死锁,Waiting for Commit Lock

使用MySQL5.6和Xtrabackup的小心一个bug,http://bugs.mysql.com/bug.php?id=70307,这个bug在5.6.23中已经修复。

Xtrabackup备份的时候执行flushs tables with read lock和show slave status会有可能和SQL Thread形成死锁,导致SQL Thread一直被卡主,STOP也没有用,Kill我们测试会丢失数据,只有Restart Server才行。
原因是SQL Thread的DML操作完成之后,持有rli->data_lock锁,commit的时候等待MDL_COMMIT,而flush tables with read lock之后执行的show slave status会等待rli->data_lock;修复方法是rli->data_lock锁周期只在DML操作期间持有。

重现步骤:

一、创建表
CREATE TABLE test (
  id int(10) NOT NULL AUTO_INCREMENT,
  age int(11) DEFAULT '0',
  PRIMARY KEY (id),
  KEY idx_age (age)

) ENGINE=InnoDB

二、master上执行update test set value=sleep(20)+53 where id=1;(增加sleep(20)是为了模拟方便,所以需要是statement的binlog format,row格式不行)
三、等同步到slave,并且正在执行时;执行flush tables with read lock;show slave status;就会阻塞住。

官方详细的解释和说明:

Bug#19843808: DEADLOCK ON FLUSH TABLES WITH READ LOCK + SHOW SLAVE STATUS Problem: If a client thread on an slave does FLUSH TABLES WITH READ LOCK; then master does some updates, SHOW SLAVE STATUS in the same client will be blocked. Analysis: Execute FLUSH TABLES WITH READ LOCK on slave and at the same time execute a DML on the master. Then the DML should be made to stop at a state "Waiting for commit lock". This state means that sql thread is holding rli->data_lock and waiting for MDL_COMMIT lock. Now in the same client session where FLUSH TABLES WITH READ LOCK was executed issue SHOW SLAVE STATUS command. This command will be blocked waiting for rli->data_lock causing a dead lock. Once this happens it will not be possible to release the global read lock as "UNLOCK TABLES" command has to be issued in the same client where global read lock was acquired. This causes the dead lock. Fix: Existing code holds the rli->data_lock for the whole duration of commit operation. Instead of holding the lock for entire commit duration the code has been restructured in such a way that the lock is held only during the period when rli object is being updated.
推荐阅读:
  1. 使用JavaScript项目编写一个自动跳转文本功能
  2. angularjs项目中实现页面跳转的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

commit lock 死锁

上一篇:电信运营商在三网融合中的“舍”与“得”

下一篇:3个超实用的资源搜索网站,有了它们,再也没有你找不到的资源!

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》