recall

← recall

two-phase locking pattern

Transaction has two phases: growing (acquire locks, never release) and shrinking (release locks, never acquire). Guarantees serializability but at high contention cost. The 'classical' database concurrency control before MVCC dominated.

Transaction has two phases: growing (acquire locks, never release) and shrinking (release locks, never acquire). Guarantees serializability but at high contention cost. The 'classical' database concurrency control before MVCC dominated.

symptoms

  • need serializable isolation without MVCC
  • transactions deadlocking

causes

  • high contention on shared rows
  • lock acquisitions in different orders

fixes

  • enforce lock ordering to prevent deadlocks
  • short transactions to minimize lock-hold time
  • consider switching to MVCC if contention is the bottleneck

you might say

  • 2PL
  • two-phase locking

related

aliases: 2PL

topics: databases, concurrency

references: