23
cs4432 concurrency control 1 CS4432: Database Systems II Lecture #21 Concurrency Control : Theory Professor Elke A. Rundensteiner

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

Embed Size (px)

Citation preview

cs4432 concurrency control 1

CS4432: Database Systems IILecture #21

Concurrency Control : Theory

Professor Elke A. Rundensteiner

cs4432 concurrency control 2

Concepts

Transaction: sequence of ri(x), wi(x) actionsConflicting actions: read/write on same resource A:

r1(A) w2(A) w1(A)

w2(A) r1(A) w2(A)

Schedule: represents chronological order in which actions are executed

Serial schedule: no interleaving of trans/actions

cs4432 concurrency control 3

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

cs4432 concurrency control 4

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

2(B)

cs4432 concurrency control 5

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

cs4432 concurrency control 6

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

cs4432 concurrency control 7

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

cs4432 concurrency control 8

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

cs4432 concurrency control 9

In short, Schedule D cannot be “fixed” :Sd=r1(A)w1(A)r2(A)w2(A)

r2(B)w2(B)r1(B)w1(B)

• as a matter of fact, there seems to

be no save way to transform this Sd

into an equivalent serial schedule !?

cs4432 concurrency control 10

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

cs4432 concurrency control 11

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

schedule.

cs4432 concurrency control 12

Definition

S1, S2 are conflict equivalent schedulesif S1 can be transformed into S2 by a series of swaps of non-conflicting actions.

cs4432 concurrency control 13

Definition

A schedule is conflict serializable if it is conflict equivalent to some serial schedule.

cs4432 concurrency control 14

Answer: A Precedence Graph !

How determine this ?

cs4432 concurrency control 15

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)

cs4432 concurrency control 16

Exercise:

• What is P(S) forS = w3(A) w2(C) r1(A) w1(B) r1(C) w2(A) r4(A) w4(D)

• Is S conflict-serializable?

cs4432 concurrency control 17

Another Exercise:

• What is P(S) forS = w1(A) r2(A) r3(A) w4(A) ?

• Is S conflict-serializable?

cs4432 concurrency control 18

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

cs4432 concurrency control 19

Note: P(S1)=P(S2) S1, S2 conflict equivalent?

cs4432 concurrency control 20

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)

cs4432 concurrency control 21

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

cs4432 concurrency control 22

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

Theorem

P(S1) acyclic S1 conflict serializable

cs4432 concurrency control 23

Theorem holds:

P(S1) acyclic S1 conflict serializable