Two phase locking protocol in dbms
Two Phase Locking (2PL) Protocol
Two-Phase locking protocol which is also known as a 2PL protocol. It is also called P2L. In this type of locking protocol, the transaction should acquire a lock after it releases one of its locks.
This locking protocol divides the execution phase of a transaction into three different parts.
- In the first phase, when the transaction begins to execute, it requires permission for the locks it needs.
- The second part is where the transaction obtains 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
example:-
-- lock x(b);
-- read(b);
-- B=B-50;
-- write(B);
-- lock x(a);
-- read(a);
-- A=A-50;
-- write(a);
-- unlock(B);
-- unlock(a);
ADVANTAGE:-
1. the two phase locking protocol ensure conflict serializibility.
DISADVANTAGE;-
1. The two phase locking protocol does not ensure freedom from deadlock.
thank you viewers.
Comments
Post a Comment