For example if we have the schedule S1 :
r1[C] r2[A] r1[C] w3[B] w2[B] w1[C] commit1 r2[A] commit2 w3[B] commit3
We know that this schedule is not conflict serializable , so it cannot come from 2 phase locking, but it is view-serializable. However if we wanted to apply Strict 2PL to the above schedule would the answer be:
x1[C] r1[C] s2[A] r2[A] r1[C] x3[B] w3[B] T2-waits-for-Xlock-on-B w1[C] commit1 u1[C] w3[B] commit3 u3[B] x2[B] w2[B] r2[A] commit2 u2[A] u2[B]
Where u1[C] means that T1 releases the lock on object C. In this case the last write on B will be done by T2 which is different than the original schedule S1.
Or is the correct application of Strict 2PL the following:
x1[C] r1[C] s2[A] r2[A] r1[C] x3[B] w3[B] T2-waits-for-Xlock-on-B w1[C] commit1 u1[C] T3-waits-for-T2-to-take-lock-on-B-in-order-to-execute-w2[B]-first
In this case the order of reads and writes by each transaction is preserved but Deadlock occurs.
To summarize my question: Which is the correct way of applying 2 Phase Locking (Strict) in Schedule S1?
Is it mandatory to keep the order of commands the same as the original schedule, everytime we apply 2 phase locking?
question from:
https://stackoverflow.com/questions/65922532/does-2-phase-locking-need-to-keep-the-order-of-commands 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…