2-phase locking.

I am trying to solve it and looking for someone who can help me. coz its going out of my head.

1Comment
Sumit Verma @sumitkgp
12 Apr 2017 05:57 pm

Schedule S : r1(X) w1(Y) w1(X) r2(Z) w2(Z) C2 r1(Z) w1(Z) C1
We can represent the schedule in the following manner:

T1 T2
R(X)  
W(Y)  
W(X)  
  R(Z)
  W(Z)
  Commit
R(Z)  
W(Z)  
Commit  

Part a: In Two phase locking protocol (2PL), Locks can be obtained in growing phase and locks can be released in shrinking phase.
We can write the above schedule in 2PL as below, 

T1 T2
LX- (X)  
LX- (Y)  
R(X)  
W(Y)  
W(X)  
  LX-(Z)
  R(Z)
  W(Z)
  U (Z) 
  Commit
LX-(Z)  
R(Z)  
W(Z)  
U(X)  
U(Y)  
U(Z)  
Commit  

Part b. In strict 2PL , all exclusive locks will be released only after commit or abort of the transaction. This schedule is also allowed in strict 2PL, if we will unlock all the exclusive locks after the commit operation.

T1 T2
LX- (X)  
LX- (Y)  
R(X)  
W(Y)  
W(X)  
  LX-(Z)
  R(Z)
  W(Z)
  Commit
  U (Z) 
LX-(Z)  
R(Z)  
W(Z)  
Commit  
U(X)   
U(Y)   
U(Z) 

Part c. There won't be any change if transaction 2 aborts instead of commit.