Database Management Systems (2130703)

BE | Semester-3   Summer-2018 | 05/23/2018

Q4) (b)

Write a note on two phase locking protocol.

Two-Phase Locking Protocol

  • The use of locks has helped us to create neat and clean concurrent schedule.
  • The Two Phase Locking Protocol defines the rules of how to acquire the locks on a data item and how to release the locks.
  • Two phase locking (2PL) is a concurrency control method that guarantees serializability.
  • The protocol utilizes locks, applied by a transaction on data, which may block (stop) other transactions from accessing the same data during the transaction's life.
  • The Two Phase Locking Protocol assumes that a transaction can only be in one of two phases.

Phase 1 - Growing Phase

  • In this phase the transaction can only acquire locks, but cannot release any lock.
  • The transaction enters the growing phase as soon as it acquires the first lock it wants.
  • From now on it has no option but to keep acquiring all the locks it would need.
  • It cannot release any lock at this phase even if it has finished working with a locked data item.
  • Ultimately the transaction reaches a point where all the lock it may need has been acquired. This point is called Lock Point.

Phase 2 - Shrinking Phase

  • After Lock Point has been reached, the transaction enters the shrinking phase.
  • In this phase the transaction can only release locks, but cannot acquire any new lock.
  • The transaction enters the shrinking phase as soon as it releases the first lock after crossing the Lock Point.
  • From now on it has no option but to keep releasing all the acquired locks.
  • Initially the transaction is in growing phase, that is the transaction acquires locks as needed.
  • Once the transaction releases lock, it enters the shrinking phase and no more lock request may be issued.
  • Upgrading of lock is not possible in shrinking phase, but it is possible in growing phase.
  • The two phase locking protocol ensures serializability.
  • There are two different versions of the Two Phase Locking Protocol.
    1. Strict Two Phase Locking Protocol
    2. Rigorous Two Phase Locking Protocol.