MySQL JDBC:InnoDB死锁后是否有自动重试的选项?

发布于 2024-11-28 16:10:51 字数 946 浏览 0 评论 0原文

解决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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2024-12-05 16:10:51

您可以重复该语句,但在完美的世界中,您应该回滚事务并重新开始。在那个世界里你的交易会很短:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文