Deadlock vs Lockwait Timeout on MySQL [closed]

左心房为你撑大大i 提交于 2019-12-10 06:40:54

问题


Can anyone explain me on details the difference of Deadlock and Lockwait errors found on MySQL 5.1. Is it just the same? When does the deadlock error occur and when does the lockwait timeout occur?


回答1:


A deadlock occurs where a circular dependency exists amongst the locks that transactions must acquire in order to proceed: for example, imagine that transaction 1 holds lock A but needs to acquire lock B to proceed; and transaction 2 holds lock B but needs to acquire lock A to proceed—the transactions are immediately deadlocked (no timeout required) and neither can proceed until one releases its locks. Thus the only solution is for one transaction to be rolled back (one's application code should detect this eventuality and handle accordingly, usually by attempting the transaction again).

A wait timeout occurs when the configured timeout period (e.g. innodb_lock_wait_timeout in the case of InnoDB locks) elapses whilst a transaction awaits a lock, perhaps because a slow query is holding the lock and has not finished executing. It's possible (even, likely) that the lock would have become available and been acquired if the transaction had waited longer, but the timeout exists to avoid applications waiting on the database indefinitely.




回答2:


Deadlock is two threads infinitely waiting on the same thing. Lock wait timeout means one thread timed out while waiting to get a lock, thus preventing a deadlock.



来源:https://stackoverflow.com/questions/16563843/deadlock-vs-lockwait-timeout-on-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!