Two phase locking

From Wikipedia, the free encyclopedia

In databases and transaction processing, two phase locking, (2PL) is a concurrency control locking protocol, mechanism, that guarantees serializability. It is also the name of the resulting class (set) of transaction schedules. Using locks that block processes, 2PL is subject to deadlocks that result from the mutual blocking of two transactions or more.


Contents

[edit] Two phase locking

According to the two phase locking protocol, locks are handled by a transaction in two distinct, consecutive phases during the transaction's execution:

Phase 1: locks are acquired and no locks are released.

Phase 2: locks are released and no locks are acquired.

The serializability property is guaranteed for a schedule with transactions that obey the protocol. The 2PL schedule class is defined as the class of all the schedules comprising transactions with data access orders that could be generated by the 2PL protocol.

[edit] Strict two phase locking

The Strict two phase locking (S2PL) class of schedules is the intersection of the 2PL class with the class of schedules possessing the strictness property.

To comply with the S2PL protocol a transaction needs to comply with 2PL, and release its write (exclusive) locks only after it has ended, i.e., being either committed or aborted.

Typically end of Phase 1 is safely determined when a transaction has entered its ready state in all its processes (processing has ended, and it is ready to be committed; no additional locking is possible). If several processes (two or more) are involved, then a synchronization point (similar to atomic commitment) among them is needed to determine end of Phase 1 for all of them. This is usually too costly, and end of Phase 1 is usually postponed to be merged with transaction end (atomic commitment protocol for a multiprocess transaction), which turns S2PL to SS2PL (see below).

S2PL is a special case of 2PL, i.e., the S2PL class is a proper subclass of 2PL.

[edit] Strong strict two phase locking

To comply with the strong strict two phase locking (SS2PL) protocol a transaction needs to comply with 2PL, and release both its write (exclusive) and read (shared) locks only after it has ended, i.e., being either committed or aborted. A transaction obeying SS2PL can be viewed as having phase 1 that lasts its entire execution duration, and no phase 2 (or a degenerate phase 2). Thus, only one phase is actually left, and "two-phase" in the name seems to be still utilized due to the historical development of the concept from 2PL. The SS2PL property of a schedule is also called rigorousness, and an SS2PL schedule is also called a rigorous schedule.

SS2PL is a special case of S2PL, i.e., the SS2PL class of schedules is a proper subclass of S2PL (every SS2PL schedule is also an S2PL schedule, but S2PL schedules exist that are not SS2PL).

SS2PL is the concurrency control protocol of choice for most database systems since it provides besides serializability also Strictness, which is instrumental for efficient database recovery, and also commitment ordering (CO) for participating in environments where a CO based global serializability solution is employed. Many variants of SS2PL exist that utilize various lock types with various semantics in different situations, including cases of lock-type change during a transaction. Notable are variants that use multi-granularity locking.

[edit] See also