且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么提交不会导致死锁

更新时间:2023-02-03 19:39:39

我怀疑这是一个边缘案例,不值得提高效率.请注意,您必须进行3次会话才能尝试抓住同一行-罕见的情况.而且您做了回滚-也很罕见.因此,发生的僵局是过大的,但不值得解决.因此,必须准备在任何地方处理死锁.

I suspect this is an edge case that is not worth making more efficient. Note that you had to get 3 sessions trying to grab the same row -- a rare happening. And you did a ROLLBACK -- also rare. So the deadlock that occurred is overkill, but not worth fixing. For this reason, one must be prepared to handle deadlocks everywhere.

仅供参考,如果这是Galera群集的3个节点,则COMMIT上将存在代码必须处理的错误.我怀疑如果您多次将此事务(回滚或提交)应用于多个节点,将会发生更多奇怪的事情.

FYI, If this were 3 nodes of a Galera cluster, there would be errors on COMMIT that the code would have to handle. I suspect there are even more combinations of strange things going on if you apply this transaction (with rollback or commit) multiple times to multiple nodes.

现在要问您的问题...可能不会发生死锁,因为其中一个线程获得了排他锁,而另一个线程却被等待"而不是死锁"击中.

Now to your question... Presumably the deadlock did not happen because one of the threads got the exclusive lock and the other was hit with a "wait" instead of a "deadlock".