Intro to DBMS

Categories of Two Phase Locking

As we know, Basic 2-PL achieves serializability, but if we want to achieve cascades, recoverability, and deadlock removal from the schedule, then we have to use categories of two-phase locking.

Categories of 2-PL

There are three basic categories of 2-PL

1. Strict 2-PL

A schedule will be in Strict 2PL if

  • It must satisfy the basic 2-PL.
  • Each transaction should hold all Exclusive(X) Locks until the Transaction is Commited or aborted.

2. Rigorous 2-PL

It is similar to Strict 2-PL in its advantages and disadvantages but a little bit more strict than Strict 2-PL.

A schedule will be in Rigorous 2PL if

  • It must satisfy the basic 2-PL.
  • Each transaction should hold all Exclusive(X) Locks as well as Shared(S) Locks until the Transaction is Commits or aborted.

Difference between Strict and Rigorous 2PL

In Strict 2PL, If T1 acquires a Shared lock on some data (Say A) and T2 also requests a shared lock on the same data (“A”), then it is granted.

But in Rigorous 2PL, If T1 acquires a Shared lock on data  “A” and T2 also requests a shared lock on the same data “A”, then it will not be granted because T1 has to commit before to granting a shared lock to T2.

The following figure explains all

Advantages of Strict/ Rigorous 2PL

There are the same advantages and disadvantages of strict/Rigid 2PL. Explained under

Recoverable: As T2 can’t acquire any lock until T1 commits or abort. So if T1 fails, then there is no effect on T2, so the schedule will become recoverable.

Cascadeless: T2 can’t acquire any lock until T1 commits or aborts. So if T1 fails, then no effect on T2 and the schedule will become cascadless. Cascadless means the rollback of one transaction doesn’t affect the other transactions.

Note: Deadlock and starvation problems still exist in strict 2-PL

3. Conservative 2-PL

It is just an assuming technique that cannot implemented where,

Before starting the transaction, the transaction (i.e., T1) should hold all the locks on all data items(i.e., A, B, C etc). In this way, the rest of the transactions (T2, T3  … Tn) will not access the data until T1 commits or aborts.

Conservative 2PL prevents deadlocks along with recoverability and cascadless. Because when any transaction holds all the resources, then it will never go to a deadlock state.

Keep in mind: it is difficult to use in practice because of the need to pre-declare the read-set and the write-set, which is not possible in many situations.

Compression of 2PL Categories

Rigorous is more strict than strict 2PL and basic 2PL. Look at the following diagram