2PL

Context

The serializability is a concurrency control property that a transaction system guarantees each transaction is getting executed one by one.

The 2PL or Two-Phase Locking is such method to reach serializability.

Overview

The 2PL is straightforward like its name - it has two phases.

Notably, a LOCK POINT is at which phase 1 ends, that is, when the transaction acquires the last lock it needs.

Solutions

Patterns

Shared Lock v/s Exclusive Lock

2PL handles below two locks.

Cascading Rollback

The cascading rollback is at when handling multiple transactions a failed transaction leads to all other transaction rollbacked in some cases.

For example, say we have below 3 transactions on 2 resources x and y.

Note: T1=Transaction 1, T2=Transaction 2, T3=Transaction 3. And so as below example.

The 2PL cannot avoid the cascading failure.

Deadlocks and Starvation

A deadlock is a state when each operation is waiting for some other operations to take action. However, no operation can proceed at all. When the deadlock happens, the system enters a state called starvation.

For example, say we have below two transactions on two resources x and y.

The 2PL cannot avoid the deadlock.

References