Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction...

66
Transaction Theory 3. Transaction theory 6 Serializability Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1

Transcript of Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction...

Page 1: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory

3. Transaction theory

6 Serializability

7 View Serializability

8 Conflict Serializability

9 Conflict Graph

10 Closure Properties

11 Transaction Abort and Fault Tolerance

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1

Page 2: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory

3. Transaction theory

6 Serializability

7 View Serializability

8 Conflict Serializability

9 Conflict Graph

10 Closure Properties

11 Transaction Abort and Fault Tolerance

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1

Page 3: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory

3. Transaction theory

6 Serializability

7 View Serializability

8 Conflict Serializability

9 Conflict Graph

10 Closure Properties

11 Transaction Abort and Fault Tolerance

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1

Page 4: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory

3. Transaction theory

6 Serializability

7 View Serializability

8 Conflict Serializability

9 Conflict Graph

10 Closure Properties

11 Transaction Abort and Fault Tolerance

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1

Page 5: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory

3. Transaction theory

6 Serializability

7 View Serializability

8 Conflict Serializability

9 Conflict Graph

10 Closure Properties

11 Transaction Abort and Fault Tolerance

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1

Page 6: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory

3. Transaction theory

6 Serializability

7 View Serializability

8 Conflict Serializability

9 Conflict Graph

10 Closure Properties

11 Transaction Abort and Fault Tolerance

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1

Page 7: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Serializability

Introduction to the topicFormalization of schedulesSerializability conceptsComparison of serializability concepts

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–2

Page 8: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Introduction to Serializability

T1 : read(A); A := A− 10; write(A); read(B);

B := B + 10; write(B);

T2 : read(B); B := B − 20; write(B); read(C);

C := C + 20; write(C);

Execution alternatives for two transactions:I Serial, e.g. T1 before T2I Interleaved, e.g. alternating steps of T1 and T2

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–3

Page 9: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Interleaved execution: Example

Execution 1 Execution 2 Execution 3T1 T2 T1 T2 T1 T2

read(A) read(A) read(A)A− 10 read(B) A− 10write(A) A− 10 read(B)read(B) B − 20 write(A)B + 10 write(A) B − 20write(B) write(B) read(B)

read(B) read(B) write(B)B − 20 read(C) B + 10write(B) B + 10 read(C)read(C) C + 20 write(B)C + 20 write(B) C + 20write(C) write(C) write(C)

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–4

Page 10: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Results of different executions

A B C A + B + CInitial Value 10 10 10 30After execution 1 0 0 30 30After execution 2 0 0 30 30After execution 3 0 20 30 50

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–5

Page 11: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Simplified modelLock-Unlock-Model

T1 : lock A; unlock A; lock B; unlock B;

T2 : lock B; unlock B; lock C; unlock C;

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–6

Page 12: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Interleaved Executions with Lock/Unlock: Example

Execution 1 Execution 2 Illegal execution

T1 T2 T1 T2 T1 T2

lock A lock A lock Aunlock A lock B lock Block B unlock A unlock Aunlock B unlock B lock B

lock B lock B unlock Bunlock B lock C lock Cread C unlock B unlock Bunlock C unlock C unlock C

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–7

Page 13: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Serializability

An interleaved execution of a set of transactions is calledserializable, if the result of the interleaved execution is identical withthe result of a (randomly chosen) serial execution of the same set oftransactions transaction.

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–8

Page 14: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

The concept of schedules

Scheduler

u4 u3 u2 u1

v4 v3 v2 v1

w4 w3 w2 w1

... w2 v3 w1 u1 v2 v1

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–9

Page 15: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

The Read-Write Model

Transaction T is a finite sequence of operations (steps) pi of theform r(xk ) or w(xk ):

T = p1p2p3 · · · pn with pi ∈ {r(xk ),w(xk )}

A complete transaction T has as last step either an Abort a or aCommit c:

T = p1 · · · pna

orT = p1 · · · pnc.

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–10

Page 16: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Interleaved transactions

SHUFFLE(T ): set of all possible interleaved executions of thesteps of all transactions Ti in the set T

All steps of the transaction Ti are included only onceThe relative order of the steps of a transaction is preserved

T1 := r1(x)w1(x)T2 := r2(x)r2(y)w2(y)

SHUFFLE(T ) = {r1(x)w1(x)r2(x)r2(y)w2(y),r2(x)r1(x)w1(x)r2(y)w2(y),. . . }

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–11

