Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Two Phase Locking 2PL Concurrency Control Protocol - Set 3 GeeksforGeeks

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

9/27/2019 Two Phase Locking (2-PL) Concurrency Control Protocol | Set 3 - GeeksforGeeks

Custom Search

COURSES Login

HIRE WITH US


Two Phase Locking (2-PL) Concurrency Control
Protocol | Set 3
Prerequisite – Basics of Two Phase Locking protocol(2-PL), Types of 2-PL.

Now, we know both Strict 2-PL and Rigorous 2-PL avoids Cascading Rollbacks and
ensures a Strict schedule but still cannot guarantee that our schedule is Deadlock free.
We have seen both Strict and Rigorous 2-PL are similar in application and a general
misconception is common that Conservative 2-PL also follows same sets of protocols as
the above two. For clarity let’s go through Conservative 2-PL in details.

Conservative 2-PL –

A.K.A Static 2-PL, this protocol requires the transaction to lock all the items it access
before the Transaction begins execution by predeclaring its read-set and write-set. If any
of the predeclared items needed cannot be locked, the transaction does not lock any of
the items, instead it waits until all the items are available for locking. So the operation on
data cannot start until we lock all the items required.

Now let’s see an interesting example on Conservative 2-PL. Tell me if the following
schedule follows Conservative 2-PL?

Schedule: Lock-S(A) Lock-X(B) Read(A) Read(B) Write(A) Unlock(A) Comm

Do you think the above Schedule does not follow Conservative 2-PL? Don’t confuse the
protocol as just a modi ed version of Rigorous 2-PL, We can release the locks whenever
we want, but we need to lock all the data items before carrying out any operation. This is
https://www.geeksforgeeks.org/two-phase-locking-2-pl-concurrency-control-protocol-set-3/ 1/6
9/27/2019 Two Phase Locking (2-PL) Concurrency Control Protocol | Set 3 - GeeksforGeeks

what makes it Deadlock-free. The above schedule follows Conservative 2-PL.


Some interesting traits about Conservative 2-PL:

Schedule following this will not have a Growing Phase as we’ve seen in Basic, Strict
and Rigorous 2-PL. As locking the data before using it is mandatory so this protocol
has no Growing phase. Moreover, this rule makes it Deadlock free as if an item is not
available for locking the transaction releases all the locks and tries again later, i.e, no
Hold and Wait. This makes one of the four necessary conditions for deadlock void.
We only have to lock all the items beforehand, so releasing or unlocking them has no
restrictions like we had in Strict or Rigorous 2-PL.
As no operations are done before acquiring all the locks, we have no Growing phase
in this protocol unlike Basic, Strict, Rigorous 2-PL.
Although we get a Deadlock free schedule but in this protocol we may still face
drawbacks like Cascading Rollbacks. So this protocol doen not ensure Strict
Schedules. This is a disadvantage in comparison to Strict and Rigorous 2-PL.

Let’s discuss an example now. See how the schedule below follows Conservative 2-PL but
does not follow Strict and Rigorous 2-PL.

T1 T2

1 Lock-X(A)

2 Lock-X(B)

3 Read(A)

4 *operation on

5 Write(A)

6 Unlock(A)

7 Lock-X(A)

8 Read(A)

9 *operation on

https://www.geeksforgeeks.org/two-phase-locking-2-pl-concurrency-control-protocol-set-3/ 2/6
9/27/2019 Two Phase Locking (2-PL) Concurrency Control Protocol | Set 3 - GeeksforGeeks

10 Write(A)

11 Unlock(A)

12 Read(B)

13 *operation on
B

14 Write(B)

15 Unlock(B)

16 Commit

17 Commit

Look at the schedule, it completely follows Conservative 2-PL, but fails to meet the
requirements of Strict and Conservative 2-PL, that is because we unlock A and B before
the transaction commits.

How can cascading abort happen in Conservative 2-PL?


This can happen because a Transaction may carry out a Dirty Read from another
Transaction. We don’t have such restrictions in our protocol so this situation is possible.

Look at the Example given above, we have a Dirty Read operation from T1 to T2 at Step 8.
If T1 aborts, then T2 would be rolled back.

GATE related question:


GATE-CS-2016 (Set 1) | Question 61

https://www.geeksforgeeks.org/two-phase-locking-2-pl-concurrency-control-protocol-set-3/ 3/6
9/27/2019 Two Phase Locking (2-PL) Concurrency Control Protocol | Set 3 - GeeksforGeeks

Recommended Posts:
Two Phase Locking Protocol
Graph Based Concurrency Control Protocol in DBMS
Lock Based Concurrency Control Protocol in DBMS
Categories of Two Phase Locking (Strict, Rigorous & Conservative)
Concurrency Control in DBMS
Concurrency Control Techniques
Timestamp based Concurrency Control
Difference between Stop and Wait protocol and Sliding Window protocol
Difference between Flow Control and Congestion Control
Implementation of Locking in DBMS
Multiple Granularity Locking in DBMS
Concurrency problems in DBMS Transactions
User Datagram Protocol (UDP)
E ciency of Stop and Wait Protocol
Difference between Stateless and Stateful Protocol

zerocool
Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using
contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See
your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you nd anything incorrect by clicking on the "Improve
Article" button below.

Improved By : Deeksharmaaa

Article Tags : DBMS GATE CS

https://www.geeksforgeeks.org/two-phase-locking-2-pl-concurrency-control-protocol-set-3/ 4/6
9/27/2019 Two Phase Locking (2-PL) Concurrency Control Protocol | Set 3 - GeeksforGeeks

Practice Tags : DBMS


2

1.8
To-do Done
Based on 5 vote(s)

Feedback/ Suggest Improvement Add Notes Improve Article

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.

Load Comments

https://www.geeksforgeeks.org/two-phase-locking-2-pl-concurrency-control-protocol-set-3/ 5/6
9/27/2019 Two Phase Locking (2-PL) Concurrency Control Protocol | Set 3 - GeeksforGeeks

5th Floor, A-118,


Sector-136, Noida, Uttar Pradesh - 201305
feedback@geeksforgeeks.org

COMPANY LEARN
About Us Algorithms
Careers Data Structures
Privacy Policy Languages
Contact Us CS Subjects
Video Tutorials

PRACTICE CONTRIBUTE
Courses Write an Article
Company-wise Write Interview Experience
Topic-wise Internships
How to begin? Videos

@geeksforgeeks, Some rights reserved

https://www.geeksforgeeks.org/two-phase-locking-2-pl-concurrency-control-protocol-set-3/ 6/6

You might also like