1 / 20

ICS 214A: Database Management Systems Fall 2002

ICS 214A: Database Management Systems Fall 2002. Lecture 18: Redo/Undo Logging and Media Failure Professor Chen Li. Motivation. Undo logging: cannot bring backup DB copies up to date Redo logging: need to keep all modified blocks in memory until commit Solution: undo/redo logging

isabel
Download Presentation

ICS 214A: Database Management Systems Fall 2002

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ICS 214A: Database Management Systems Fall 2002 Lecture 18: Redo/Undo Logging and Media Failure Professor Chen Li

  2. Motivation • Undo logging: cannot bring backup DB copies up to date • Redo logging: need to keep all modified blocks in memory until commit • Solution: undo/redo logging Update  <Ti, X, v, w> v = old value, w = new value Notes 18

  3. Undo/redo logging • Suppose transaction T changes DB element X from v (old value) to w (new values) • Update record <T, X, v, w> • Rule: • Before modifying any db element X (vw) on disk changed by xact T, write the update log record <T,X,v,w> on disk • <T COMMIT> can precede or follow any db-element change on disk Notes 18

  4. <T1, start> <T1, A, 8, 16> 16 16 16 16 Example T1: Read (A,t); t  t2 A=B Write (A,t); Read (B,t); t  t2 Write (B,t); Output (A); Output (B); A:8 B:8 A:8 B:8 <T1, B, 8, 16> <T1, commit> disk memory log Notice: <T1,COMMIT> log record can be before or after the two output operations Notes 18

  5. Undo/redo Recovery • Redo all the committed xacts in the order earliest-first (backwards) • Undo all the incomplete xacts in the order latest-first (forwards) Notes 18

  6. <T1, start> <T1, A, 8, 16> 16 16 16 16 Example 1 T1: Read (A,t); t  t2 A=B Write (A,t); Read (B,t); t  t2 Write (B,t); Output (A); Output (B); failure! A:8 B:8 A:8 B:8 <T1, B, 8, 16> <T1, commit> disk memory log Recovery: T1 is committed. Redo: write 16 to both A and B on disk. Notes 18

  7. <T1, start> <T1, A, 8, 16> 16 16 16 Example 2 T1: Read (A,t); t  t2 A=B Write (A,t); Read (B,t); t  t2 Write (B,t); Output (A); Output (B); failure! A:8 B:8 A:8 B:8 <T1, B, 8, 16> <T1, commit> disk memory log Recovery: same as before. Notes 18

  8. <T1, start> <T1, A, 8, 16> 16 16 16 Example 3 T1: Read (A,t); t  t2 A=B Write (A,t); Read (B,t); t  t2 Write (B,t); Output (A); Output (B); failure! A:8 B:8 A:8 B:8 <T1, B, 8, 16> disk memory log Recovery: T1 incomplete. Undo: previous values (8) of A and B are written to disk. Notes 18

  9. <T1, start> <T1, A, 8, 16> 16 16 Example 4 T1: Read (A,t); t  t2 A=B Write (A,t); Read (B,t); t  t2 Write (B,t); Output (A); Output (B); failure! A:8 B:8 A:8 B:8 <T1, B, 8, 16> disk memory log Recovery: same as before. Notes 18

  10. Example 5 failure! T1: Read (A,t); t  t2 A=B Write (A,t); Read (B,t); t  t2 Write (B,t); Output (A); Output (B); <T1, start> A:8 B:8 A:8 B:8 16 disk memory log Recovery: T1 incomplete. Do nothing. Notes 18

  11. Nonquiescent checkpoint: flexible • Write (and flush) <START CKPT(T1,…,Tk)> log record, where T1,…,Tk are active xacts • Write do disk all buffers that are dirty, I.e., they contain one or more changed DB elements. Flush all buffers. (In redo logging, we only flush those buffers written by committed xacts.) • Write and flush <END CKPT> log record Notes 18

  12. Example Redo/Undo Log: <T1, START> <T1, A, 4,5> <T2, START> <T1, COMMIT> <T2, B, 9, 10> <START CKPT(T2)>  Start checkpoint. T2 active <T2, C, 14, 15>  continue, accept new xacts, <T3, START> make sure B=10 by T2 is on disk, <T3, D, 19, 20> and A = 5 by T1 is on disk. <END CKPT>  end checkpoint <T2, COMMIT>  continue <T3, COMMIT> Notes 18

  13. Recovery: example 1 • T2 and T3 already committed. • Since we see <END CKPT> first (backward), T1’s changes must be on disk. So T1 can be ignored. • Redo T2 and T3, forward. • Do NOT need to look at the log records before <START CKPT> • Reason: their changes are already on disk Redo/Undo Log: <T1, START> <T1, A, 4,5> <T2, START> <T1, COMMIT> <T2, B, 9, 10> <START CKPT(T2)> <T2, C, 14, 15> <T3, START> <T3, D, 19, 20> <END CKPT> <T2, COMMIT> <T3, COMMIT> Notes 18

  14. Recovery: example 2 • T2 committed. • T3 incomplete • Redo T2 (forward): C = 15 (on disk) • Undo T3 (backward): D = 19 (on disk) Redo/Undo Log: <T1, START> <T1, A, 4,5> <T2, START> <T1, COMMIT> <T2, B, 9, 10> <START CKPT(T2)> <T2, C, 14, 15> <T3, START> <T3, D, 19, 20> <END CKPT> <T2, COMMIT> Notes 18

  15. Recovery: example 3 • See <START CKPT(T2)> first (backward) • T2 active and incomplete. • Undo (backward): C= 14 and B = 9 (on disk) • T3 incomplete • Undo (backward): D = 19 (on disk) • T1 complete • Redo (forward): A = 5 (on disk) Redo/Undo Log: <T1, START> <T1, A, 4, 5> <T2, START> <T1, COMMIT> <T2, B, 9, 10> <START CKPT(T2)> <T2, C, 14, 15> <T3, START> <T3, D, 19, 20> Notes 18

  16. Media failure (loss of non-volatile storage) A: 16 Solution: Make copies of data! Notes 18

  17. Example 1Triple modular redundancy • Keep 3 copies on separate disks • Output(X) --> three outputs • Input(X) --> three inputs + vote X3 X1 X2 Notes 18

  18. Example #2 Redundant writes, Single reads • Keep N copies on separate disks • Output(X) --> N outputs • Input(X) --> Input one copy - if ok, done - else try another one  Assumes bad data can be detected Notes 18

  19. Example #3: DB Dump + Log backup database active database log • If active database is lost, • restore active database from backup • bring up-to-date using redo entries in log Notes 18

  20. Summary • Consistency of data • One source of problems: failures - Logging - Redundancy • Another source of problems:Data Sharing..... ICS214B Notes 18

More Related