Two Phase Locking

What
Two phase locking is an implementation that guarantees conflict serializability

Rules

 * 1) Before reading, each transaction must obtain either a shared lock or an exclusive lock on the object.
 * 2) A transaction cannot request new locks once it has released any locks

Time vs. Number of Locks
There will naturally be a growing phase followed by a shrinking phase when dealing with two phase locking necessarily because of the second condition.

Implications

 * Two_phase_locking_serializability.png phase locking on its own is enough to guarantee conflict serializability because it does not allow dependency cycles
 * Using two phase locking, the schedule of conflicting transactions is conflict equivalent to a serial schedule ordered by lock point. The diagram to the right shows that if we have three transactions (t1, t2, t3) with lock points l1,l2, and l3 respectively, we can get an equivalent schedule with a serial ordering of t1, t2, t3.

What
Strict two phase locking solves a problem with the regular two phase locking method which is cascading aborts. A cascading abort is when a rollback of one transaction necessarily requires a rollback of another transaction.

Example
The example to the right shows the necessity for a cascading abort, as the second transaction uses an object modified by the first transaction.

Rules

 * 1) Same as original two phase locking
 * 2) Transactions don't release their locks until their results are committed.

Examples

 * Example: Strict 2PL