- Two phase locking
In
databases andtransaction processing , two phase locking, (2PL) is a "concurrency control " locking protocol, mechanism, that guaranteesserializability . It is also the name of the resulting "class" (set) oftransaction schedules. Using "locks" that block processes, 2PL is subject to "deadlock s" that result from the mutual blocking of two transactions or more.Two phase locking
A Lock is a database system object, associated with a database object (typically a data item). It is associated (applied) by a transaction with (to) the database object before accessing it. Lock existence prevents undesired (typically synchronization rule violating) operations of other transactions from acting upon that database object by blocking them. A database operation upon a database object checks for lock existence for that object, and halts when noticing a lock type that is intended to block it (according to a predefined agreement/locking-scheme).
According to the two phase locking protocol, a transaction handles its locks 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.
trict 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". On the other hand, "read (shared)" locks are released regularly during phase 2.
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.
trong 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 system s since it provides besidesserializability also Strictness, which is instrumental for efficientdatabase recovery, and alsocommitment ordering (CO) for participating in environments where a CO basedglobal 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.ee also
*
Serializability
*Lock (computer science)
Wikimedia Foundation. 2010.