Recent Post

Lock Types

 Binary Locks
Two states : locked (1) or unlocked (0).
Locked objects are unavailable to other objects.
Unlocked objects are open to any transaction.
Transaction unlocks object when complete.
Every transaction requires a lock and unlock operation for each data item that is accessed.
It locks before use of data item and release the lock after performing operation.
Problems with binary locks : Irrecoverability, Deadlock and Lock Concurrency level.

 Shared/Exclusive Locks:
  1. Shared (S Mode )
      (i) Exists when concurrent transactions granted READ access.
      (ii) Produces no conflict for read-only transactions.
      (iii) Issued when transaction wants to read and exclusive lock not held on item.

  2. Exclusive (X Mode):
        (i) Exists when access reserved for locking transaction.
        (ii) Used when potential for conflict exists.
        (ii) Issued when transaction wants to update unlocks data

 Lock-compatibility matrix:
  (a) A transaction may grants a lock on item if the request lock is compatible with locks already held on item by other transaction.
  (b) Any number of transactions can hold shared locks on an item,but if any transaction holds an exclusive on the no other transaction may hold any lock on the item.

 Problems with Locking:
  (a) Transaction schedule may not be serialisable: Managed through two-phase locking.
  (b) Schedule may create deadlocks: Managed by using deadlock detection and prevention techniques.

Two-Phase Locking
   Two-phase locking defines how transaction acquire and relinquish locks.
1. Growing phase: Acquired all the required locks without unlocking any data. Once all locks have been acquired, the transaction is in its locked point.
2. Shrinking phase: Releases all locks and cannot obtain any new lock.
  Governing rules of 2PL :
   (i) Two transactions cannot have conflicting locks.
   (ii) No unlock operation can precede a lock operation in the same transaction.
   (iii) No data are affected until all locks are obtained.

Basic 2PL Protocol
  Equal serial schedule based on lock point.
  Problems with basic 2PL : Irrecoverability, Deadlock and Starvation.

Strict 2PL Protocol
  Basic 2PL with all exclusive locks should be hold until commit/roll back.
  It ensure serializability strict recoverable.
  Problems with strict 2PL: Starvation and irrecoverability.

Rigorous 2PL protocol
  Basic 2PL with all locks (S/X) should be hold until commit.
  Equivalent serial schedule based on order of commit.

Class Diagram of Schedules with Serializability


No comments