8,563 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)

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.

2 votes
2 votes

both are allowed in 2PL.

Related questions

773
views
1 answers
0 votes
2.7k
views
2 answers
4 votes
learncp asked Oct 7, 2015
2,659 views
$\begin{bmatrix} T1 &T2 \\ R(A) & \\ W(A)& \\ & R(A)\\ & W(A)\\ &R(B) \\ &W(B) \\ & Commit\\ Abort& \end{bmatrix}$How is this ... present in T2 ..?This example is given in the book by Raghu Ramkrishnan on page 529 and 552 (for reference)
1.6k
views
3 answers
1 votes
learncp asked Sep 18, 2015
1,580 views
Suppose we have a schedule containing two transactions  as shown- ... t2, and for B we will get t1->t2.. Same graph will be obtained if we draw a single polygraph
440
views
1 answers
1 votes
gate-17 asked Jul 27, 2016
440 views