Question 76
Let us assume that transaction T1 has arrived before transaction T2. Consider schedule ?
S=r1(A); r2(B) ; w2(A) ; w1(B)
Which of the following is true?Step-by-Step Solution
Step-by-Step Explanation
Understand the Setup & Core Rules
Since transaction \(T_{1}\) arrives before transaction \(T_{2}\), their timestamps (\(TS\)) are ordered as:
\(TS(T_{1})
• \(TS(T_1) = 10\)
• \(TS(T_2) = 20\)
Initially, the Read Timestamp (\(R\_TS\)) and Write Timestamp (\(W\_TS\)) for both data items \(A\) and \(B\) are set to 0.
Protocol Rules for Basic Timestamp Ordering (TO)
• For a Read operation r_i(X):
• If \(TS(T_i) < W\_TS(X)\), then \(T_{i}\) is rolled back.
• Otherwise, the read is allowed, and \(R\_TS(X) = \max(R\_TS(X), TS(T_i))\).
• For a Write operation w_i(X):
• If \(TS(T_i) < R\_TS(X)\) or \(TS(T_i) < W\_TS(X)\), then \(T_{i}\) is rolled back.
• Otherwise, the write is allowed, and \(W\_TS(X) = TS(T_i)\).Trace the Schedule \(S = r_1(A); r_2(B); w_2(A); w_1(B)\)
\(r_1(A)\): \(T_{1}\) reads \(A\)
• Check: \(TS(T_1) = 10 \ge W\_TS(A) = 0\) (Allowed)
• Update: \(R\_TS(A) = \max(0, 10) = \mathbf{10}\)\(r_2(B)\): \(T_{2}\) reads \(B\)
• Check: \(TS(T_2) = 20 \ge W\_TS(B) = 0\) (Allowed)
• Update: \(R\_TS(B) = \max(0, 20) = \mathbf{20}\)\(w_2(A)\): \(T_{2}\) writes \(A\)
• Check: \(TS(T_2) = 20 \ge R\_TS(A) = 10\) and \(TS(T_2) = 20 \ge W\_TS(A) = 0\) (Allowed)
• Update: \(W\_TS(A) = \mathbf{20}\)\(w_1(B)\): \(T_{1}\) writes \(B\)
• Check: Compare \(TS(T_1)\) against \(R\_TS(B)\)
• Since \(TS(T_1) = 10 < R\_TS(B) = 20\), this violates the protocol. \(T_{1}\) is attempting to write an older value into a data item that has already been read by a newer transaction (\(T_{2}\)).Conclusion
Because of the protocol violation at step 4, \(T_{1}\) is rejected and rolled back, making Option B the correct statement.