DATABASE MANAGEMENT SYSTEM

LOCK BASED PROTOCOL

In database management systems (DBMS), a lock-based protocol is a fundamental mechanism used to control concurrent access to data items by multiple transactions. Its primary goal is to ensure data consistency and transaction isolation in a multi-user environment where multiple transactions may access and modify the same data concurrently.

Types of Locks

  1. Shared (Read) Lock:
  • A transaction holding a shared lock on a data item can read but cannot modify it.
  • Multiple transactions can hold shared locks simultaneously on the same data item, allowing for concurrent reading.
  1. Exclusive (Write) Lock:
  • A transaction holding an exclusive lock on a data item can both read and modify it.
  • Only one transaction can hold an exclusive lock on a data item at any given time, ensuring that writes are serialized and preventing concurrent writes that could lead to inconsistent data.

TYPES OF LOCK BASED PROTOCOLS

  1. Simplistic Lock Protocol

       a. Exclusive Lock Only:

  • Transactions acquire exclusive locks (write locks) on data items they intend to modify.
  • Once a transaction holds an exclusive lock on a data item, no other transaction can read or write to that data item until the lock is released.
  1. Lock Acquisition:
  • A transaction requests an exclusive lock before it performs any write operation (such as an update or delete) on a data item.
  • If another transaction already holds the lock on that data item, the requesting transaction must wait until the lock is released.
  1. Lock Release:
  • The exclusive lock is released once the transaction commits or aborts.
  • Upon release, other transactions waiting to acquire the lock can proceed with their operations on the data item.

2. Pre-claiming Lock Protocol

  1. Transaction Initiation:
  • Before a transaction begins executing, it pre-claims (or pre-acquires) locks on all data items it may need during its execution. This is typically done during the transaction's initialization phase.
  1. Lock Acquisition:
  • Instead of acquiring locks on demand (i.e., when the transaction needs to access a data item), the transaction acquires all necessary locks upfront.
  • Transactions may acquire shared locks (for reading) or exclusive locks (for writing) depending on their operations.
  1. Execution Phase:
  • Once a transaction has pre-claimed all necessary locks, it proceeds with its operations without needing to acquire additional locks during its execution phase.
  • This reduces the overhead of lock management during the critical path of transaction processing.
  1. Lock Release:
  • Locks are released in the usual manner after the transaction completes its execution, either by committing or aborting.
  • This ensures that other transactions can subsequently access the data items.

 

3. Two-Phase Locking (2PL)

Two-phase locking (2PL) is a well-known concurrency control protocol used in database management systems (DBMS) to ensure serializability of transactions. It governs how transactions acquire and release locks on data items, aiming to prevent conflicts that can lead to data inconsistency. Here’s an in-depth look at the Two-Phase Locking protocol:

Phases of Two-Phase Locking:

              a) Growing Phase (Lock Acquisition):

  • During this phase, a transaction can acquire locks on data items but cannot release any lock.
  • As the transaction executes, it may acquire both shared (read) locks and exclusive (write) locks on data items it accesses.
  • Once a transaction releases a lock (in the shrinking phase), it cannot acquire any new locks.

     b)Shrinking Phase (Lock Release):

  • After a transaction starts releasing locks, it cannot acquire any new locks on data items.
  • The transaction continues to release locks as it completes its operations and prepares to commit or abort.

4. Strict Two-Phase Locking (Strict-2PL)

Strict Two-Phase Locking (Strict-2PL) is a variant of the Two-Phase Locking (2PL) protocol in database management systems (DBMS) in which locks are released only after commit. 

  • In Strict Two-Phase Locking (Strict-2PL), the initial phase resembles the traditional Two-Phase Locking (2PL) protocol. 
  • During this phase, transactions acquire all necessary locks upfront and proceed with their operations without releasing any locks prematurely.
  •  Unlike 2PL, however, Strict-2PL retains each lock until the transaction completes its execution. 
  • Specifically, locks are not released after their immediate use; instead, all locks held by the transaction are released simultaneously upon its commitment. 
  • Unlike 2PL, Strict-2PL does not include a shrinking phase for gradual lock release.