Database Management System · Unit 8
Concurrency Control
Exam-focused notes for Concurrency Control (Database Management System, BIT202): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.
Concurrency Control in short
Many users use a database at the same time. Concurrency control is the part of the DBMS that lets them work together without damaging the data. This chapter covers locks, two-phase locking, deadlock, and starvation.
What this unit covers
- Concurrent execution in multiuser systems
- Need for concurrency control
- Binary locks
- Shared and exclusive locks
- Two-phase locking protocol
- Deadlock definition and examples
- Starvation in DBMS
Two-phase locking protocol
2082 · 5 marks
What is two phase locking protocol? How can it lead to the deadlock condition? [5]
Show solved answerHide answer
Two Phase Locking (2PL) Protocol
Definition
Two Phase Locking (2PL) is a concurrency control protocol that ensures serializability of transactions by regulating when locks can be acquired and released. It states that:
A transaction must acquire all the locks it needs before releasing any lock.
The protocol divides the execution of a transaction into two distinct phases:
The Two Phases
Phase 1: Growing Phase (Lock Acquisition Phase)
- A transaction may acquire locks (shared or exclusive).
- A transaction may NOT release any lock.
- The number of locks held by the transaction increases (or stays the same).
Phase 2: Shrinking Phase (Lock Release Phase)
- A transaction may release locks.
- A transaction may NOT acquire any new lock.
- The number of locks held decreases until all are released.
The point at which the last lock is acquired is called the Lock Point.
Number
of Locks
| /\
| / \
| / \
| / \
| / \
|___/ \___
|
+--Growing--+--Shrinking--> Time
Types of 2PL
| Type | Description |
|---|---|
| Basic 2PL | Locks released during shrinking phase |
| Strict 2PL | All exclusive locks held until commit/abort |
| Rigorous 2PL | All locks held until commit/abort |
How 2PL Can Lead to Deadlock
Deadlock occurs when two or more transactions are waiting for each other to release locks, forming a circular wait condition.
Example:
Consider two transactions T1 and T2:
| Step | T1 | T2 |
|---|---|---|
| 1 | Lock-X(A) -- success | |
| 2 | Lock-X(B) -- success | |
| 3 | Lock-X(B) -- WAIT (B locked by T2) | |
| 4 | Lock-X(A) -- WAIT (A locked by T1) |
Result:
- T1 holds lock on A and waits for B
- T2 holds lock on B and waits for A
- Neither can proceed -- DEADLOCK
Why 2PL Causes This:
In the growing phase, a transaction acquires locks one at a time (not all at once). This means:
- T1 acquires lock on A, then tries to acquire lock on B
- T2 acquires lock on B, then tries to acquire lock on A
- Since neither can release a lock during the growing phase (2PL rule), a circular dependency forms
This is a direct consequence of the 2PL rule that locks cannot be released until the shrinking phase begins, combined with the fact that locks are acquired incrementally.
Deadlock Handling
Since 2PL can cause deadlocks, the DBMS must handle them using:
- Deadlock Detection -- using a wait-for graph; if a cycle is detected, one transaction is rolled back (victim selection)
- Deadlock Prevention -- using timestamp-based schemes (Wait-Die or Wound-Wait protocols)
Summary
| Feature | Detail |
|---|---|
| Purpose | Ensures serializability |
| Phase 1 | Acquire locks only (Growing) |
| Phase 2 | Release locks only (Shrinking) |
| Deadlock | Possible due to incremental lock acquisition and circular wait |
Shared and exclusive locks
2080 · 5 marks
What is Shared/Exclusive (Read/Write) Locks? How it is different from binary Locks. [5]
Deadlock definition and examples
Need for concurrency control
2079 · 5 marks
What is meant by the concurrent execution of database transactions in a multiuser system? Discuss why concurrency control is needed, and give informal examples. [5]
Starvation in DBMS
2078 · 5 marks
What is starvation in DBMS? Explain with example. [5]
Make Unit 8 stick
Practice BIT202 with flashcards & quizzes