Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CS4432: Database Systems II Lecture #26 Concurrency Control and Recovery Professor Elke A. Rundensteiner."— Presentation transcript:

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

2 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. A schedule is conflict serializable if it is conflict equivalent to some serial schedule.

3 Theorem P(S 1 ) acyclic  S 1 conflict serializable

4 Example: T j T i W j (A) r i (A) Commit T i Abort T j Concurrency control & recovery … … … … … …

5 5 Example: T j T i W j (A) r i (A) Commit T i Abort T j Concurrency control & recovery … … … … … …  Non-Persistent Commit (Bad!) dirty data

6 6 Example: T j T i W j (A) r i (A) Commit T i Abort T j Concurrency control & recovery … … … … … …  Problem : Non-Persistent Commit Can be avoided by recoverable schedules

7 7 Example: T j T i W j (A) r i (A) w i (B) Abort T j [ Commit T i] Concurrency control & recovery … … … … … … dirty data

8 8 Example: T j T i w j (A) r i (A) w i (B) Abort T j [ Commit T i] Concurrency control & recovery … … … … … …  Cascading rollback

9 9 Example: T j T i W j (A) r i (A) w i (B) Abort T j [ Commit T i] Concurrency control & recovery … … … … … …  Cascading rollback avoided by avoids-cascading- rollback (ACR) schedules

10 10 Key Observation: Schedule is conflict serializable, Yet not “recoverable”.

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

12 12 To model this, two new actions: C i - transaction T i commits A i - transaction T i aborts

13 13... Back to example: “dirty read” T j T i W j (A) r i (A) C i  can we commit here?

14 14 Definition T i reads from T j in S (denoted as T j  S T i ) if (1) w j (A) < S r i (A) (2) a j < S r i (A) (< : does not precede ) (3) If w j (A) < S w k (A) < S r i (A) then a k < S r i (A)

15 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

16 16 Note: in transactions, reads and writes precede commit or abort  If C i  T i, then r i (A) < C i w i (A) < C i  If A i  T i, then r i (A) < A i w i (A) < A i Another rule: –at most one Ci or Ai per transaction

17 17 How to achieve recoverable schedules?

18 18 With 2PL, hold write locks to commit (strict 2PL) T j T i W j (A) C j u j (A) r i (A)...

19 19 S is recoverable if each transaction commits only after all transactions from which it read have committed. S avoids cascading rollback if each transaction may read only those values written by committed transactions. S is strict if each transaction may read and write only items previously written by committed transactions.

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

21 21 Types of schedules: Avoids cascading rollback RC ACR ST SERIAL RC : recoverable ACR: avoids cascading rollback ST: strict

22 22 Examples Recoverable: –w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 1 c 2 Avoids Cascading Rollback: –w 1 (A) w 1 (B) w 2 (A) c 1 r 2 (B) c 2 Strict: –w 1 (A) w 1 (B) c 1 w 2 (A) r 2 (B) c 2 Assumes w 2 (A) is done without reading

23 23 Where are serializable schedules? Avoids cascading rollback RC ACR ST SERIAL

24 Recoverable vs Serializable ? Recoverable and serializable: –w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 1 c 2 Recoverable and not serializable: –w 2 (A) w 1 (B) w 1 (A) r 2 (B) c 1 c 2 Not recoverable yet serializable: –w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 2 c 1

25 Recoverable vs Serializable ? Every STRICT schedule is serializable. Every STRICT schedule is ACR (and thus recoverable).

26 Recoverable vs Serializable ? Recoverable and serializable: –w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 1 c 2 Recoverable and not serializable: –w 2 (A) w 1 (B) w 1 (A) r 2 (B) c 1 c 2 Not recoverable yet serializable: –w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 2 c 1

27 Recoverable vs Serializable ? Recoverable and serializable: –w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 1 c 2 Recoverable and not serializable: –w 2 (A) w 1 (B) w 1 (A) r 2 (B) c 1 c 2 Not recoverable yet serializable: –w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 2 c 1 Every STRICT schedule is serializable. Every STRICT schedule is ACR (and thus recoverable).

28 Recoverable vs Serializable ? Recoverable and serializable: –w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 1 c 2 Recoverable and not serializable: –w 2 (A) w 1 (B) w 1 (A) r 2 (B) c 1 c 2 Not recoverable yet serializable: –w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 2 c 1 Not recoverable and not serializable: –w 2 (A) w 1 (B) w 1 (A) r 2 (B) c 2 c 1

29 –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)

30 Basics of Concurrency Control and Recovery


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

Similar presentations


Ads by Google