Strict two-phase locking

Strict two-phase locking

In computer science, strict two-phase locking (Strict 2PL) is a locking method used in concurrent systems.

The two rules of Strict 2PL are:

# If a transaction T wants to read/write an object, it must request a shared/exclusive lock on the object.
# All locks held by transaction T are released when T commits (and not before).

Here is an example of Strict 2PL in action with interleaved actions.

:D = egin{bmatrix}T1 & T2 \S(A) & \R(A) & \ & S(A) \ & R(A) \ & X(B) \ & R(B) \ & W(B) \ & Commit \X(C) & \R(C) & \W(C) & \Commit &end{bmatrix}

or in text form:

T1: S(A), R(A); T2: S(A), R(A), X(B), R(B), W(B), Commit; T1: X(C), R(C), W(C), Commit

where
*S(O) is a shared lock action on an object O
*X(O) is an exclusive lock action on an object O
*R(O) is a read action on an object O
*W(O) is a write action on an object O

Strict 2PL prevents transactions reading uncommitted data, overwriting uncommitted data, and unrepeatable reads. Thus, it prevents cascading rollbacks, since eXclusive locks (for write privileges) must be held until a transaction commits.

Strict 2PL does not guarantee a deadlock-free schedule

Avoiding deadlocks can be important in real time systems, and may additionally be difficult to enforce in distributed data bases, or fault tolerant systems with multiple redundancy.

A deadlocked schedule allowed under Strict 2PL:

:G = egin{bmatrix}T1 & T2\X(A) & \ & X(B) & \X(B) & \ & X(A) end{bmatrix}

Text:T1: X(A) T2:X(B) T1:X(B) T2: X(A)

T1 is waiting for T2's lock on B to be released, while T2 is waiting for T1's lock on A to be released. These transactions cannot proceed and both are deadlocked.

There is no general solution to the problem of deadlocks in computing systems, so they must be anticipated and dealt with accordingly. Nonetheless, several solutions such as the Banker's algorithm or the imposition of a partial ordering on lock acquisition exist for avoiding deadlocks under certain conditions.

Even more strict than strict two-phase locking is rigorous two-phase locking, in which transactions can be serialized by the order in which they commit. Under rigorous 2PL, all locks (shared and exclusive) must be held until a transaction commits. Most database systems use strict 2PL.

Non-strict two-phase locking

In computer science, non-strict two-phase locking, also 2PL, is a locking method used in concurrent systems.

The rules for 2PL are similar to those of Strict 2PL:

# If a transaction T wants to read/write an object, it must request a shared/exclusive lock on the object.
# A transaction cannot request additional locks on any object once it releases any lock, and it can release locks at any time (not only at commit time, as in Strict 2PL).

So, every transaction has a growing phase (it acquires locks) and a shrinking phase (it releases locks). 2PL allows only conflict serializable schedules, but doesn't guarantee that deadlocks will be avoided.

2PL is one scheduling algorithm, sometimes used instead of:

*simultaneous locking, simultaneous release (Disadvantage: redundant locking, no interactive transactions)
*incremental locking, simultaneous release (Disadvantage: Deadlock)
*simultaneous locking, incremental release (Disadvantage: rollback, redundant locking)
*incremental locking, incremental release (Disadvantage: deadlock, rollback)

External links

* [http://www-stud.uni-due.de/~selastoe/?mdl=dbms&mode=strict automatic schedule solver and generator] by Laurens Stötzel, University of Duisburg-Essen, Germany


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Two-phase locking — This article is about concurrency control. For commit consensus within a distributed transaction, see Two phase commit protocol. In databases and transaction processing two phase locking, (2PL) is a concurrency control method that guarantees… …   Wikipedia

  • Two phase locking — 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… …   Wikipedia

  • Rigorous two-phase locking — In computer science, rigorous two phase locking (Rigorous 2PL) is a locking method used in concurrent systems.The two rules of Rigorous 2PL are:# If a transaction T wants to read/write an object, it must request a shared/exclusive lock on the… …   Wikipedia

  • Conservative two-phase locking — In computer science, conservative two phase locking (C2PL) is a locking method used in DBMS and relational databases. Conservative 2PL prevents deadlocks. The difference between 2PL and C2PL is that C2PL s transactions obtain all the locks they… …   Wikipedia

  • Multiple granularity locking — In computer science, multiple granularity locking (MGL), sometimes called the John Rayner locking method, is a locking method used in database management systems (DBMS) and relational databases. In MGL, locks are set on objects that contain other …   Wikipedia

  • Commitment ordering — In concurrency control of databases, transaction processing (transaction management), and related applications, Commitment ordering (or Commit ordering; CO; (Raz 1990, 1992, 1994, 2009)) is a class of interoperable Serializability techniques …   Wikipedia

  • Serializability — In concurrency control of databases,[1][2] transaction processing (transaction management), and various transactional applications (e.g., transactional memory[3] and software transactional memory), both centralized and distributed, a transaction… …   Wikipedia

  • Global serializability — In concurrency control of databases, transaction processing (transaction management), and other transactional distributed applications, Global serializability (or Modular serializability) is a property of a global schedule of transactions. A… …   Wikipedia

  • Concurrency control — In information technology and computer science, especially in the fields of computer programming (see also concurrent programming, parallel programming), operating systems (see also parallel computing), multiprocessors, and databases, concurrency …   Wikipedia

  • Deadlock — This article is about the computer science concept. For other uses, see Deadlock (disambiguation). A deadlock is a situation where in two or more competing actions are each waiting for the other to finish, and thus neither ever does. It is often… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”