database recovery
play

Database Recovery Lecture # 21 Database Systems Andy Pavlo AP AP - PowerPoint PPT Presentation

Database Recovery Lecture # 21 Database Systems Andy Pavlo AP AP Computer Science 15-445/15-645 Carnegie Mellon Univ. Fall 2018 2 CRASH RECOVERY Recovery algorithms are techniques to ensure database consistency, transaction atomicity,


  1. Database Recovery Lecture # 21 Database Systems Andy Pavlo AP AP Computer Science 15-445/15-645 Carnegie Mellon Univ. Fall 2018

  2. 2 CRASH RECOVERY Recovery algorithms are techniques to ensure database consistency, transaction atomicity, and durability despite failures. Recovery algorithms have two parts: → Actions during normal txn processing to ensure that the DBMS can recover from a failure. → Actions after a failure to recover the database to a state Today that ensures atomicity, consistency, and durability. CMU 15-445/645 (Fall 2018)

  3. 3 ARIES A lgorithms for R ecovery and I solation E xploiting S emantics Developed at IBM Research in early 1990s. Not all systems implement ARIES exactly as defined in this paper but they're close. CMU 15-445/645 (Fall 2018)

  4. 5 ARIES M AIN IDEAS Write-Ahead Logging: → Any change is recorded in log on stable storage before the database change is written to disk. → Has to be STEAL + NO-FORCE . Repeating History During Redo: → On restart, retrace actions and restore database to exact state before crash. Logging Changes During Undo: → Record undo actions to log to ensure action is not repeated in the event of repeated failures. CMU 15-445/645 (Fall 2018)

  5. 6 Log Sequence Numbers Normal Commit & Abort Operations Fuzzy Checkpointing Recovery Algorithm CMU 15-445/645 (Fall 2018)

  6. 7 WAL RECO RDS We need to extend our log record format from last class to include additional info. Every log record now includes a globally unique log sequence number (LSN). Various components in the system keep track of LSNs that pertain to them… CMU 15-445/645 (Fall 2018)

  7. 8 LO G SEQ UEN CE N UM BERS Name Where Definition Memory Last LSN in log on disk flushedLSN page x Newest update to page x pageLSN Oldest update to page x page x recLSN since it was last flushed T i Latest action of txn T i lastLSN Disk LSN of latest checkpoint MasterRecord CMU 15-445/645 (Fall 2018)

  8. 9 WRITIN G LO G RECO RDS Each data page contains a pageLSN . → The LSN of the most recent update to that page. System keeps track of flushedLSN . → The max LSN flushed so far. Before page x can be written to disk, we must flush log at least to the point where: → pageLSN x ≤ flushedLSN CMU 15-445/645 (Fall 2018)

  9. 10 WRITIN G LO G RECO RDS Log Sequence Numbers Log Sequence Numbers WAL WAL (Tail) 001 :<T 1 BEGIN > 002 :<T 1 , A, 1, 2> 017 :<T 5 BEGIN > 003 :<T 1 COMMIT > 004 :<T 2 BEGIN > 018 :<T 5 , A, 9, 8> 005 :<T 2 , A, 2, 3> 006 :<T 3 BEGIN > 019 :<T 5 , B, 5, 1> 007 :< CHECKPOINT > 008 :<T 2 COMMIT > 020 :<T 5 COMMIT > 009 :<T 3 , A, 3, 4> 010 :<T 4 BEGIN > ⋮ 011 :<T 4 , X, 5, 6> 012 :<T 4 , Y, 9, 7> 013 :<T 3 , B, 4, 2> 014 :<T 3 COMMIT > 015 :<T 4 , B, 2, 3> 016 :<T 4 , C, 1, 2> Buffer Pool pageLSN recLSN pageLSN recLSN A=9 B=5 C=2 A=9 B=5 C=2 MasterRecord flushedLSN Database CMU 15-445/645 (Fall 2018)

  10. 10 WRITIN G LO G RECO RDS WAL WAL (Tail) 001 :<T 1 BEGIN > 002 :<T 1 , A, 1, 2> 017 :<T 5 BEGIN > 003 :<T 1 COMMIT > 004 :<T 2 BEGIN > 018 :<T 5 , A, 9, 8> 005 :<T 2 , A, 2, 3> 006 :<T 3 BEGIN > 019 :<T 5 , B, 5, 1> 007 :< CHECKPOINT > 008 :<T 2 COMMIT > 020 :<T 5 COMMIT > 009 :<T 3 , A, 3, 4> 010 :<T 4 BEGIN > ⋮ 011 :<T 4 , X, 5, 6> 012 :<T 4 , Y, 9, 7> 013 :<T 3 , B, 4, 2> 014 :<T 3 COMMIT > 015 :<T 4 , B, 2, 3> 016 :<T 4 , C, 1, 2> Buffer Pool pageLSN recLSN pageLSN recLSN A=9 B=5 C=2 A=9 B=5 C=2 MasterRecord flushedLSN Database CMU 15-445/645 (Fall 2018)

  11. 10 WRITIN G LO G RECO RDS WAL WAL (Tail) 001 :<T 1 BEGIN > 002 :<T 1 , A, 1, 2> 017 :<T 5 BEGIN > 003 :<T 1 COMMIT > 004 :<T 2 BEGIN > 018 :<T 5 , A, 9, 8> 005 :<T 2 , A, 2, 3> 006 :<T 3 BEGIN > 019 :<T 5 , B, 5, 1> 007 :< CHECKPOINT > 008 :<T 2 COMMIT > 020 :<T 5 COMMIT > 009 :<T 3 , A, 3, 4> 010 :<T 4 BEGIN > ⋮ 011 :<T 4 , X, 5, 6> 012 :<T 4 , Y, 9, 7> 013 :<T 3 , B, 4, 2> 014 :<T 3 COMMIT > 015 :<T 4 , B, 2, 3> 016 :<T 4 , C, 1, 2> Buffer Pool pageLSN recLSN pageLSN recLSN A=9 B=5 C=2 A=9 B=5 C=2 MasterRecord flushedLSN Database CMU 15-445/645 (Fall 2018)

  12. 10 WRITIN G LO G RECO RDS WAL WAL (Tail) 001 :<T 1 BEGIN > 002 :<T 1 , A, 1, 2> 017 :<T 5 BEGIN > 003 :<T 1 COMMIT > 004 :<T 2 BEGIN > 018 :<T 5 , A, 9, 8> 005 :<T 2 , A, 2, 3> 006 :<T 3 BEGIN > 019 :<T 5 , B, 5, 1> 007 :< CHECKPOINT > 008 :<T 2 COMMIT > 020 :<T 5 COMMIT > 009 :<T 3 , A, 3, 4> 010 :<T 4 BEGIN > ⋮ 011 :<T 4 , X, 5, 6> 012 :<T 4 , Y, 9, 7> 013 :<T 3 , B, 4, 2> 014 :<T 3 COMMIT > 015 :<T 4 , B, 2, 3> 016 :<T 4 , C, 1, 2> Buffer Pool pageLSN recLSN pageLSN recLSN A=9 B=5 C=2 A=9 B=5 C=2 MasterRecord flushedLSN Database CMU 15-445/645 (Fall 2018)

  13. 10 WRITIN G LO G RECO RDS WAL WAL (Tail) 001 :<T 1 BEGIN > 002 :<T 1 , A, 1, 2> 017 :<T 5 BEGIN > 003 :<T 1 COMMIT > 004 :<T 2 BEGIN > 018 :<T 5 , A, 9, 8> 005 :<T 2 , A, 2, 3> 006 :<T 3 BEGIN > 019 :<T 5 , B, 5, 1> 007 :< CHECKPOINT > 008 :<T 2 COMMIT > 020 :<T 5 COMMIT > 009 :<T 3 , A, 3, 4> 010 :<T 4 BEGIN > ⋮ 011 :<T 4 , X, 5, 6> 012 :<T 4 , Y, 9, 7> 013 :<T 3 , B, 4, 2> 014 :<T 3 COMMIT > 015 :<T 4 , B, 2, 3> 016 :<T 4 , C, 1, 2> Buffer Pool pageLSN recLSN pageLSN recLSN A=9 B=5 C=2 A=9 B=5 C=2 MasterRecord flushedLSN Database CMU 15-445/645 (Fall 2018)

  14. 10 WRITIN G LO G RECO RDS WAL ? WAL (Tail) 001 :<T 1 BEGIN > 002 :<T 1 , A, 1, 2> 017 :<T 5 BEGIN > 003 :<T 1 COMMIT > 004 :<T 2 BEGIN > 018 :<T 5 , A, 9, 8> 005 :<T 2 , A, 2, 3> 006 :<T 3 BEGIN > 019 :<T 5 , B, 5, 1> 007 :< CHECKPOINT > 008 :<T 2 COMMIT > 020 :<T 5 COMMIT > 009 :<T 3 , A, 3, 4> 010 :<T 4 BEGIN > ⋮ 011 :<T 4 , X, 5, 6> 012 :<T 4 , Y, 9, 7> 013 :<T 3 , B, 4, 2> 014 :<T 3 COMMIT > 015 :<T 4 , B, 2, 3> 016 :<T 4 , C, 1, 2> Buffer Pool pageLSN recLSN pageLSN recLSN A=9 B=5 C=2 A=9 B=5 C=2 Safe to unpin because MasterRecord pageLSN ≤ flushedLSN flushedLSN Database CMU 15-445/645 (Fall 2018)

  15. 10 WRITIN G LO G RECO RDS WAL WAL (Tail) 001 :<T 1 BEGIN > 002 :<T 1 , A, 1, 2> 017 :<T 5 BEGIN > 003 :<T 1 COMMIT > 004 :<T 2 BEGIN > 018 :<T 5 , A, 9, 8> 005 :<T 2 , A, 2, 3> 006 :<T 3 BEGIN > 019 :<T 5 , B, 5, 1> 007 :< CHECKPOINT > 008 :<T 2 COMMIT > 020 :<T 5 COMMIT > 009 :<T 3 , A, 3, 4> 010 :<T 4 BEGIN > ⋮ 011 :<T 4 , X, 5, 6> 012 :<T 4 , Y, 9, 7> ? 013 :<T 3 , B, 4, 2> 014 :<T 3 COMMIT > 015 :<T 4 , B, 2, 3> 016 :<T 4 , C, 1, 2> Buffer Pool pageLSN recLSN pageLSN recLSN A=9 B=5 C=2 A=9 B=5 C=2 Not safe to unpin because MasterRecord pageLSN > flushedLSN flushedLSN Database CMU 15-445/645 (Fall 2018)

  16. 11 WRITIN G LO G RECO RDS All log records have an LSN . Update the pageLSN every time a txn modifies a record in the page. Update the flushedLSN in memory every time the DBMS writes out the WAL buffer to disk. CMU 15-445/645 (Fall 2018)

  17. 12 N O RM AL EXECUTIO N Each txn invokes a sequence of reads and writes, followed by commit or abort. Assumptions in this lecture: → All log records fit within a single page. → Disk writes are atomic. → Single-versioned tuples with Strict 2PL. → STEAL + NO-FORCE buffer management with WAL. CMU 15-445/645 (Fall 2018)

  18. 13 TRAN SACTIO N CO M M IT Write COMMIT record to log. All log records up to txn’s COMMIT record are flushed to disk. → Note that log flushes are sequential, synchronous writes to disk. → Many log records per log page. When the commit succeeds, write a special TXN- END record to log. → This does not need to be flushed immediately. CMU 15-445/645 (Fall 2018)

  19. 14 TRAN SACTIO N CO M M IT WAL WAL (Tail) 001 :<T 1 BEGIN > 002 :<T 1 , A, 1, 2> 012 :<T 4 BEGIN > 003 :<T 1 COMMIT > 004 :<T 2 BEGIN > 013 :<T 4 , A, 9, 8> 005 :<T 2 , A, 2, 3> 006 :<T 3 BEGIN > 014 :<T 4 , B, 5, 1> 007 :< CHECKPOINT > 008 :<T 2 COMMIT > 015 :<T 4 COMMIT > 009 :<T 3 , A, 3, 4> 010 :<T 3 , B, 4, 2> 011 :<T 3 , COMMIT > 012 :<T 4 BEGIN > 013 :<T 4 , A, 9, 8> 014 :<T 4 , B, 5, 1> 015 :<T 4 COMMIT > Buffer Pool pageLSN recLSN pageLSN recLSN A=9 B=5 C=2 A=9 B=5 C=2 MasterRecord flushedLSN Database flushedLSN = 015 CMU 15-445/645 (Fall 2018)

Recommend


More recommend