MySQL JDBC:InnoDB死锁后是否有自动重试的选项?
我解决MySQL错误“尝试获取锁时发现死锁;尝试重新启动交易”
我发现可以安全地重新尝试交易
死锁并不危险。再试一次。
http://dev.mysql.com/doc/refman/ 5.0/en/innodb-deadlocks.html
有一个“super insert..select”语句在选择其他两个表的连接组合并在瓶颈表上使用子语句条件后插入到瓶颈表中作为还有几张小桌子。
瓶颈是“等待锁”,毫无疑问是在等待写锁。 InnoDB 似乎是完美的选择。 (对于写入量大的表)现在对这一声明的犹豫都消失了。
但现在问题出现了:每执行 100 次该语句,大约有 1 到 2 次会因为死锁而失败。我相信死锁只发生在“超级插入..选择”的实例之间。我将安装该语句的自动重试,但我想知道
问题:MySQL JDBC 是否有一个选项可以在收到异常后打开语句的自动重试,还是我必须编写自己的代码为此?
com.mysql.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
在这种情况下,我没有启动事务或停止事务命令。只是那一个“超级插入..选择”语句
I am Working around MySQL error “Deadlock found when trying to get lock; try restarting transaction”
I found out that the transaction can be safely reattempted
Deadlocks are not dangerous. Just try again.
http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html
There was a single "super insert..select" statement that inserted into the bottleneck table after selecting a joined combo of two other tables and using sub-statements conditions on the bottleneck table as well as a few tiny tables.
The bottle neck was "waiting for lock", it was waiting for write lock no doubt. InnoDB seemed the perfect fit. (for write-heavy table) And the hesitations on this one statement are now all gone.
But now the problem arises: For every 100 executions of the statement, about 1 or 2 of them will fail because of the deadlock. I believe the deadlock only occurs between instances of the "super insert..select". I will install an auto retry of that statement, but I wondered
Question: Does MySQL JDBC have an option to turn on auto-retry of statements after receiving the exception, or do I have to write my own code for that?
com.mysql.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
In this case, I do not have start transaction or stop transaction commands. Just that one "super insert..select" statement
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以重复该语句,但在完美的世界中,您应该回滚事务并重新开始。在那个世界里你的交易会很短:)
You can repeat the statement but in a perfect world you should rollback your transaction and start it again. And your transactions would be short in that world :)