SlideServe
Menu
Préférences
© SlideServe · v2026

ICS 214B: Transaction Processing and Distributed Data Management

vala avatar
30 diapositives · 471 Views · Aug 14, 2014

ICS 214B: Transaction Processing and Distributed Data Management. Lecture 2: Enforcing Serializable Schedules Professor Chen Li. How to enforce serializable schedules?. Option 1: run system, recording P(S); at end of day, check for P(S) cycles and declare if execution was good.

ICS 214B: Transaction Processing and Distributed Data Management - slide 1
01 / 30ICS 214B: Transaction Processing and Distributed Data Management
1 / 17

Télécharger la présentation

ICS 214B: Transaction Processing and Distributed Data Management
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. ICS 214B: Transaction Processing and Distributed Data Management Lecture 2: Enforcing Serializable Schedules Professor Chen Li

  2. How to enforce serializable schedules? Option 1: run system, recording P(S); at end of day, check for P(S) cycles and declare if execution was good Notes 02

  3. How to enforce serializable schedules? Option 2: prevent P(S) cycles from occurring T1 T2 ….. Tn Scheduler DB Notes 02

  4. A locking protocol Two new actions: lock (exclusive): li (A) unlock: ui (A) T1 T2 lock table scheduler Notes 02

  5. Rule #1: Well-formed transactions Ti: … li(A) … pi(A) … ui(A) ... 1) Lock an element before accessing it 2) Unlock the element after accessing it Notes 02

  6. Rule #2 Legal scheduler S = …….. li(A) ………... ui(A) ……... Once an element A is locked by one transaction Ti, the schedule will not grant any other lock requests on A no lj(A) Notes 02

  7. Exercise • What schedules are legal?What transactions are well-formed? S1 = l1(A)l1(B)r1(A)w1(B)l2(B)u1(A)u1(B) r2(B)w2(B)u2(B)l3(B)r3(B)u3(B) S2 = l1(A)r1(A)w1(B)u1(A)u1(B) l2(B)r2(B)w2(B)l3(B)r3(B)u3(B) S3 = l1(A)r1(A)u1(A)l1(B)w1(B)u1(B) l2(B)r2(B)w2(B)u2(B)l3(B)r3(B)u3(B) Notes 02

  8. Another problem: schedule F is still allowed, but it’s bad! A B T1 T2 25 25 l1(A);Read(A) A A+100;Write(A);u1(A) 125 l2(A);Read(A) A Ax2;Write(A);u2(A) 250 l2(B);Read(B) B Bx2;Write(B);u2(B) 50 l1(B);Read(B) B B+100;Write(B);u1(B) 150 250 150 Notes 02

  9. no unlocks no locks Rule #3 Two phase locking (2PL) Ti = ……. li(A) ………... ui(A) ……... A transaction once releases a lock, it cannot request more locks. Notes 02

  10. # locks held by Ti Time Growing Shrinking Phase Phase Notes 02

  11. Schedule G T1 T2 l1(A);Read(A) A A+100;Write(A) l1(B); u1(A) l2(A);Read(A) A Ax2;Write(A);l2(B) request delayed Notes 02

  12. Schedule G T1 T2 l1(A);Read(A) A A+100;Write(A) l1(B); u1(A) l2(A);Read(A) A Ax2;Write(A);l2(B) Read(B);B B+100 Write(B); u1(B) request delayed Notes 02

  13. Schedule G T1 T2 l1(A);Read(A) A A+100;Write(A) l1(B); u1(A) l2(A);Read(A) A Ax2;Write(A);l2(B) Read(B);B B+100 Write(B); u1(B) l2(B); u2(A);Read(B) B Bx2;Write(B);u2(B); request delayed Notes 02

  14. Schedule H (T2 reversed) T1 T2 l1(A); Read(A) l2(B);Read(B) A A+100;Write(A) B Bx2;Write(B) l1(B) l2(A) Deadlock! delayed delayed Notes 02

  15. Solution • Assume deadlocked transactions are rolled back • They have no effect • They do not appear in schedule Notes 02

  16. Next step: Show that rules #1,2,3  conflict- serializable schedules Notes 02

  17. New Conflict rules for li(A), ui(A): • Check the semantics of the operations, e.g., • li(A), uj(A) conflict • li(A), ri(A) conflict; li(A), wi(A) conflict • ri(A), ui(A) conflict; wi(A), ui(A) conflict • Some actions can never become adjacent after legal swaps • <ui(A), uj(A)>, <li(A), rj(A)>,... Example: l1(A)r1(A)l1(B)u1(A)l2(A)w2(A)w1(B)u2(A)u1(B) Notes 02

  18. Theorem Rules #1,2,3  conflict (2PL) serializable schedule To help in proof: Definition Shrink(Ti) = SH(Ti) = first unlock action of Ti Notes 02

  19. By rule 3: SH(Ti) SH(Tj) So, SH(Ti) <S SH(Tj) Proof of lemma: Ti  Tj means that S = … pi(A) … qj(A) …; p,q conflict By rules 1,2: ui(A) <S lj(A) S = … pi(A) … ui(A) … lj(A) ... qj(A) … Lemma Ti  Tj in S  SH(Ti) <S SH(Tj) Notes 02

  20. Theorem Rules #1,2,3  conflict (2PL) serializable schedule Proof: (1) Assume P(S) has cycle T1 T2 …. Tn T1 (2) By lemma: SH(T1) <SH(T2) < ... <SH(T1) (3) Impossible, so P(S) acyclic (4)  S is conflict serializable Notes 02

  21. Beyond this simple 2PL protocol, it is all a matter of improving performance and allowing more concurrency…. • Shared locks • Multiple granularity • Inserts, deletes, and phantoms • Other types of concurrency control mechanisms Notes 02

  22. Shared locks S = ...l1(A) r1(A) u1(A) … l2(A) r2(A) u2(A) … read only, noconflict Use “shared” lock: S=... ls1(A) r1(A) ls2(A) r2(A) …. us1(A) us2(A) Notes 02

  23. Lock actions l-ti(A): lock A in t mode (t is S or X) u-ti(A): unlock t mode (t is S or X) “S” = “Shared”, “X” = “Exclusive” Shorthand: ui(A): unlock whatever modes Ti has locked A Notes 02

  24. Rule #1 Well formed transactions Ti =... l-S1(A) … r1(A) …u1 (A) … Ti =... l-X1(A) … w1(A) …u1 (A) … Lock an element before accessing it Release the lock afterwards Notes 02

  25. What about transactions that read and write same object? Option 1: Request exclusive lock Ti = ...l-X1(A) … r1(A) ... w1(A) ... u(A) … Notes 02

  26. Option 2: Upgrade (E.g., need to read, but don’t know if will write…) Ti=... l-S1(A) … r1(A) ...l-X1(A) …w1(A) ...u(A)… Think of - Get 2nd lock on A, or - Drop S, get X lock Notes 02

  27. Rule #2 Legal scheduler S = ....l-Si(A) … … ui(A) … l-Sj(A) OK, but no l-Xj(A) S = ... l-Xi(A) … … ui(A) … no l-Xj(A) no l-Sj(A) Notes 02

  28. A way to summarize Rule #2 Compatibility matrix: “comp” S X S true false X false false Notes 02

  29. Rule # 3 2PL transactions No change: • Locking must precede unlocking, i.e., • No action sli(X) or xli(X) can be preceded by ui(X) Notes 02

  30. Theorem Rules 1,2,3  Conf.serializable for S/X locks schedules Notes 02