Page 17: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Schedule

A complete schedule is a SHUFFLE-Element of a set of completetransactions.

A schedule is a prefix of a complete schedule.

r1(x)r2(x)w1(x)︸ ︷︷ ︸a schedule

r2(y)a1w2(y)c2

︸ ︷︷ ︸a complete schedule

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–12

Page 18: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Serial schedule

A serial schedule s for T is a complete schedule of the followingform:

s := Tρ(1) · · ·Tρ(n) for a permutation ρ of {1, . . . ,n}

Resulting serial schedules for two transactions:T1 := r1(x)w1(x)c1 and T2 := r2(x)w2(x)c2:

s1 := r1(x)w1(x)c1︸ ︷︷ ︸T1

r2(x)w2(x)c2︸ ︷︷ ︸T2

s2 := r2(x)w2(x)c2︸ ︷︷ ︸T2

r1(x)w1(x)c1︸ ︷︷ ︸T1

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–13

Page 19: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Serializability

Correctness criteria

A schedule s is correct, if its effect (the result of the execution of theschedule) is equivalent to the effect of a (randomly chosen) serialschedule s′ regarding the same set of transactions (s ≈ s′).

If a schedule s is equivalent to a serial schedule s′, then s isserializable (to s′).

Open: How to define "being equivalent"?

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–14

Page 20: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory View Serializability

View serializability

Idea: Effect of a transaction only depends on what values wereseen by the transaction.It reads the value that was written lastSpecial treatment necessary for the initialization and for the finalresult of a schedule

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–15

Page 21: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory View Serializability

View serializability: Preparations

Artificial additional transactions:1 Initial transaction T0: initially writes all involved objects2 Terminal transaction T∞: reads all involved objects in the end

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–16

Page 22: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory View Serializability

Reads-from-relation

If→s is the relation ”temporally before in the schedule s”, then”rj(x) reads x from Ti ” if and only if:

I wi(x)→s rj(x) andI 6 ∃k(wi(x)→s wk (x) ∧ wk (x)→s rj(x)).

Reads-from-relation RF (s) for a schedule s:RF (s) := { (Ti , x ,Tj) | rj(x) reads x from Ti}

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–17

Page 23: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory View Serializability

View equivalence

Two schedules s and s′ are view equivalent, if:1 op(s) = op(s′)

op(s): the set of all steps occurring in s including a and c (Setsmust be identical for both schedules)

2 RF (s) = RF (s′)Schedules s and s′ have the same ”Reads-from-relation”

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–18

Page 24: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory View Serializability

View equivalence: Example I

Given two complete schedules s1 and s2 consisting of twotransactions T1 and T2 with:

s1 := r1(x)r2(y)w1(y)w2(y)c1c2

s2 := r1(x)w1(y)r2(y)w2(y)c2c1

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–19

Page 25: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory View Serializability

View equivalence: Example II

For calculating the reads-from-relations RF (s1) and RF (s2), s1and s2 are expanded by the initial transaction T0 and the terminaltransaction T∞ in the following way:

s1 := w0(x)w0(y)c0︸ ︷︷ ︸T0

r1(x)r2(y)w1(y)w2(y)c1c2 r∞(x), r∞(y)c∞︸ ︷︷ ︸T∞

s2 := w0(x)w0(y)c0︸ ︷︷ ︸T0

r1(x)w1(y)r2(y)w2(y)c2c1 r∞(x), r∞(y)c∞︸ ︷︷ ︸T∞

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–20

Page 26: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory View Serializability

View equivalence: Example III

Resulting reads-from-relations:

RF (s1) := {(T0, x ,T1), (T0, y ,T2), (T0, x ,T∞), (T2, y ,T∞)}RF (s2) := {(T0, x ,T1), (T1, y ,T2), (T0, x ,T∞), (T2, y ,T∞)}

View equivalence of s1 and s2: Comparison ofreads-from-relationsSince RF (s1) 6= RF (s2), s1 and s2 are not view equivalent

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–21

Page 27: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory View Serializability

View Serializability

A schedule s is view serializable, only if s is view equivalent to aserial schedule.

Set of all view serializable schedules: VSR (view serializability)For n transactions, there exist n! serial schedulesProblems:

I Exponential complexity for testingI Testing requires complete schedules (blind writes and transaction

aborts)

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–22

Page 28: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory View Serializability

View Serializability: Example

