Explain deadlock detection.
In : BE Subject : Database Management SystemsFirst, a deadlock is a situation where two or more transactions are permanently blocked because each is holding a lock on a resource that the other needs.
Example:
-
Transaction T1 has a lock on Data Item A and requests a lock on Data Item B.
-
Transaction T2 has a lock on Data Item B and requests a lock on Data Item A.
-
T1 is waiting for T2 to release B, and T2 is waiting for T1 to release A. They are stuck in a circular wait forever.
Deadlock Detection
Since preventing deadlocks can be restrictive, many DBMSs allow them to happen but have a mechanism to find and break them. This is deadlock detection.
The system uses a Wait-For Graph to model dependencies between transactions.
The Wait-For Graph
-
Nodes represent active transactions.
-
A directed edge from T1 to T2 (T1 → T2) means Transaction T1 is waiting for a resource (e.g., a lock) that is currently held by Transaction T2.