5

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:

  1. 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:

  1. 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?

2 Answers2

0

The first rule of thumb is if there are two non-conflicting operations in a schedule they can be swapped. S1 is view serializable and both w3[B]'s and w2[B] are blind writes and they can also be swapped. In order to apply strict 2PL, we need to guarantee that the last write on B is made by T3 i.e. the last operation in the resulting schedule should be w3[B]. Therefore, we can swap the first w3[B] with w2[B] and the answer should be:

x1[C] r1[C] s2[A] r2[A] r1[C] x2[B] w2[B] T3-waits-for-Xlock-on-B w1[C] commit1
u1[C] r2[A] commit2 u2[A] u2[B] x3[B] w3[B] w3[B] commit3 u3[B]
Rahul Sharma
  • 5,562
  • 4
  • 24
  • 48
0

If I understood the problem right, here's what you are suggesting:

  1. Schedule S1 is non CSR and hence non 2PL.
  2. 2PL scheduler takes input S1 and converts it to a 2PL schedule S2.
  3. You want this 2PL schedule S2 to be view equivalent to S1.

But why? The 2PL schedule only needs to be view and conflict equivalent to its respective view and conflict equivalent serial schedules.

In other words:

  1. 2PL scheduler takes ANY schedule S1 and converts it into a 2PL schedule.
  2. This output schedule S2 is in CSR and hence also in VSR. (CSR ⊂ VSR)
  3. Now, if you generate a view equivalent serial schedule S3 from S2, this will be view equivalent to S2.
  4. And, if you generate a conflict equivalent serial schedule S4 from S2, this will be conflict equivalent to S2.
Pranaya Tomar
  • 199
  • 1
  • 13