Obviously, schedule s2 is view serializable, because s2 is serial.Possible serial schedules s′ and s′′ for s1:

I s′ = T1T2 = r1(x)w1(y)c1r2(y)w2(y)c2RF (s′) := {(T0, x ,T1), (T1, y ,T2), (T0, x ,T∞), (T2, y ,T∞)}→ RF (s′) 6= RF (s1)

I s′′ = T2T1 = r2(y)w2(y)c2r1(x)w1(y)c1RF (s′′) := {(T0, y ,T2), (T0, x ,T1), (T0, x ,T∞), (T1, y ,T∞)}→ RF (s′′) 6= RF (s1)

RF (s′) 6= RF (s1) and RF (s′′) 6= RF (s1): Schedule s1 is notserializable!

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–23

Page 29: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Conflict Serializability

Idea: Only the relative order of operations and not the actuallyread value is of importance in conflict situationsIt is not necessary to know which transaction has most recentlywritten a value, only whether the value has been written before orafter a transaction

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–24

Page 30: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

ConflictsT1 T2

read Aread A

order independent

T1 T2

read Awrite A

order dependent

T1 T2

write Aread A

order dependent

T1 T2

write Awrite A

order dependent

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–25

Page 31: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Conflict Serializability

Conflict relation C of s:C(s) := { (p,q) | p,q are in conflict and p →s q}

Conflict matrix:

ri (x) wi (x)rj (x)

√–

wj (x) – –

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–26

Page 32: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Adjusted conflict relation

conf(s) is an ”adjusted” conflict relation, which includes noaborted transactions

conf(s) := C(s)− { (p,q) | (p ∈ t ′ ∨ q ∈ t ′) ∧ t ′ ∈ aborted(s)}aborted(s): Set of aborted transactions in schedule s

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–27

Page 33: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Adjusted conflict relation: Example

Given schedule s:

s = r1(x)w1(x)r2(x)r3(y)w2(y)c2a1c3

Conflict relation for s:

C(s) := {(w1(x), r2(x)), (r3(y),w2(y))}

Removing aborted transaction T1 from s:

conf(s) := {(r3(y),w2(y))}

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–28

Page 34: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Conflict equivalence

Two schedules s and s′ are conflict equivalent (s ≈c s′) if:1 op(s) = op(s′)2 conf(s) = conf(s′)

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–29

Page 35: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Conflict serializability

A schedule s is conflict serializable, if and only if s is conflictequivalent to a serial schedule.

Class of all conflict serializable schedules: CSR (conflictserializability)

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–30

Page 36: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Conflict serializability: Example I

Given two schedules s and s′:s = r1(x)r1(y)w2(x)w1(y)r2(z)w1(x)w2(y)s′ = r1(y)r1(x)w1(y)w2(x)w1(x)r2(z)w2(y)

Question:Are schedules s and s′ conflict equivalent?Step 1:op(s) = op(s′) applies, since all database operations occurring ins occur in s′ as well; also applies vice versa

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–31

Page 37: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Conflict serializability: Example II

Step 2: Adjusted conflict relations

conf(s) = {(r1(x),w2(x)), (w2(x),w1(x)), (r1(y),w2(y)),(w1(y),w2(y))}

conf(s′) = {(r1(x),w2(x)), (w2(x),w1(x)), (r1(y),w2(y)),(w1(y),w2(y))}

I conf(s) = conf(s′) applies; so the conflict relations are equal andtherefore s and s′ are conflict equivalent

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–32

Page 38: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Conflict serializability: Example III

Test for conflict serializability by comparison with serial schedulesGiven schedule s:

s = r1(x)r1(y)w2(x)w1(y)r2(z)w1(x)w2(y)

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–33

Page 39: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Conflict serializability: Example IV

Adjusted conflict relation for s:

conf(s) = {(r1(x),w2(x)), (w2(x),w1(x)), (r1(y),w2(y)), (w1(y),w2(y))}

Possible serial schedule s1:

s1 = T1T2 = r1(x)r1(y)w1(y)w1(x)c1w2(x)r2(z)w2(y)c2

I Conflict relation of s1 is not equal to the conflict relation of s:

conf(s1) = {(r1(x),w2(x)), (w1(x),w2(x)),(r1(y),w2(y)), (w1(y),w2(y))}

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–34

Page 40: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Conflict serializability: Example V

Possible serial schedule s2 as a candidate:

