Two-Phase Locking (2PL): Conflict-Serializability and Lock-Point Serialization Order
Two-phase locking {keyword{def="Protocol using a growing phase followed by a shrinking phase for each transaction"} keyword{def="Lock point is the operation where a transaction acquires the lock that first determines ordering"} keyword{def="Precedence graph represents rw/wr/ww order constraints between transactions"} } (2PL) enforces a disciplined way to acquire and release locks so that the resulting schedule is conflict-serializable. Moreover, for each pair of conflicting transactions, their relative order in the equivalent serial schedule is determined by the lock points—the specific lock acquisition events that enforce the conflicts.
At a high level:
- To show conflict serializability, we show that the precedence graph of a 2PL schedule is acyclic.
- To show the serialization order follows lock points, we define a “lock-based” ordering between transactions implied by the first (or relevant) lock acquisitions, and we prove that this ordering is exactly the serial order captured by the precedence graph.
A crucial idea is that in 2PL, once a transaction begins releasing locks (shrinking phase), it can no longer acquire new locks. This prevents “lock re-acquisition” patterns that would otherwise create cycles in the precedence graph.
Two-Phase Locking (2PL) & Conflict Serializability (Locking-Based Ordering)
Formal setting: schedules, conflicts, and precedence graphs
Let a schedule be an interleaving of operations from transactions. Conflicts arise when two operations from different transactions:
- access the same data item, and
- at least one is a write, and
- the two operations occur in different orders in the schedule.
We build a precedence graph (a directed graph) where each node is a transaction, and we add an edge if the schedule contains a conflict where ’s operation occurs before ’s corresponding conflicting operation on the same item. Then:
- The schedule is conflict-serializable iff the precedence graph is acyclic (equivalently, has a topological order corresponding to a serial order).
This is the standard route: prove 2PL ⇒ acyclic precedence graph ⇒ conflict serializable.
Prove that 2PL schedules are conflict-serializable (via acyclicity of the precedence graph)
- 1Step 1
Take any 2PL schedule and construct its precedence graph : add edge whenever an operation of conflicts with an operation of and occurs earlier in .
- 2Step 2
Assume contains a cycle: . For each edge , pick a concrete conflicting pair of operations on some data item that witnesses this edge.
- 3Step 3
Because operations on a data item must hold compatible/exclusive locks, the conflicting operation order implies that the earlier transaction acquired a lock on its required mode for that item before the later transaction could perform its conflicting operation.
- 4Step 4
For any item , consider the lock acquisitions around its conflicting operations. In a cycle, you would need each transaction to be ‘ahead’ in lock acquisition for the item that creates each edge, but the 2PL growing-then-shrinking rule forbids a transaction that has started releasing locks from later acquiring a lock needed to create a later edge in the cycle.
- 5Step 5
In a cycle, you force at least one transaction to acquire (for some edge) a lock after it has begun releasing locks—violating 2PL.
- 6Step 6
Since assuming a cycle leads to contradiction, must be acyclic. Therefore is conflict-serializable.
Why the shrinking phase blocks cycles (core intuition)
A precedence-cycle requires “mutual forcing”: transaction must appear before for some item, before , …, and finally before . In lock-based terms, that would require a pattern where the transactions keep acquiring locks in a way that alternates who holds/requests locks “later” in the schedule while still respecting lock compatibility.
Under 2PL, each transaction has:
- a growing phase: it may acquire locks, but does not release them, then
- a shrinking phase: it may release locks, but does not acquire new ones.
This structure prevents the kind of “after-releasing, later-acquire” behavior that cycles would require. Hence a cycle can’t exist in the precedence graph.
type="tip" title="Tip: Think in terms of ‘who must lock first’" content="Every precedence edge comes from a conflicting operation order on some data item . Under locking, that means must have acquired the decisive lock on before could do the conflicting operation. In a cycle, these lock-order requirements conflict with the shrinking-phase rule."
type="warning" title="Warning: This relies on the strict 2PL rule" content="If you allow transactions to release some locks but still acquire new ones later (i.e., not strict/2PL), precedence cycles may become possible. The ‘no lock acquisition during shrinking’ property is what blocks the cyclic ordering."
Lock Points and the Corresponding Serialization Order
Definitions: lock points, conflicting transactions, and serialization order
We now refine the result: not only is the schedule conflict-serializable, but the serial order can be chosen based on lock points.
A keyword lock point is commonly taken as the acquisition time of the lock on the data item that is responsible for enforcing the precedence relation.
For a particular pair of transactions and that conflict on some item , suppose in the schedule there is an operation of before the conflicting operation of . Then the precedence graph has an edge .
Under 2PL, we can show:
- The transaction that acquires the relevant lock first becomes earlier in the equivalent serial schedule.
- More generally, if we define a serial order consistent with all precedence edges, that serial order equals the ordering induced by these lock points.
Construct the equivalent serial schedule order from lock points
- 1Step 1
For every edge in , select the conflicting operations on a data item where ’s operation occurs earlier in the schedule.
- 2Step 2
For the witnessing operations on , determine the lock acquisition events that make the second transaction’s conflicting operation possible. The earlier transaction’s decisive lock acquisition is the lock point that supports .
- 3Step 3
Create an order relation: if is forced by a conflict whose decisive lock point for occurs earlier than ’s corresponding decisive lock point, then place before in the serial order.
- 4Step 4
Because is acyclic under 2PL, the edge constraints are jointly satisfiable by some topological ordering. The lock-point ordering matches these constraints; hence the constructed order yields a valid serial schedule.
- 5Step 5
Therefore, the transaction order in the equivalent serial schedule can be chosen to follow the lock points that determine each conflict’s direction.
A visualization: lock points induce precedence edges
Consider a conflict on between and . The lock point order implies the precedence edge direction.
Because 2PL prevents new lock acquisitions during shrinking, these lock-point-implied edges cannot be arranged into cycles; the resulting graph has a topological order that matches lock-point order.
Relationship between properties
How 2PL constraints translate into graph properties and serializability.
Key nuances and common misconceptions
2PL Conflict Serializability & Lock Points
Knowledge Check
To prove a schedule is conflict-serializable using the precedence graph method, which property must you prove about the precedence graph under 2PL?