The locking technique uses a lock that guarantees the exclusive use of data of transactions. The lock is used to restrict different transaction which is executing at the same time.
There are 3 phases of Locking technique
- Taking the lock control and accessing the data of the transaction
- Complete the transaction execution
- Release lock
There are two types of lock available in this protocol
- Shared lock: It is also represented by ‘lock-S’, and allows only to read the data from the transaction.
- Exclusive lock: It is also represented by ‘lock-X, and allows both the read and write operation to the data from the transaction.
2-phase locking technique
It is the same as the Locking technique explained above but it has two phases to act which are:
- Growing phase: It is a phase where a transaction acquires the lock but does not release it.
- Shrinking phase: It is a phase where a transaction releases the lock but does not acquire it.
The 2-phase locking technique is further divided into 3 categories
- Strict 2 phase locking
- Rigorous 2 phase locking
- Conservative 2 phase locking
Strict 2 phase locking
This locking technique satisfies the basic 2 phase locking but holds all the exclusive locks until the transaction is committed or aborted during the execution.
Rigorous 2 phase locking
This locking technique satisfies the basic 2 phase locking but holds all the exclusive locks and shared locks until the transaction is committed or aborted during the execution.
Conservative 2 phase locking
It is a locking technique that satisfies the basic 2 phase locking but it holds all the required locks at the beginning of transaction execution.
Rigorous two-phase locking is stricter than any of the available categories but it is very easy to implement. It ensures Cascadeless and strict recovery.
|Rigorous 2 phase locking||Strict 2 phase locking||Conservative 2 phase locking|
|It locks the exclusive and shared locks until the transaction gets committed or aborted||It locks the exclusive locks only until the transaction gets committed or aborted||It acquires all the locks required for the transaction at the beginning of transaction execution.|
|It is easy to implement.||It is complex to implement.||It is not practically not possible.|
|It does not have any growing phase but has shrinking phase.||It does not have any growing phase but has shrinking phase.||It may have any growing phase but no shrinking phase|
|It is not deadlock-free.||It is not deadlock-free.||It is deadlock-free.|
|It is stricter than strict and conservative 2 phase locking||It is stricter than basic locking techniques.||It is practically not possible.|