If you use a storage engine that supports transactions, you
probably have faced or heard of deadlock's.
From MySQL Documentation:
“Always be prepared to re-issue a transaction if it fails due to
deadlock. Deadlocks are not dangerous. Just try again.”
At work, we had an important job that sometimes were failing due to dead lock. I wanted to enhance it, so it will do what the documentation says ( Retry the transaction ). In order to do that, I wanted to have a scenario where I was able to reproduce the deadlock and the victim transaction was the one from the job I was fixing.
Create a deadlock is simple, you just need to have 2 sessions
that each one holds a lock that the other is waiting for. For
example:
We have a table that has 4 entries on it (entry 1, entry 2, entry
3, entry 4) and we have 2 …