cs4432: database systems ii
DESCRIPTION
CS4432: Database Systems II. Lecture #22 Concurrency Control. Professor Elke A. Rundensteiner. Chapter 9 Concurrency Control. T1T2…Tn. DB (consistency constraints). Concepts. Transaction: sequence of r i (x), w i (x) actions Conflicting actions: - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/1.jpg)
cs4432 concurrency control 1
CS4432: Database Systems IILecture #22
Concurrency Control
Professor Elke A. Rundensteiner
![Page 2: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/2.jpg)
cs4432 concurrency control 2
Chapter 9 Concurrency Control
T1 T2 … Tn
DB(consistencyconstraints)
![Page 3: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/3.jpg)
cs4432 concurrency control 3
Concepts
Transaction: sequence of ri(x), wi(x) actions
Conflicting actions: r1(A) w2(A) w1(A)
w2(A) r1(A) w2(A)
Schedule: represents chronological orderin which actions are executed
Serial schedule: no interleaving of actions or transactions
![Page 4: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/4.jpg)
cs4432 concurrency control 4
A ReCap
• Examples of Main Concepts are given next.
![Page 5: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/5.jpg)
cs4432 concurrency control 5
Example:
T1: Read(A) T2: Read(A)A A+100 A A2Write(A) Write(A)Read(B) Read(B)B B+100 B B2Write(B) Write(B)
Constraint: A=B
![Page 6: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/6.jpg)
cs4432 concurrency control 6
Schedule C
T1 T2Read(A); A A+100Write(A);
Read(A);A A2;
Write(A);Read(B); B B+100;Write(B);
Read(B);B B2;
Write(B);
A B25 25
125
250
125
250250 250
![Page 7: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/7.jpg)
cs4432 concurrency control 7
Sc’=r1(A)w1(A) r1(B)w1(B)r2(A)w2(A)r2(B)w2(B)
T1 T2
Example: Sc=r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)
![Page 8: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/8.jpg)
cs4432 concurrency control 8
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 aserial schedule,I.e., in this case (T1,T2).
![Page 9: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/9.jpg)
cs4432 concurrency control 9
Schedule D
T1 T2Read(A); A A+100Write(A);
Read(A);A A2;
Write(A);
Read(B);B B2;
Write(B);Read(B); B B+100;Write(B);
A B25 25
125
250
50
150250 150
![Page 10: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/10.jpg)
cs4432 concurrency control 10
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)T1 T2
![Page 11: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/11.jpg)
cs4432 concurrency control 11
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) T1T2
![Page 12: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/12.jpg)
cs4432 concurrency control 12
For Schedule D:Sd=r1(A)w1(A)r2(A)w2(A)
r2(B)w2(B)r1(B)w1(B)
• there seems to be no save way to transform this S-D into an equivalent serial schedule?
![Page 13: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/13.jpg)
cs4432 concurrency control 13
For Schedule D:Sd=r1(A)w1(A)r2(A)w2(A)
r2(B)w2(B)r1(B)w1(B)
T1 T2 T2 T1
T1 T2
Sd cannot be rearranged into serial schedule
![Page 14: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/14.jpg)
cs4432 concurrency control 14
Definition
S1, S2 are conflict equivalent schedulesif S1 can be transformed into S2 by a series of swaps on non-conflicting actions.
![Page 15: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/15.jpg)
cs4432 concurrency control 15
Definition
A schedule is conflict serializable if it is conflict equivalent to some serial schedule.
![Page 16: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/16.jpg)
cs4432 concurrency control 16
Answer: A Precedence Graph !
How determine this ?
![Page 17: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/17.jpg)
cs4432 concurrency control 17
Nodes: transactions in SArcs: Ti Tj whenever
- pi(A), qj(A) are actions in S- pi(A) <S qj(A)
- at least one of pi, qj is a write
Precedence graph P(S) (S is
schedule)
![Page 18: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/18.jpg)
cs4432 concurrency control 18
Exercise:
• What is P(S) forS = w3(A) w2(C) r1(A) w1(B) r1(C) w2(A) r4(A) w4(D)
• Is S serializable?
![Page 19: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/19.jpg)
cs4432 concurrency control 19
Another Exercise:
• What is P(S) forS = w1(A) r2(A) r3(A) w4(A) ?
• Is S serializable?
![Page 20: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/20.jpg)
cs4432 concurrency control 20
Lemma
S1, S2 conflict equivalent P(S1)=P(S2)
Proof:Assume P(S1) P(S2) Ti: Ti Tj in S1 and not in S2
S1 = …pi(A)... qj(A)… pi, qj
S2 = …qj(A)…pi(A)... conflict
S1, S2 not conflict equivalent
![Page 21: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/21.jpg)
cs4432 concurrency control 21
Note: P(S1)=P(S2) S1, S2 conflict equivalent
Counter example:
S1=w1(A) r2(A) w2(B) r1(B) S2=r2(A) w1(A) r1(B) w2(B)
![Page 22: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/22.jpg)
cs4432 concurrency control 22
Theorem
P(S1) acyclic S1 conflict serializable
() Assume S1 is conflict serializable Ss: Ss, S1 conflict equivalent P(Ss) = P(S1)
P(S1) acyclic since P(Ss) is acyclic
![Page 23: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/23.jpg)
cs4432 concurrency control 23
() Assume P(S1) is acyclicTransform S1 as follows:(1) Take T1 to be transaction with no incident arcs(2) Move all T1 actions to the front
S1 = ……. qj(A)…….p1(A)…..
(3) we now have S1 = < T1 actions ><... rest ...>(4) repeat above steps to serialize rest!
T1
T2 T3
T4
TheoremP(S1) acyclic S1 conflict serializable
![Page 24: CS4432: Database Systems II](https://reader035.vdocument.in/reader035/viewer/2022062520/56815a95550346895dc8146e/html5/thumbnails/24.jpg)
cs4432 concurrency control 24
How to enforce serializable schedules?
Next Time …