s2 = T2T1 = w2(x)r2(z)w2(y)c2r1(x)r1(y)w1(y)w1(x)c1

I Conflict relation of s2 is not equal to the conflict relation of s:

conf(s2) = {(w2(x), r1(x)), (w2(y), r1(y)),(w2(y),w1(y)), (w2(x),w1(x))}

Therefore: s /∈ CSR, which means that schedule s is not conflictserializable

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–35

Page 41: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Conflict serializability: Example VI

Schedule:s3 = r1(x)r2(x)w2(y)c2w1(x)c1

is obviously conflict serializable, since only one conflict occurs

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–36

Page 42: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Graph-based Test

Conflict graph G(s) = (V ,E) for schedule s:1 Set of vertices V includes all transactions occurring in s2 Set of edges E includes all directed edges between two conflicting

transactions:(t , t ′) ∈ E ⇔ t 6= t ′ ∧ (∃p ∈ t)(∃q ∈ t ′) with (p,q) ∈ conf(s)

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–37

Page 43: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Serializability

Chronological sequence of three transactions

T1 T2 T3

r(y)r(u)

r(y)w(y)w(x)

w(x)w(z)

w(x)

s = r1(y)r3(u)r2(y)w1(y)w1(x)w2(x)w2(z)w3(x)

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–38

Page 44: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Graph

Conflict graph

T1

T3T2

G(s):

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–39

Page 45: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Graph

Properties of conflict graph G(s)

1 If s is a serial schedule, the given conflict graph is an acyclic graph2 For every acyclic graph G(s), a serial schedule s′ can be

constructed in order to make s conflict serializable to s′ (Test e.g.by topological sorting)

3 If a graph contains cycles, the respective schedule is not conflictserializable

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–40

Page 46: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Graph

Topological Sorting

(Recursive) iteration through the graph can detect the absence ofcycles

I Each node is visited onceI processing status per node and time stamp for entering and leaving

is notedI repeated reentry on arbitrary unprocessed nodes

Topological sorting can be done in the same runI Times of leaving provides the order

sorted sequence defines a conflict-equivalent serial schedulesee example of Saake/Sattler: Algorithmen und Datenstrukturen(the absent-minded professor ...)

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–41

Page 47: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Graph

Topological Sorting: Input

panties

shoes

socks

watch

trousers

belt

shirt

tie

jacket

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–42

Page 48: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Graph

Topological Sorting: Result

panties11/16

12/15

6/7

1/8

2/5

3/4

17/18

13/14

9/10

shoes

socks

watch

trousers

belt

shirt

tie

jacket

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–43

Page 49: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Graph

Topological Sorting: Alternative result

panties

shoes

socks

watch

trousers

belt

shirt

tie

jacket

17/18

9/12

6/7

2/3

15/16

10/11

13/14

1/4

5/8

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–44

Page 50: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Conflict Graph

Conflict Graphs and Serializability

For every schedule s applies:

G(s) acyclical⇔ s ∈ CSR

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–45

Page 51: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Closure Properties

Problems during run-time

Verification of serializability properties during run-timeI Only incomplete schedules available during run-time

Observation of incomplete schedules is necessaryI Transactions that have not performed a commit yet can still be

aborted anytime

How does this affect the accuracy of the verification?

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–46

Page 52: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Closure Properties

Closure Properties

1 Prefix ClosureIf property E applies to a schedule s, E also applies to any prefixof s. If E is fulfilled at the end of a schedule, E must not havebeen violated before.

2 Commit ClosureIf E applies to s, E also applies to CP(s) ("committed projection").If E applies to a set of transactions, it still applies if some of themare aborted.

3 Prefix-commit Closure (PCC)Prefix-commit closure is the conjunction.

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–47

Page 53: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Closure Properties

Closure Properties

VSR-Schedules are not prefix-commit closedI not prefix closed: blind writes can repairI not commit closed: last writes can be changed by Abort

CSR-Schedules are prefix-commit closedI prefix closed: cycles in the graph remain cyclesI commit closed: Aborts can not generate any cycles

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–48

Page 54: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Closure Properties

CSR vs VSR: Example IDoes CSR ⊂ VSR or VSR ⊂ CSR?

Given: schedule s:s = r1(y)r3(w) r2(y)w1(y)︸ ︷︷ ︸

T2→T1

w1(x)w2(x)︸ ︷︷ ︸T1→T2

w2(z)w3(x)c2c1c3

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–49

Page 55: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Closure Properties

