Docsity

DBMS Concurrency Control: Locking and Deadlocks, Study Guides, Projects, Research of Computer science

Toggle sidebar
bg1
DBMS Concurrency Control
In a multi-user database environment, concurrency control is essential to ensure data
integrity and consistency. This guide explores how DBMS manages simultaneous
transactions to prevent data anomalies.
1. Locking Mechanisms
A lock is a synchronization mechanism used to limit access to a data item when
multiple transactions are active.
Types of Locks
Shared (S) Lock: Also known as a "Read Lock." Multiple transactions can hold a
shared lock on the same item. It allows reading but prevents updates.
Exclusive (X) Lock: Also known as a "Write Lock." Only one transaction can hold an
exclusive lock. No other transaction can read or write until it is released.
Two-Phase Locking (2PL) Protocol
To ensure Serializability, DBMS often follows the 2PL protocol:
Growing Phase: Transaction acquires locks but cannot release any.
Shrinking Phase: Transaction releases locks but cannot acquire new ones.
2. Deadlocks: The "Deadly Embrace"
A Deadlock occurs when two or more transactions are stuck in a circular wait, each
holding a resource the other needs.
Wait-For Graph (WFG) Visualization
Locking Mechanisms & Deadlock Resolution Strategies
•
•
1.
2.
Page 1 of 3
pf3

Partial preview of the text

Download DBMS Concurrency Control: Locking and Deadlocks and more Study Guides, Projects, Research Computer science in PDF only on Docsity!

DBMS Concurrency Control

In a multi-user database environment, concurrency control is essential to ensure data integrity and consistency. This guide explores how DBMS manages simultaneous transactions to prevent data anomalies.

1. Locking Mechanisms

A lock is a synchronization mechanism used to limit access to a data item when multiple transactions are active.

Types of Locks

Shared (S) Lock: Also known as a "Read Lock." Multiple transactions can hold a shared lock on the same item. It allows reading but prevents updates. Exclusive (X) Lock: Also known as a "Write Lock." Only one transaction can hold an exclusive lock. No other transaction can read or write until it is released.

Two-Phase Locking (2PL) Protocol

To ensure Serializability , DBMS often follows the 2PL protocol:

Growing Phase: Transaction acquires locks but cannot release any. Shrinking Phase: Transaction releases locks but cannot acquire new ones.

2. Deadlocks: The "Deadly Embrace"

A Deadlock occurs when two or more transactions are stuck in a circular wait, each holding a resource the other needs.

Wait-For Graph (WFG) Visualization

Locking Mechanisms & Deadlock Resolution Strategies

A cycle in the Wait-For Graph (WFG) indicates a Deadlock state.

3. Deadlock Handling Strategies

Strategy Mechanism Pros / Cons

Prevention Wait-Die or Wound-Wait using timestamps.

Prevents deadlocks entirely but can lead to unnecessary rollbacks.

Avoidance Dynamic analysis of resource allocation (Banker's Algorithm).

Theoretically sound; overhead is too high for modern high-speed DBMS.

Detection Periodic WFG analysis to find cycles.

Allows high concurrency; requires a "Victim" rollback if deadlock is found.

Deadlock Prevention via Timestamps:

Wait-Die: If TS(T_i) < TS(T_j) , T_i waits; else T_i dies. Wound-Wait: If TS(T_i) < TS(T_j) , T_i wounds T_j ; else T_i waits.

4. Academic References

Silberschatz, A., Korth, H. F., & Sudarshan, S. Database System Concepts. McGraw- Hill. Elmasri, R., & Navathe, S. B. Fundamentals of Database Systems. Pearson.

T1 T

Waits for Item Y

Waits for Item X