Detection Using Waits-For Graph (cont’d)
So, to find deadlocks
- when a transaction blocks, add an edge to the graph
- periodically check for cycles in the waits-for graph
Don’t test for deadlocks too often. (A cycle won’t disappear until you detect it and break it.)
When a deadlock is detected, select a victim from the cycle and abort it.
Select a victim that hasn’t done much work (e.g., has set the fewest locks).