in Databases
7,437 views
3 votes
3 votes
How to check if a schedule is allowed in 2PL or not?

S1:R2(A)W1(B)W1(C)R3(B)R2(B)R1(A)R2(C)W3(A)

S2:W2(A)W1(A)W3(A)W2(B)W1(B)W3(B)
in Databases
7.4k views

4 Comments

@joshi,It is not always  true that every serialzble schedule is allowed under 2PL because a conflict serializle schedule may or may not be in 2PL.

see this https://gateoverflow.in/42378/conflict-serializable-and-2pl-schedule

http://www.edugrabs.com/2-phase-locking/

thats why I want to know is there any procedure to find out when schedules are given like this without locks.
1
1
yes, true...i missed that thing.
0
0
0
0

2 Answers

6 votes
6 votes

Schedule: A predefined timely order execution of two or more transaction. The order of execution has to be maintained.

  S1:R2(A)W1(B)W1(C)R3(B)R2(B)R1(A)R2(C)W3(A)  
T1 T2 T3
  Lock_R(A)  
  R(A)  
Lock_X(B)    
W(B)    
Lock_X(C)    
W(C)    
Lock_R(A)    
Unlock(B)    
Unlock(C)    
    Lock_R(B)
    R(B)
  Lock_R(B)  
  R(B)  
R(A)    
U(A)    
  Lock_R(C)  
  R(C)  
    Lock_X(A)
    W(A)

Therefore, S1 can definitely allowed in 2PL.

S2:W2(A)W1(A)W3(A)W2(B)W1(B)W3(B)

T1 T2 T3
  Lock_X(A)  
  W(A)  
  Lock_X(B)  
  Unlock(A)  
Lock_X(A)    
W(A)    
Lock_X(B) //denied    
     
     
     
  W(B)  

Because in T2, Lock_X(B) has to be acquired in growing phase as T2 wants to W(B) (see in the given schedule), when T1 wants Lock_X(B) it is denied because T2 has it for W(B) operation later. Therefore, Transaction wont progress any further.
Some people might be having doubt that T2 has all the locks then why doesn't T2 completes its execution first by W(B) and release Lock(B), you are conceptually right but the problem is you are given a SCHEDULE in which order has to be maintained. If the task was you were given 3 transactions and you were asked whether there can a schedule possible which is allowed in 2PL then you can design such schedule, but here you are asked whether this schedule will pass through 2PL or not and the answer is NO. S2 is not allowed in 2PL, though it is Conflict Serializable, you can check by drawing precedence graph it will be an acyclic graph and you can find a topological order which is conflict equal to one of the serial schedules of S2.

3 Comments

In schedule S2 transaction T1 will deny lock_x(a) too right??
0
0
yes i think so
0
0
No it has already been unlocked by T2
0
0
2 votes
2 votes

both are allowed in 2PL.

4 Comments

plz share some ref to learn this topic??
0
0
(1)if schedule(s) not CSS(conflict serializable schedule) then not allowed to execute by 2pl.

(2) if schedule is executed by 2pl then schedule guaranteed CSS and equal to serial schedule based on order of lock points .

(3) every 2pl schedule is CSS but every CSS may not in 2pl.

For css you have to js draw precedence graph if graph is acyclic then css otherwise not
1
1
S2 not allowed by 2pl

Because x(A) for T1 denied by T2
0
0
www.mathcs.emory.edu/~cheung/Courses/554/Syllabus/7-serializability/2PL.html
0
0