Lecture 3.10 - Deadlock and Multiple Granularity
Lecture 3.10 - Deadlock and Multiple Granularity
• Neither T3 nor T4 can make progress — executing lock-S(B) causes T4 to wait for T3 to release
its lock on B, while executing lock-X(A) causes T3 to wait for T4 to release its lock on A.
• Such a situation is called a deadlock.
• To handle a deadlock one of T3 or T4 must be rolled back
and its locks released.
Deadlocks (Cont.)
Deadlock
Deadlock
Detection and
Deadlock Recovery
Avoidance Deadlock
Prevention
Deadlock Avoidance
https://www.quora.com/What-is-wait-die-and-wound-wait-in-DBMS
Deadlock Avoidance
• To decide whether the transaction has to wait or abort
or rollback.
• Wait-Die:
• If requesting transaction is older than the transaction that
holds a lock on requested data item, then the transaction is
allowed to wait until the transaction is completed and release
locks.
• Otherwise requesting transaction is aborted and rollback and
rescheduled.
• Wound-Wait: Opposite of Wait-Die
Deadlock Avoidance: Wound- Wait
• If requesting transaction is older than the transaction
that holds a lock on requested data item, then the
transaction is allowed to wait until the transaction is
completed and release locks.
• Otherwise requesting transaction is aborted and
rollback and rescheduled
Deadlock Handling
• System is deadlocked if there is a set of transactions such that every
transaction in the set is waiting for another transaction in the set.
• Deadlock prevention protocols ensure that the system will never enter
into a deadlock state. Some prevention strategies :
• Require that each transaction locks all its data items before it begins execution
(predeclaration).
• Impose partial ordering of all data items and require that a transaction can lock
data items only in the order specified by the partial order.
Deadlock prevention (Cont.)
• Timeout-Based Schemes:
• a transaction waits for a lock only for a specified amount of time. If the lock has not been
granted within that time, the transaction is rolled back and restarted,
• Thus, deadlocks are not possible
• simple to implement; but starvation is possible. Also difficult to determine good value of
the timeout interval.
Deadlock Detection
• Deadlocks can be described as a wait-for graph, which consists of a pair G =
(V,E),
• V is a set of vertices (all the transactions in the system)
• E is a set of edges; each element is an ordered pair Ti Tj.
• If Ti Tj is in E, then there is a directed edge from Ti to Tj, implying that Ti is
waiting for Tj to release a data item.
• When Ti requests a data item currently being held by Tj, then the edge Ti Tj is
inserted in the wait-for graph. This edge is removed only when Tj is no longer
holding a data item needed by Ti.
• The system is in a deadlock state if and only if the wait-for graph has a cycle.
Must invoke a deadlock-detection algorithm periodically to look for cycles.
Deadlock Detection (Cont.)
For queries
Email: [email protected]