CSR vs VSR: Example IISchedule s is not conflict serializable, since conflict graph G(s)contains a cycle.

T2

T3T1

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–50

Page 56: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Closure Properties

CSR vs VSR: Example IIIIs s view serializable?

Determining of the reads-from-relation RF

RF (s) = {(T0, y ,T1), (T0,w ,T3), (T0, y ,T2), (T3, x ,T∞),

(T1, y ,T∞), (T2, z,T∞), (T0,w ,T∞)}

Serial schedule s′ = T2 T1 T3:

s′ = r2(y)w2(x)w2(z)c2r1(y)w1(y)w1(x)c1r3(w)w3(x)c3

Reads-from-relation for schedule s′:

RF (s′) = {(T0, y ,T1), (T0,w ,T3), (T0, y ,T2), (T3, x ,T∞),

(T1, y ,T∞), (T2, z,T∞), (T0,w ,T∞)}

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–51

Page 57: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Closure Properties

CSR vs VSR: Example IV

RF (s) = RF (s′) applies, therefore, schedule s is view serializableTherefore: Conflict serializability is more restrictive than viewserializability

¬(CSR ⊃ VSR)

Generally:CSR ⊂ VSR

Cause: blind writes can repair violations caused by conflicts

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–52

Page 58: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Transaction Abort and Fault Tolerance

Fault ToleranceIn terms of fault tolerance, the following schedule s is not acceptable:

s = r1(x)w1(x)r2(x)a1w2(x)c2

. . . though it is serializable in VSR and CSR!

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–53

Page 59: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Transaction Abort and Fault Tolerance

Recoverability RC

s is recoverable, if the following condition is fulfilled:

(Ti reads from Tj in s) ∧ (ci ∈ s)⇒ (cj →s ci)

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–54

Page 60: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Transaction Abort and Fault Tolerance

Recoverability: Example

s1 = w1(x)w1(y)r2(u)w2(x)r2(y)w2(y)c2w1(z)c1

In s1, T2 reads data object y from T1 but c2 comes before c1 s1 isnot recoverable

s2 = w1(x)w1(y)r2(u)w2(x)r2(y)w2(y)w1(z)c1c2

s2 is recoverable

But: Problems when aborting T1 instead of c1 (dirty read)!

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–55

Page 61: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Transaction Abort and Fault Tolerance

Avoiding cascading aborts

Schedule s avoids cascading aborts ACA, if the followingcondition is fulfilled:

(Ti reads x from Tj in s )⇒ (cj →s ri(x))

A transaction may only read data that has last been written byan already committed transaction.

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–56

Page 62: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Transaction Abort and Fault Tolerance

Avoiding cascading aborts: Example

Schedule s2 from the last example does not belong into the classACAHowever, s3 avoids cascading aborts:

s3 = w1(x)w1(y)r2(u)w2(x)w1(z)c1r2(y)w2(y)c2

Therefore: s3 ∈ ACA

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–57

Page 63: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Transaction Abort and Fault Tolerance

Problems with Before-Images

DB Content Operationx = 1 (initial value)x = 2 w1(x← 2) [ BFx ,T1 = 1 ]x = 3 w2(x← 3) [ BFx ,T2 = 2 ]

a1 rollback of w1(x ← 2) with BFx := 1.Overwriting of T2 has to be maintained

x = 3a2 rollback of w2(x ← 3) with BFx := ??

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–58

Page 64: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Transaction Abort and Fault Tolerance

Strictness ST

Schedule s is strict, if the following applies:

(wj(x)→s pi(x) ∧ j 6= i)⇒(aj →s pi(x) ∨ cj →s pi(x), (p ∈ {r ,w}))

No ”written” object of an incomplete transaction may be read oroverwritten

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–59

Page 65: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Transaction Abort and Fault Tolerance

Strictness: Example

s3 /∈ STs4 is strict, therefore s4 ∈ ST:

s4 = w1(x)w1(y)r2(u)w1(z)c1w2(x)r2(y)w2(y)c2

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–60

Page 66: Transaction Theory 3. Transaction theoryProcessing/_/tp4.pdfThomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–1 Transaction Theory 3. Transaction theory

Transaction Theory Transaction Abort and Fault Tolerance

Relation between the concepts

RC

ST

VSR

CSR

serial

ACA

acceptable using cascading repair

often using strict locking protocols

Thomas Leich, Gunter Saake Transaction Processing Last updated: 18.10.2019 3–61