Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner.

Similar presentations


Presentation on theme: "Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner."— Presentation transcript:

1 cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner

2 cs4432concurrency control2 Chapter 9Concurrency Control T1T2…Tn DB (consistency constraints)

3 cs4432concurrency control3 Concepts Transaction: sequence of r i (x), w i (x) actions Conflicting actions: read/write on same resource A. Schedule: represents chronological order in which actions are executed Serial schedule: no interleaving of trans/actions S 1, S 2 are conflict equivalent schedules if S 1 transform into S 2 by swaps on non-conflicting actions. A schedule is conflict serializable if it is conflict equivalent to some serial schedule.

4 cs4432concurrency control4 For a given schedule: Sd=r 1 (A)w 1 (A)r 2 (A)w 2 (A) r 2 (B)w 2 (B)r 1 (B)w 1 (B) T 1  T 2 T 2  T 1 T 1 T 2 If graph has cycles, Then schedule is not conflict serializable. Record dependencies in Precedence Graph:

5 cs4432concurrency control5 Theorem P(S 1 ) acyclic  S 1 conflict serializable

6 cs4432concurrency control6 How to enforce serializable schedules?

7 cs4432concurrency control7 How to enforce serializable schedules? Option 1: try all possible swaps of non- conflicting operation pairs to determine if the schedule can be turned into a serial one, I.e., if the schedule is ‘good’.

8 cs4432concurrency control8 How to enforce serializable schedules? Option 2: run system, recording P(S); at end of day, check for P(S) cycles and declare if execution was good

9 cs4432concurrency control9 Option 3: prevent P(S) cycles from occurring T 1 T 2 …..T n Scheduler DB How to enforce serializable schedules?

10 cs4432concurrency control10 A locking protocol Two new actions: lock (exclusive):l i (A) unlock:u i (A) scheduler T 1 T 2 lock table

11 cs4432concurrency control11 Rule #1: Well-formed transactions T i : … l i (A) … p i (A) … u i (A)...

12 cs4432concurrency control12 Rule #2 Legal scheduler S = …….. l i (A) ………... u i (A) ……... no l j (A)

13 cs4432concurrency control13 What schedules are legal? What transactions are well-formed? S1 = l 1 (A)l 1 (B)r 1 (A)w 1 (B)l 2 (B)u 1 (A)u 1 (B) r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B) S2 = l 1 (A)r 1 (A)w 1 (B)u 1 (A)u 1 (B) l 2 (B)r 2 (B)w 2 (B)l 3 (B)r 3 (B)u 3 (B) S3 = l 1 (A)r 1 (A)u 1 (A)l 1 (B)w 1 (B)u 1 (B) l 2 (B)r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B) Exercise:

14 cs4432concurrency control14 What schedules are legal? What transactions are well-formed? S1 = l 1 (A)l 1 (B)r 1 (A)w 1 (B)l 2 (B)u 1 (A)u 1 (B) r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B) S2 = l 1 (A)r 1 (A)w 1 (B)u 1 (A)u 1 (B) l 2 (B)r 2 (B)w 2 (B)l 3 (B)r 3 (B)u 3 (B) S3 = l 1 (A)r 1 (A)u 1 (A)l 1 (B)w 1 (B)u 1 (B) l 2 (B)r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B) Exercise:

15 cs4432concurrency control15 Schedule F : Adding locking ??? T1 T2 l 1 (A);Read(A) A A+100;Write(A);u 1 (A) l 2 (A);Read(A) A Ax2;Write(A);u 2 (A) l 2 (B);Read(B) B Bx2;Write(B);u 2 (B) l 1 (B);Read(B) B B+100;Write(B);u 1 (B)

16 cs4432concurrency control16 Schedule F T1 T l 1 (A);Read(A) A A+100;Write(A);u 1 (A) 125 l 2 (A);Read(A) A Ax2;Write(A);u 2 (A) 250 l 2 (B);Read(B) B Bx2;Write(B);u 2 (B) 50 l 1 (B);Read(B) B B+100;Write(B);u 1 (B) A B

17 cs4432concurrency control17 Rule #3 Two phase locking (2PL) for transactions T i = ……. l i (A) ………... u i (A) ……... no unlocks no locks

18 cs4432concurrency control18 # locks held by Ti Time Growing Shrinking Phase Phase

19 cs4432concurrency control19 Schedule F : Does it follow 2PL ? T1 T2 l 1 (A);Read(A) A A+100;Write(A);u 1 (A) l 2 (A);Read(A) A Ax2;Write(A);u 2 (A) l 2 (B);Read(B) B Bx2;Write(B);u 2 (B) l 1 (B);Read(B) B B+100;Write(B);u 1 (B)

20 cs4432concurrency control20 Schedule G T1 T2 l 1 (A);Read(A) A A+100;Write(A) l 1 (B); u 1 (A) l 2 (A);Read(A) A Ax2;Write(A);

21 cs4432concurrency control21 Schedule G delayed

22 cs4432concurrency control22 Schedule G delayed

23 cs4432concurrency control23 Schedule G delayed

24 cs4432concurrency control24 We Got the GOOD Schedule !!!! T1T2 Read(A); A  A+100 Write(A); Read(A);A  A  2; Write(A); Read(B); B  B+100; Write(B); Read(B);B  B  2; Write(B); AB

25 cs4432concurrency control25 Schedule H (T 2 reversed) T1T2 l 1 (A); Read(A) l 2 (B);Read(B) A A+100;Write(A) B Bx2;Write(B) …

26 cs4432concurrency control26 Schedule H (T 2 reversed) delayed

27 cs4432concurrency control27 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!

28 cs4432concurrency control28 We need to show 2PL Protocol “works”: Show that rules #1,2,3  conflict- serializable schedules

29 cs4432concurrency control29 Conflict rules for l i (A), u i (A): l i (A), l j (A) conflict l i (A), u j (A) conflict

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

31 cs4432concurrency control31 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) … By rule 3: SH(Ti) SH(Tj) So, SH(Ti) < S SH(Tj)

32 cs4432concurrency control32 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

33 cs4432concurrency control33 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


Download ppt "Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner."

Similar presentations


Ads by Google