DBMS Notes

Categories of Two Phase Locking

As we know Basic 2-PL achieve the serializability, but if we want to achieve cascadless, recoverability and deadlock removal from 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.
  • And each transaction should holds all Exclusive(X) Locks until the Transaction is Commits or abort.

2. Rigorous 2-PL

It is similar to Strict 2-PL in its advantage and disadvantage but little bit more strict than Strict 2-PL.

A schedule will be in Rigorous 2PL if

  • It must satisfy the basic 2-PL.
  • And each transaction should holds  all Exclusive(X) Locks as well as Shared(S) Locks  until  the Transaction is Commits or abort.

Difference between Strict and Rigorous 2PL

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

But in Rigorous 2PL, If T1 acquire Shared lock on data  “A” and T2 also request for shared lock on same data “A” then it will not be granted. Because T1 has to commit before to grant shared lock to T2.

Following figure explain all

Advantages of Strict/ Rigorous 2PL

There are same advantages and disadvantage of Strict/ Rigorous 2PL. Explained under

Recoverable: As T2 can’t acquire any lock until T1 committed or abort. So if T1 fail then no effect on the T2 so schedule will become recoverable.

Cascadeless: As T2 can’t acquire any lock until T1 committed or abort. So if T1 fail then no effect on the T2 so schedule will become cascadless. Cascadless means rollback of one transaction doesn’t effect the other transactions.

Note: Still deadlock and starvation problems are exist in strict 2-PL

3. Conservative 2-PL

It is just a assuming technique which cannot implemented where,

Before to start 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 rest of transactions (T2, T3  … Tn) will not access the data until T1 commit or abort.

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

Keep in mind: it is difficult to use in practice because of 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

 

Help Other’s By Sharing…

Contact Us

Burewala, Vehari, Punjab, Pakistan

cstaleem1@gmail.com

Website: CStaleem.com

Pin It on Pinterest