220 likes | 277 Views
CS4432: Database Systems II. Lecture #20 Concurrency Control – Chapter 18. Professor Elke A. Rundensteiner. Chapter 9 Concurrency Control. T1 T2 … Tn. DB (consistency constraints). Example:. T1: Read(A) T2: Read(A) A A+100 A A 2 Write(A) Write(A)
E N D
CS4432: Database Systems II Lecture #20 Concurrency Control – Chapter 18 Professor Elke A. Rundensteiner concurrency control
Chapter 9 Concurrency Control T1 T2 … Tn DB (consistency constraints) concurrency control
Example: T1: Read(A) T2: Read(A) A A+100 A A2 Write(A) Write(A) Read(B) Read(B) B B+100 B B2 Write(B) Write(B) Constraint: A=B concurrency control
A schedule An ordering of operations inside one or more transactions over time What is correct outcome ? concurrency control
A B 25 25 125 125 250 250 250 250 Schedule A T1 T2 Read(A); A A+100 Write(A); Read(B); B B+100; Write(B); Read(A);A A2; Write(A); Read(B);B B2; Write(B); concurrency control
A B 25 25 50 50 150 150 150 150 Schedule B T1 T2 Read(A);A A2; Write(A); Read(B);B B2; Write(B); Read(A); A A+100 Write(A); Read(B); B B+100; Write(B); concurrency control
Serial Schedules ! • Any serial schedule is “good”. concurrency control
Yet Interleave Transactionsina Schedule? concurrency control
A B 25 25 125 250 125 250 250 250 Schedule C T1 T2 Read(A); A A+100 Write(A); Read(A);A A2; Write(A); Read(B); B B+100; Write(B); Read(B);B B2; Write(B); concurrency control
A B 25 25 125 250 50 150 250 150 Schedule D T1 T2 Read(A); A A+100 Write(A); Read(A);A A2; Write(A); Read(B);B B2; Write(B); Read(B); B B+100; Write(B); concurrency control
A B 25 25 125 125 25 125 125 125 Same as Schedule D but with new T2’ Schedule E T1 T2’ Read(A); A A+100 Write(A); Read(A);A A1; Write(A); Read(B);B B1; Write(B); Read(B); B B+100; Write(B); concurrency control
What is a ‘good’ schedule? concurrency control
We want schedules that are “good” regardless of : • initial state and • transaction semantics • Hence we consider only : • order of read/writes Example: Sc=r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B) concurrency control
Remember Schedule C T1 T2 Read(A); A A+100 Write(A); Read(A);A A2; Write(A); Read(B); B B+100; Write(B); Read(B);B B2; Write(B); concurrency control
Example: Sc=r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B) Sc’=r1(A)w1(A) r1(B)w1(B)r2(A)w2(A)r2(B)w2(B) T1 T2 concurrency control
Now Let’s Try that for Schedule D !!! T1 T2 Read(A); A A+100 Write(A); Read(A);A A2; Write(A); Read(B);B B2; Write(B); Read(B); B B+100; Write(B); concurrency control
Now for Sd: Sd=r1(A)w1(A)r2(A)w2(A) r2(B)w2(B)r1(B)w1(B) Sd=r1(A)w1(A) r1(B)w1(B)r2(A)w2(A)r2(B)w2(B) concurrency control
Or, let’s try for Sd: Sd=r1(A)w1(A)r2(A)w2(A) r2(B)w2(B)r1(B)w1(B) Sd=r2(A)w2(A)r2(B)w2(B) r1(A)w1(A)r1(B)w1(B) concurrency control
In short, Schedule D cannot be “fixed” : Sd=r1(A)w1(A)r2(A)w2(A) r2(B)w2(B)r1(B)w1(B) Observation : there seems to be no save way to transform this schedule Sd into an equivalent serial schedule !?! concurrency control
We note about schedule D: • T2 T1 • T1 T2 T1 T2 Sd cannot be rearranged into a serial schedule Sd is not “equivalent” to any serial schedule Sd is “bad” concurrency control
Returning to Sc Sc=r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B) T1 T2 T1 T2 no cycles Sc is “equivalent” to a serial schedule, I.e., in this case (T1,T2). concurrency control
Idea: Swap non-conflicting operation pairs to see if you can go to a serial schedule. concurrency control