Two Phase Locking (2PL)
Two-Phase Locking (2PL)
is a concurrency control method. It ensures conflict serializable schedules. 2PL
divides the execution phase of a transaction into three parts.
- In the first phase, when the
transaction begins to execute, it requires permission for the locks it
needs.
- The second part the transaction
acquires all the locks. When a transaction releases its first lock, the
third phase starts.
- In this third phase, the
transaction cannot demand any new locks. Instead, it only releases the
acquired locks.
The
Two-Phase Locking protocol allows each transaction to make a lock or unlock
request in two steps:
- Growing Phase: In this phase transaction may obtain locks but may
not release any locks.
- Shrinking Phase: In this phase, a transaction may release locks but
not obtain any new lock
2PL
protocol offers serializability. The 2PL algorithm offers
Strict Serializability, which is the golden standard when it comes to data
integrity. But it does not avoid cascading rollback and deadlocks.
Consider
a schedule:
Where
LP is lock point, Read(A)
in T2 and T3 denotes Dirty Read because of Write(A) in T1.
Because of Dirty Read in T2 and T3 in lines 8
and 12 respectively, when T1 failed we have to rollback others
also. Hence Cascading Rollbacks are possible in 2-PL.
No comments:
Post a Comment