Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
807 views
in Technique[技术] by (71.8m points)

distributed system - Does 2 phase locking need to keep the order of commands?

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?

question from:https://stackoverflow.com/questions/65922532/does-2-phase-locking-need-to-keep-the-order-of-commands

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...