Presentation is loading. Please wait.

Presentation is loading. Please wait.

Optimistic Concurrency Control Lecture 13. 2-Phase Locking Recap Phases – Growth – acquire all locks – Shrinking – release locks as done Strict 2PL –

Similar presentations


Presentation on theme: "Optimistic Concurrency Control Lecture 13. 2-Phase Locking Recap Phases – Growth – acquire all locks – Shrinking – release locks as done Strict 2PL –"— Presentation transcript:

1 Optimistic Concurrency Control Lecture 13

2 2-Phase Locking Recap Phases – Growth – acquire all locks – Shrinking – release locks as done Strict 2PL – Don’t release write locks until end of xaction Rigorous – Release no locks until end

3 Phantom Problem Updating ranges of records is slow in 2PL Some actions may break atomicity – E.g., T1 reads, then T2 writes and T2 commits first Address with predicate locks on B+ Trees

4 Study Break: Phantom Reads Are the following xactions possibly subject to the phantom problem? T1 SELECT * FROM accounts WHERE name=‘Jane’; SELECT avg(bal) FROM accounts WHERE name=‘Jane’; T2 UPDATE set bal=bal+10 FROM accounts WHERE name like ‘k%’; T1 SELECT AVG(salary) INTO AVG FROM emp WHERE dept=‘eecs’; SELECT name FROM emp WHERE salary > avg AND dept = ’eecs’; T2 INSERT INTO emp(id,name,dept,salary) VALUES (1, ’joe’, ’eecs’, 50k);

5 OCC Runtime twrite(n,i,v): if n not in write_set // never written, make copy m = copy(n); copies[n] = m; write_set = write_set union {n}; write(copies[n], i, v))) tread(n,i): read_set = read_set union {n}; if n in write_set return read(copies[n],i); else return read(n,i);

6 Validation Rules When Tj completes its read phase, require that for all Ti < Tj, one of the following conditions must be true for validation to succeed (Tj to commit): 1)Ti completes its write phase before Tj starts its read phase 2)W(Ti) does not intersect R(Tj), and Ti completes its write phase before Tj starts its write phase. 3)W(Ti) does not intersect R(Tj) or W(Tj), and Ti completes its read phase before Tj completes its read phase. 4)W(Ti) does not intersect R(Tj) or W(Tj), and W(Tj) does not intersect R(Ti) [no conflicts] These rules will ensure serializability, with Tj being ordered after Ti with respect to conflicts

7 Condition 1 Ti completes its write phase before Tj starts its read phase Don't overlap at all. ReadValidate Write Ti ReadValidate Write Tj Time

8 Condition 2 W(Ti) does not intersect R(Tj), and Ti completes its write phase before Tj starts its write phase. Tj doesn’t read anything Ti wrote. Anything Tj wrote that Ti also wrote will be installed afterwards. Anything Ti read will not reflect Tjs writes ReadValidate Write Ti ReadValidate Write Tj Time W(Ti) ∩ R(Tj) = { }R(Ti) ∩ W(Tj) ≠ { } W(Ti) ∩ W(Tj) ≠ { }

9 Condition 3 W(Ti) does not intersect R(Tj) or W(Tj), and Ti completes its read phase before Tj completes its read phase. Tj doesn’t read or write anything Ti wrote (but Ti may read something Tj writes). Ti definitely won’t see any of Tj’s writes, because it finishes reading before Tj starts validation, so Ti ordered before Tj. Ti will always complete its read phase before Tj b/c timestamps assigned after read phase ReadValidate Write Ti ReadValidate Write Tj Time W(Ti) ∩ R(Tj) = { }R(Ti) ∩ W(Tj) ≠ { } W(Ti) ∩ W(Tj) = { }

10 Study Break: Optimistic Concurrency What xaction(s) succeed? ReadValidate Write Ti ReadValidate Write Tj ReadValidate Write Tk R(Ti) = d W(Ti) = a, b, c R(Tj) = d W(Tj) = b, c R(Tk) = d W(Tk) = d


Download ppt "Optimistic Concurrency Control Lecture 13. 2-Phase Locking Recap Phases – Growth – acquire all locks – Shrinking – release locks as done Strict 2PL –"

Similar presentations


Ads by Google