Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.

Similar presentations


Presentation on theme: "CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner."— Presentation transcript:

1 CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner

2 CS4432transaction management2 # locks held by Ti Time Growing Shrinking Phase Phase 2 Phase Locking Protocol

3 CS4432transaction management3 Now : Show that rules #1,2,3  conflict- serializable schedules

4 CS4432transaction management4 Conflict rules for l i (A), u i (A): l i (A), l j (A) conflict l i (A), u j (A) conflict

5 CS4432transaction management5 Theorem Rules #1,2,3  conflict (2PL) serializable schedule To help in proof: Definition Shrink(Ti) = SH(Ti) = first unlock action of Ti

6 CS4432transaction management6 Lemma Ti  Tj in S  SH(Ti) < S SH(Tj) Proof of lemma: Ti  Tj means that S = … p i (A) … q j (A) …; p,q conflict By rules 1,2: S = … p i (A) … u i (A) … l j (A)... q j (A) … SH(Ti) SH(Tj) By rule 3: So, SH(Ti) < S SH(Tj)

7 CS4432transaction management7 Proof: (1) Assume P(S) has cycle T 1  T 2  …. T n  T 1 (2) By lemma: SH(T 1 ) < SH(T 2 ) <... < SH(T 1 ) (3) Impossible, so P(S) acyclic (4)  S is conflict serializable Theorem Rules #1,2,3  conflict (2PL) serializable schedule

8 CS4432transaction management8 Beyond this simple 2PL protocol, it is all a matter of improving performance and allowing more concurrency…. –Shared locks –Multiple granularity –Other types of C.C. mechanisms

9 CS4432transaction management9 Chapter 10 More on transaction processing Topics: Cascading rollback Recoverable schedule Deadlocks –Prevention –Detection

10 CS4432transaction management10 Schedule H (T 2 reversed) delayed

11 CS4432transaction management11 Assume deadlocked transactions are rolled back –They have no effect –They do not appear in schedule E.g., Schedule H = This space intentionally left blank!

12 CS4432transaction management12 Example:T i T o W i (A) r j (A) Commit T o Abort T i Concurrency control & recovery … … … … … …  Cascading rollback (Bad!)

13 CS4432transaction management13 Schedule is conflict serializable T i T o But not recoverable

14 CS4432transaction management14 Need to make “final’ decision for each transaction: –commit decision - system guarantees transaction will or has completed, no matter what –abort decision - system guarantees transaction will or has been rolled back (has no effect)

15 CS4432transaction management15 To model this, two new actions: C i - transaction T i commits A i - transaction T i aborts

16 CS4432transaction management16... Back to example: T i T j W i (A) r j (A) C j  can we commit here?

17 CS4432transaction management17 Definition T i read from T j in S (T j  S T j ) if (1) w j (A) < S r i (A) (2) a j < S r i (A) (< : does not precede ) (3) If w j (A) < S w k (A) < S r i (A) then a k < S r i (A)

18 CS4432transaction management18 Definition Schedule S is recoverable if whenever T j  S T i and j  i and C i  S then C j < S C i

19 CS4432transaction management19 Note: in transactions, reads and writes precede commit or abort  If C i  T i, then r i (A) < C i w i (A) < C i  If A i  T i, then r i (A) < A i w i (A) < A i

20 CS4432transaction management20 How to achieve recoverable schedules?

21 CS4432transaction management21  With 2PL, hold write locks to commit (strict 2PL) T i T j W i (A) Ci u i (A) r j (A)...

22 CS4432transaction management22 S is recoverable if each transaction commits only after all transactions from which it read have committed. S avoids cascading rollback if each transaction may read only those values written by committed transactions.

23 CS4432transaction management23 S is strict if each transaction may read and write only items previously written by committed transactions. Avoids cascading rollback RC ACA ST SERIAL

24 CS4432transaction management24

25 CS4432transaction management25 Schedule with Deadlock delayed

26 CS4432transaction management26 Deadlocks Detection –Wait-for graph Prevention –Resource ordering –Timeout –Wait-die –Wound-wait

27 CS4432transaction management27 Deadlock Detection Build Wait-For graph Use lock table structures Build incrementally or periodically When cycle found, rollback victim T1T1 T3T3 T2T2 T6T6 T5T5 T4T4 T7T7

28 CS4432transaction management28 Resource Ordering Order all elements A 1, A 2, …, A n A transaction T can lock A i after A j only if i > j Problem : Ordered lock requests not realistic in most cases

29 CS4432transaction management29 Timeout If transaction waits more than L sec., roll it back! Simple scheme Hard to select L

30 CS4432transaction management30 Wait-die Transactions given a timestamp when they arrive …. ts(T i ) T i can only wait for T j if ts(T i )< ts(T j )...else die

31 CS4432transaction management31 T 1 (ts =10) T 2 (ts =20) T 3 (ts =25) wait Example: wait?

32 CS4432transaction management32 Wound-wait Transactions given a timestamp when they arrive … ts(T i ) T i wounds T j if ts(T i )< ts(T j ) else T i waits “Wound”: T j rolls back and gives lock to T i

33 CS4432transaction management33 Summary Cascading rollback Recoverable schedule Deadlock –Prevention –Detection


Download ppt "CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner."

Similar presentations


Ads by Google