Distributed Transactions 1 Transactions Distributed DBMS Model transactions
Distributed Transactions 1
Transactions Distributed DBMS Model transactions T data manager …. T DM TM …. T TM T transaction manager …. network T DM DM physical database CS 5204 – Fall, 2008 2
Transactions Serialization T 1 : concurrent execution T 2 : T 3 : DB log : CS 5204 – Fall, 2008 3
Transactions Serialization T 1 : concurrent execution T 2 : T 3 : DB log : OPERATIONS READ(X): read any one copy of X R 1 (X 3) WRITE (Z): write all copies of Z W 3(Z 2) and W 3 (Z 3) CS 5204 – Fall, 2008 4
Transactions Serialization T 1 : concurrent execution T 2 : T 3 : DB log : DB is acceptable if it is guaranteed to have resulted from any one of: T 1 T 2 T 3 T 2 T 1 T 3 T 2 T 3 T 1 T 2 T 3 T 2 T 1 CS 5204 – Fall, 2008 5
Transactions Serialization Consider two concurrent transactions executed at only one DM LOG: R 1(X) R 2(Y) R 1(Y) W 1(Z) W 1(X) W 2(X) R 2(Z) CS 5204 – Fall, 2008 6
Transactions Serialization Consider two concurrent transactions executed at only one DM LOG: R 1(X) R 2(Y) R 1(Y) W 1(Z) W 1(X) W 2(X) R 2(Z) Serial Order: R 2(Y) W 2(X) R 2(Z) ; R 1(X) R 1(Y) W 1(Z) W 1(X) CS 5204 – Fall, 2008 7
Transactions Serialization Consider two concurrent transactions executed at only one DM 2 LOG: R 1(X) R 2(Y) R 1(Y) W 1(Z) W 1(X) W 2(X) R 2(Z) 1 2 Serial Order: R 2(Y) W 2(X) R 2(Z) ; R 1(X) R 1(Y) W 1(Z) W 1(X) 1 2 last write conflict read source conflict CS 5204 – Fall, 2008 8
Transactions Serialization Consider two concurrent transactions executed at only one DM LOG: R 1(X) R 2(Y) R 1(Y) W 1(Z) W 1(X) W 2(X) R 2(Z) Serial Order: R 1(X) R 1(Y) W 1(Z) W 1(X) ; R 2(Y) W 2(X) R 2(Z) CS 5204 – Fall, 2008 9
Transactions Serialization Consider two concurrent transactions executed at only one DM LOG: R 1(X) R 2(Y) R 1(Y) W 1(Z) W 1(X) W 2(X) R 2(Z) Serial Order: R 1(X) R 1(Y) W 1(Z) W 1(X) ; R 2(Y) W 2(X) R 2(Z) CS 5204 – Fall, 2008 10
Transactions Distributed Transaction Processing Transactions: T 1 : READ(X); WRITE(Y); DM 1 T 2 : READ(Y); WRITE(Z); DM 2 T 3 : READ(Z); WRITE(X); DM 3 CS 5204 – Fall, 2008 X 1 Y 2 Z 3 X 3 11
Transactions Distributed Transaction Processing Transactions: T 1 : READ(X); WRITE(Y); DM 1 T 2 : READ(Y); WRITE(Z); DM 2 T 3 : READ(Z); WRITE(X); DM 3 X 1 Y 2 Z 3 X 3 LOGS: L 1 : R 2(Y 1) R 1(X 1) W 1(Y 1) W 3(X 1) L 2 : R 3(Z 2) W 2(Z 2) W 1(Y 2) L 3 : W 3(X 3) W 2(Z 3) CS 5204 – Fall, 2008 12
Transactions Distributed Transaction Processing Transactions: T 1 : READ(X); WRITE(Y); DM 1 T 2 : READ(Y); WRITE(Z); DM 2 T 3 : READ(Z); WRITE(X); DM 3 LOGS: X 1 Y 2 Z 3 X 3 L 1 : R 2(Y 1) R 1(X 1) W 1(Y 1) W 3(X 1) L 2 : R 3(Z 2) W 2(Z 2) W 1(Y 2) L 3 : W 3(X 3) W 2(Z 3) Question: Are these logs equivalent to some serial execution of the transactions? CS 5204 – Fall, 2008 13
Transactions Serialization of Distributed Logs Conflict: Pj(AX) and Qi(BY) conflict if (1) P and Q are not both READ, and (2) A = B (same data item), and (3) i j (different transactions), and (4) X = Y (same data manager/log) CS 5204 – Fall, 2008 14
Transactions Serialization of Distributed Logs Conflict: Pj(AX) and Qi(BY) conflict if (1) P and Q are not both READ, and (2) A = B, and (3) i j, and (4) X = Y LOGS: L 1 : R 2(Y 1) R 1(X 1) W 1(Y 1) W 3(X 1) L 2 : R 3(Z 2) W 2(Z 2) W 1(Y 2) L 3 : W 3(X 3) W 2(Z 3) CS 5204 – Fall, 2008 15
Transactions Serialization of Distributed Logs Conflict: Pj(AX) and Qi(BY) conflict if (1) P and Q are not both READ, and (2) A = B, and (3) i j, and (4) X = Y LOGS: 2 L 1 : R 2(Y 1) R 1(X 1) W 1(Y 1) W 3(X 1) L 2 : R 3(Z 2) W 2(Z 2) W 1(Y 2) 3 L 3 : W 3(X 3) W 2(Z 3) 1 CS 5204 – Fall, 2008 16
Transactions Serialization of Distributed Logs Conflict: Pj(AX) and Qi(BY) conflict if (1) P and Q are not both READ, and (2) A = B, and (3) i j, and (4) X = Y LOGS: 2 L 1 : R 2(Y 1) R 1(X 1) W 1(Y 1) W 3(X 1) L 2 : R 3(Z 2) W 2(Z 2) W 1(Y 2) 3 L 3 : W 3(X 3) W 2(Z 3) 1 CS 5204 – Fall, 2008 1 2 3 => T 1 T 3 => T 2 T 1 => T 3 T 2 Contradictory No total order Not serializable 17
Transactions Serialization of Distributed Logs Theorem: Distributed logs are serializable if there exists a total ordering of the transactions such that for conflicting operations Pj and Qi a log shows Pj Qi only if Tj Ti LOGS: 2 L 1 : R 2(Y 1) R 1(X 1) W 1(Y 1) W 3(X 1) L 2 : R 3(Z 2) W 2(Z 2) W 1(Y 2) 3 L 3 : W 3(X 3) W 2(Z 3) 1 CS 5204 – Fall, 2008 1 2 3 => T 1 T 3 => T 2 T 1 => T 3 T 2 Contradictory No total order Not serializable 18
Transactions Locking • transactions must use Two Phase Locking (2 PL) locking phase release phase Ti time no locks released no new locks requested • only the following lock requests are granted lock request READ WRITE current lock state not locked READ locked WRITE locked OK OK DENY CS 5204 – Fall, 2008 19
Transactions Locking Ti Ri(X) Wi(Y) lock(X) lock(Y) r ) Y , (X e s a e el concurrency controller • request lock before accessing a data item • release all locks at the end of transaction This guarantees serializability [ESWAREN] CS 5204 – Fall, 2008 20
Transactions Effects of Locking L 1 : R 2(Y 1) Suppose the transactions have executed to this point: L 2 : R 3(Z 2) L 3 : W 3(X 3) The locks are then: Lock for Lock state Waiting for lock X write-locked by T 3 T 1 Y read-locked by T 2 Z read-locked by T 3 T 2 Only T 3 is able to execute; it will complete its write and release its locks, leading to … CS 5204 – Fall, 2008 21
Transactions Effects of Locking L 1 : R 2(Y 1), W 3(X 1) …these logs, and… L 2 : R 3(Z 2) L 3 : W 3(X 3) …this lock state: Lock for Lock state Waiting for lock X unlocked T 1 Y read-locked by T 2 Z unlocked T 2 Both T 1 and T 2 can acquire the locks needed to execute their next actions, resulting in… CS 5204 – Fall, 2008 22
Transactions Effects of Locking L 1 : R 2(Y 1), W 3(X 1), R 1(X 1) …these logs, and… L 2 : R 3(Z 2), W 2(Z 2) L 3 : W 3(X 3), W 2(Z 3) …this lock state: Lock for Lock state X read-locked by T 1 Y read-locked by T 2 Z write-locked by T 2 Waiting for lock T 1 Transaction T 2 completes, releases its lock - resulting in… CS 5204 – Fall, 2008 23
Transactions Effects of Locking …this lock state: Lock for Lock state X read-locked by T 1 Y unlocked Z unlocked Waiting for lock T 1 At this point, T 1 can acquire the write-lock on Y, perform its write operations and complete, leading to the final serializable logs: L 1 : R 2(Y 1), W 3(X 1), R 1(X 1), W 1(Y 1) L 2 : R 3(Z 2), W 2(Z 2), W 1(Y 2) L 3 : W 3(X 3), W 2(Z 3) CS 5204 – Fall, 2008 24
- Slides: 24