DMBS_Module5.2 Concurrency Control
DMBS_Module5.2 Concurrency Control
Module 5.2
Concurrency Control,
Lock-based Protocols and Deadlocks,
Database Recovery
Example:
In concurrent execution environment if T1 conflicts with T2
over a data item A, then the existing concurrency control
decides if T1 or T2 should get the A and if the other
transaction is rolled-back or waits.
Y N
Write
N N
one at a time.
Unlocking (Shrinking) Phase:
A transaction unlocks its locked data items one at a time.
Requirement:
For a transaction these two phases must be mutually exclusively,
that is, during locking phase unlocking phase must not start and
during unlocking phase locking phase must not begin.
T1 T2 Result
read_lock (Y); read_lock (X); Initial values: X=20; Y=30
read_item (Y); read_item (X); Result of serial execution
unlock (Y); unlock (X); T1 followed by T2
write_lock (X); Write_lock (Y); X=50, Y=80.
read_item (X); read_item (Y); Result of serial execution
X:=X+Y; Y:=X+Y; T2 followed by T1
write_item (X); write_item (Y); X=70, Y=50
unlock (X); unlock (Y);
T1 T2 Result
read_lock (Y); X=50; Y=50
read_item (Y); Nonserializable because it.
unlock (Y); violated two-phase policy.
read_lock (X);
read_item (X);
unlock (X);
Time write_lock (Y);
read_item (Y);
Y:=X+Y;
write_item (Y);
unlock (Y);
write_lock (X);
read_item (X);
X:=X+Y;
write_item (X);
unlock (X);
T’1 T’2
read_lock (Y); read_lock (X); T1 and T2 follow two-phase
read_item (Y); read_item (X); policy but they are subject to
write_lock (X); Write_lock (Y); deadlock, which must be
unlock (Y); unlock (X); dealt with.
read_item (X); read_item (Y);
X:=X+Y; Y:=X+Y;
write_item (X); write_item (Y);
unlock (X); unlock (Y);
T1 T2
X(A)
W(A)
X(B)
W(B)
X(A)
W(A)
X(B)
W(B)
Wound-wait:
(a) If Ti < Tj (Ti has a higher priority than Tj), then abort Tj.
Otherwise, Ti is allowed to wait.
(b) Higher priority transactions can never wait for lower priority
transactions. Or, higher priority ones wounds (forces
rollback) of lower priority ones.
(c) It is preemptive.
Database Management Systems
Wait-die
A A
Wound-wait
A A
T1 T2 T3 T4
T1 T2
X(A)
X(A)
X(A)
T3 T4
X(B)
X(B)
T1 T2
X(A) T1 T2
W(A)
X(B)
W(B)
X(A)
W(A)
X(B)
W(B)
Recovery schemes of this category apply undo and
also redo for recovery.
In a single-user environment no concurrency control
is required but a log is maintained under WAL.
Note that at any time there will be one transaction in
the system and it will be either in the commit table
or in the active table.
The recovery manager performs:
Undo of a transaction if it is in the active table.
Redo of a transaction if it is in the commit table.
X Y
X' Y'
Database
Page 4
(old)
1
Page 1 1
2
2
3
Page 3 3
4
4
5
Page 2 5
Current directory
(new) Shadow directory
(updating pages 2 & 4)
Page 4
(new)
Page 2
(old)
Database Management Systems
Shadow Paging
To manage access of data items by concurrent