CS4432: Database Systems II

22
cs4432 concurrency control 1 CS4432: Database Systems II Lecture #20 Concurrency Control – Chapter 18 Professor Elke A. Rundensteiner

description

CS4432: Database Systems II. Lecture #20 Concurrency Control – Chapter 18. Professor Elke A. Rundensteiner. Chapter 9 Concurrency Control. T1T2…Tn. DB (consistency constraints). Example:. T1:Read(A)T2:Read(A) A  A+100A  A  2 Write(A)Write(A) - PowerPoint PPT Presentation

Transcript of CS4432: Database Systems II

Page 1: CS4432: Database Systems II

cs4432 concurrency control 1

CS4432: Database Systems IILecture #20

Concurrency Control – Chapter 18

Professor Elke A. Rundensteiner

Page 2: CS4432: Database Systems II

cs4432 concurrency control 2

Chapter 9 Concurrency Control

T1 T2 … Tn

DB(consistencyconstraints)

Page 3: CS4432: Database Systems II

cs4432 concurrency control 3

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 4: CS4432: Database Systems II

cs4432 concurrency control 4

A schedule

An ordering of operations inside one or more transactions over

time

What is correct outcome ?

Page 5: CS4432: Database Systems II

cs4432 concurrency control 5

Schedule A

T1 T2Read(A); A A+100Write(A);Read(B); B B+100;Write(B);

Read(A);A A2;

Write(A);

Read(B);B B2;

Write(B);

A B25 25

125

125

250

250250 250

Page 6: CS4432: Database Systems II

cs4432 concurrency control 6

Schedule B

T1 T2

Read(A);A A2;

Write(A);

Read(B);B B2;

Write(B);Read(A); A A+100Write(A);Read(B); B B+100;Write(B);

A B25 25

50

50

150

150150 150

Page 7: CS4432: Database Systems II

cs4432 concurrency control 7

Serial Schedules !

• Any serial schedule is “good”.

Page 8: CS4432: Database Systems II

cs4432 concurrency control 8

Yet Interleave Transactions

ina Schedule?

Page 9: CS4432: Database Systems II

cs4432 concurrency control 9

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 10: CS4432: Database Systems II

cs4432 concurrency control 10

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 11: CS4432: Database Systems II

cs4432 concurrency control 11

Schedule E

T1 T2’Read(A); A A+100Write(A);

Read(A);A A1;

Write(A);

Read(B);B B1;

Write(B);Read(B); B B+100;Write(B);

A B25 25

125

125

25

125125 125

Same as Schedule Dbut with new T2’

Page 12: CS4432: Database Systems II

cs4432 concurrency control 12

What is a ‘good’ schedule?

Page 13: CS4432: Database Systems II

cs4432 concurrency control 13

• 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)

Page 14: CS4432: Database Systems II

cs4432 concurrency control 14

Remember 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);

Page 15: CS4432: Database Systems II

cs4432 concurrency control 15

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 16: CS4432: Database Systems II

cs4432 concurrency control 16

Now Let’s Try that for 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);

Page 17: CS4432: Database Systems II

cs4432 concurrency control 17

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)

Page 18: CS4432: Database Systems II

cs4432 concurrency control 18

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)

Page 19: CS4432: Database Systems II

cs4432 concurrency control 19

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 !?!

Page 20: CS4432: Database Systems II

cs4432 concurrency control 20

Sd cannot be rearrangedinto a serial

scheduleSd is not “equivalent” to

any serial scheduleSd is “bad”

We note about schedule D:• T2 T1

• T1 T2 T1 T2

Page 21: CS4432: Database Systems II

cs4432 concurrency control 21

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 22: CS4432: Database Systems II

cs4432 concurrency control 22

Idea: Swap non-conflicting operation pairs to see if you can go to a serial

schedule.