![]() |
VOOZH | about |
In a Database Management System (DBMS), deadlocks occur when two or more transactions wait indefinitely for each other to release resources. This halts the systemβs progress and affects database consistency. To handle this, various deadlock prevention techniques are used in concurrency control
A timestamp (TS) is a unique identifier assigned to each transaction by the DBMS when it begins. It defines the age of a transaction - older transactions have smaller timestamps and newer transactions have larger timestamps.
Note: Timestamps help ensure that transactions are executed in an order that maintains serializability, meaning the result is the same as if transactions had been executed one after another.
When a transaction requests access to a data item, the DBMS compares the timestamp of the requesting transaction with the timestamp of the last transaction that accessed that data item.
Note: This ensures that transactions execute in a serializable and consistent order.
The Timestamp Ordering (TO) Protocol is a concurrency control technique that inherently prevents deadlocks because transactions are ordered by their timestamps and cannot wait indefinitely. Two major timestamp-based deadlock prevention schemes are:
Rule: If TS(Ti) < TS(Tj) -> Ti is older than Tj -> Ti waits for Tj. Else (Ti is younger) -> Ti is aborted and restarted later with the same timestamp.
Example:
| Transaction | Action |
|---|---|
| T1 (TS=10) | Requests item held by T2 (TS=20) |
| T1 is older | -> Allowed to wait |
| T2 (TS=20) | Requests item held by T1 (TS=10) |
| T2 is younger | -> Aborted and restarted |
Result: Deadlocks are avoided because transactions wait in one direction (older -> younger), ensuring no cycles.
This is the opposite of the Wait-Die scheme.
Rule: If TS(Ti) < TS(Tj) -> Ti is older than Tj -> Abort Tj (Ti wounds Tj) and restart it later with the same timestamp. Else (Ti is younger) -> Ti waits.
| Transaction | Action |
|---|---|
| T1 (TS=10) | Requests item held by T2 (TS=20) |
| T1 is older | -> T2 is aborted (wounded) |
| T2 (TS=20) | Requests item held by T1 (TS=10) |
| T2 is younger | -> Allowed to wait |
Result: Older transactions never wait, reducing delays and ensuring deadlock-free operation.
| Feature | Wait-Die | Wound-Wait |
|---|---|---|
| Who waits? | Older waits for younger | Younger waits for older |
| Who gets aborted? | Younger transaction | Younger transaction |
| Aggressiveness | Less aggressive | More aggressive |
| Type of aborts | Fewer restarts (older waits) | More restarts (older wounds younger) |
| Starvation | Possible (older keeps waiting) | Less likely (older never waits) |
Key Idea: Both schemes ensure that only younger transactions are aborted, breaking potential cycles and preventing deadlocks.
Drawback: Too many restarts -> increases overhead and reduces system performance.
When a transaction Ti requests a data item X held by Tj:
Advantage: Reduces unnecessary aborts compared to No-Wait. Still guarantees a deadlock-free system.
If the system does not prevent deadlocks in advance, it can detect them using a Wait-for Graph (WFG). Concept:
If the graph contains a cycle, it indicates a deadlock. The DBMS can then break the cycle by aborting one of the transactions involved.
Example: T1 -> T2 -> T3 -> T1 -> Deadlock detected.
Starvation occurs when a transaction waits indefinitely because the system keeps prioritizing other transactions. This often happens in systems with frequent aborts or restarts, such as those using deadlock prevention algorithms.
The most common method to prevent starvation is First-Come, First-Serve (FCFS) scheduling:
Read more about Starvation in DBMS
The Concurrency Control Manager is responsible for:
Note: It uses techniques like - Timestamps, Lock management, Wait-for Graphs, FCFS queueing to manage concurrent transaction execution effectively.
Try this question: GATE | GATE-CS-2017 (Set 1) | Question 46