25
CS4432: Database Systems II Lecture #26 Concurrency Control and Recovery Professor Elke A. Rundensteiner

CS4432: Database Systems II

  • Upload
    mariko

  • View
    32

  • Download
    0

Embed Size (px)

DESCRIPTION

CS4432: Database Systems II. Lecture #26 Concurrency Control and Recovery. Professor Elke A. Rundensteiner. Concepts. Serial schedule : no interleaving of transactions S 1 , S 2 are conflict equivalent schedules if S 1 transforms into S 2 by swaps on non-conflicting actions. - PowerPoint PPT Presentation

Citation preview

Page 1: CS4432: Database Systems II

CS4432: Database Systems IILecture #26

Concurrency Control and Recovery

Professor Elke A. Rundensteiner

Page 2: CS4432: Database Systems II

Concepts

Serial schedule: no interleaving of transactions

S1, S2 are conflict equivalent schedules if S1

transforms into S2 by swaps on non-conflicting actions.

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

Page 3: CS4432: Database Systems II

Example: Tj Ti

Wj(A) ri(A) Commit Ti

Abort Tj

Concurrency control & recovery

……

……

Page 4: CS4432: Database Systems II

5

Example: Tj Ti

Wj(A) ri(A) Commit Ti

Abort Tj

Concurrency control & recovery

……

……

… Non-Persistent Commit (Bad!)

dirty data

Page 5: CS4432: Database Systems II

6

Example: Tj Ti

Wj(A) ri(A) Commit Ti

Abort Tj

Concurrency control & recovery

……

……

… Problem : Non-Persistent Commit

Can beavoided byrecoverableschedules

Page 6: CS4432: Database Systems II

7

Example: Tj Ti

Wj(A) ri(A) wi(B)

Abort Tj

[Commit Ti]

Concurrency control & recovery

……

……

…dirty data

Page 7: CS4432: Database Systems II

8

Example: Tj Ti

wj(A) ri(A) wi(B)

Abort Tj

[Commit Ti]

Concurrency control & recovery

……

……

… Cascading rollback

Page 8: CS4432: Database Systems II

9

Example: Tj Ti

Wj(A) ri(A) wi(B)

Abort Tj

[Commit Ti]

Concurrency control & recovery

……

……

… Cascading rollback

avoided byavoids-cascading-rollback (ACR)schedules

Page 9: CS4432: Database Systems II

10

Key Observation:

• Schedule is conflict serializable, Yet not “recoverable”.

Page 10: CS4432: Database Systems II

11

• Need to make “final’ decision for each transaction:

– commit decision - system guarantees transaction will or has completed, no matter what (final effect will stick)

– abort decision - system guarantees transaction will or has been rolled back

(has no effect)

Page 11: CS4432: Database Systems II

12

To model this, two new actions:

• Ci - transaction Ti commits• Ai - transaction Ti aborts

Page 12: CS4432: Database Systems II

13

...

...

...

...

Back to example: “dirty read”

Tj Ti

Wj(A)ri(A)

Ci can we commit

here?

Page 13: CS4432: Database Systems II

14

Definition

Ti reads from Tj in S (denoted as Tj STi) if

(1) wj(A) <S ri(A)

(2) aj <S ri(A) (< : does not precede)

(3) If wj(A) <S wk(A) <S ri(A) then

ak <S ri(A)

Page 14: CS4432: Database Systems II

Definition

Intuition : A schedule S is recoverable,

if transactions only commit after all transactions they read from have already been committed first.

Formal : Schedule S is recoverable if whenever Tj S Ti and j i and Ci S

then Cj <S Ci

Page 15: CS4432: Database Systems II

16

Note: in transactions, reads and writes precede commit or abort

If Ci Ti, then ri(A) < Ci

wi(A) < Ci

If Ai Ti, then ri(A) < Ai

wi(A) < Ai

• Another rule: – at most one Ci or Ai per transaction

Page 16: CS4432: Database Systems II

17

How to achieve recoverable schedules?

Page 17: CS4432: Database Systems II

18

With 2PL, hold write locks to commit (strict 2PL)

Tj Ti

Wj(A)

Cj

uj(A)ri(A)

...

...

...

...

...

...

...

Page 18: CS4432: Database Systems II

20

• S is recoverable if each transaction commits only after all transactions from which it read have committed.– Allows dirty read

• S avoids cascading rollback if each transaction may read only those values written by committed transactions.– Disallows dirty read

• S is strict if each transaction may read and write only items previously written by committed transactions.

Page 19: CS4432: Database Systems II

21

Types of schedules:

Avoids cascading rollback

RC

ACR

ST SERIAL

RC : recoverableACR: avoids cascading rollback ST: strict

Page 20: CS4432: Database Systems II

22

Examples

• Recoverable:– w1(A) w1(B) w2(A) r2(B) c1 c2

• Avoids Cascading Rollback:– w1(A) w1(B) w2(A) c1 r2(B) c2

• Strict:– w1(A) w1(B) c1 w2(A) r2(B) c2

Assumes w2(A) is donewithout reading

Page 21: CS4432: Database Systems II

23

Where are serializable schedules?

Avoids cascading rollback

RC

ACR

ST SERIAL

Page 22: CS4432: Database Systems II

Recoverable vs Serializable ?

• Every STRICT schedule is serializable.

• Every STRICT schedule is ACR (and thus recoverable).

Page 23: CS4432: Database Systems II

Recoverable vs Serializable ?

• Recoverable and serializable:– w1(A) w1(B) w2(A) r2(B) c1 c2

• Recoverable and not serializable:– w2(A) w1(B) w1(A) r2(B) c1 c2

• Not recoverable yet serializable:– w1(A) w1(B) w2(A) r2(B) c2 c1

• Not recoverable and not serializable:– w2(A) w1(B) w1(A) r2(B) c2 c1

Page 24: CS4432: Database Systems II

– 0. Start T1.– 1. L1(A)– 2. R1(A)– 3. W1(A)– 4. O1(A)– 5. Start T2.– 6. L2(C)– 7. L1(B)– 8. U1(A)– 9. L2(A)– 10. W1(B)– 11. Commit T1– 12. R2(A)– 13. W2(C)– 14. U1(B)– 15. Commit T2– 16. U2(A)– 17. U2(C)

Page 25: CS4432: Database Systems II

Basics of Concurrency Control and Recovery