Cs4432recovery1 CS4432: Database Systems II Lecture #20 Failure Recovery Professor Elke A. Rundensteiner.
Published byModified over 4 years ago
Presentation on theme: "Cs4432recovery1 CS4432: Database Systems II Lecture #20 Failure Recovery Professor Elke A. Rundensteiner."— Presentation transcript:
cs4432recovery1 CS4432: Database Systems II Lecture #20 Failure Recovery Professor Elke A. Rundensteiner
cs4432recovery2 Transaction: a collection of actions that preserve consistency Consistent DBConsistent DB’ T
cs4432recovery3 Big assumption: If T starts with consistent state AND T executes in isolation T leaves consistent state
cs4432recovery4 Our failure model processor memory disk CPU M D
cs4432recovery5 Operations re Storage Hierarchy: Input (x): block containing x memory Output (x): block containing x disk Read (x,t): do input(x) if necessary t value of x in block Write (x,t): do input(x) if necessary value of x in block t Memory Disk x x
cs4432recovery6 Key problem : Unfinished transaction Example:Constraint: A=B T 1 : A A 2 B B 2
cs4432recovery7 T 1 :Read (A,t); t t 2 Write (A,t); Read (B,t); t t 2 Write (B,t); Output-to-Disk (A); Output-to-Disk (B); A: 8 B: 8 A: 8 B: 8 memory disk 16 failure!
cs4432recovery8 Need atomicity: execute all actions of a transaction or none at all
cs4432recovery9 One solution: undo logging (immediate modification) A la Hansel and Gretel recording their navigation through forest via bread crumbs … Must have durable undo logging !!!
cs4432recovery10 T 1 :Read (A,t); t t 2 A=B Write (A,t); Read (B,t); t t 2 Write (B,t); Output-to-disk (A); Output-to-disk (B); A:8 B:8 A:8 B:8 memory disk log Undo logging (Immediate modification) 16 16 16
cs4432recovery11 One “complication” Log is first written in memory Not written to disk on every action memory DB Log A: 8 16 B: 8 16 Log: A: 8 B: 8 16 BAD STATE # 1
cs4432recovery12 One “complication” Log is first written in memory Not written to disk on every action memory DB Log A: 8 16 B: 8 16 Log: A: 8 B: 8 16 BAD STATE # 2...
cs4432recovery13 Undo logging rules (1)For every action generate undo log record (containing old value) (2) Before x is modified on disk, log records pertaining to x must be on disk (write ahead logging) (3) Before commit is written to log on disk, all writes of transaction must be reflected on disk
cs4432recovery14 Recovery rules: Undo logging For every Ti with in log: - If or in log, do nothing - Else For all in log: write (X, v) output (X ) Write to log IS THIS CORRECT??
cs4432recovery15 Recovery rules: Undo logging (1) Let S = set of transactions with in log, but no (or ) record in log (2) For each in log, in reverse order (latest earliest) do: - write old value from log back to disk: - if Ti S then - write (X, v) - output (X) (3) For each Ti S do - write to log
cs4432recovery16 What if failure during recovery? No problem! Undo idempotent
cs4432recovery17 To discuss next : Redo logging Undo/redo logging, why both? Checkpoints
cs4432recovery18 Redo logging (deferred modification) T 1: Read(A,t); t t 2; write (A,t); Read(B,t); t t 2; write (B,t); Output(A); Output(B) A: 8 B: 8 A: 8 B: 8 memory DB LOG 16 output 16
cs4432recovery19 Redo logging rules (1) For every action, generate redo log record (containing new value) (2) Before X is modified on disk (DB), all log records for transaction that modified X (including commit) must be on disk (3) Flush log at commit
cs4432recovery20 Idea: Need to redo if transaction commit is in log because we don’t know if transaction failed or not. For every Ti with in log: –For all in log: Write(X, v) Output(X) Recovery rules: Redo logging IS THIS CORRECT??
cs4432recovery21 (1) Let S = set of transactions with in log (2) For each in log, in forward order (earliest latest) do: - if Ti S then Write(X, v) Output(X) optional Recovery rules: Redo logging
cs4432recovery22 Recovery is very, very SLOW ! Redo log: FirstT1 wrote A,BLast RecordCommitted a year agoRecord (1 year ago)--> STILL, Need to redo after crash!!... Crash
cs4432recovery23 Solution: Checkpoint (simple version) Periodically: (1) Do not accept new transactions (2) Wait until all transactions finish (3) Flush all log records to disk (log) (4) Flush all buffers to disk (DB) (do not discard buffers) (5) Write “checkpoint” record on disk (log) (6) Resume transaction processing
cs4432recovery24 Example: what to do at recovery? Redo log (disk): Checkpoint Crash...
cs4432recovery25 Key drawbacks: Undo logging: cannot bring backup DB copies up to date Redo logging: need to keep all modified blocks inmemory until commit
cs4432recovery27 Rules Page X can be flushed before or after Ti commit Log record flushed before corresponding updated page (WAL) Flush at commit (log only)
cs4432recovery28 Non-quiesce checkpoint L O G for undodirty buffer pool pages flushed Start-ckpt active TR: Ti,T2,... end ckpt...
cs4432recovery29 Examples what to do at recovery time? no T1 commit L O G T 1,- a... Ckpt T 1... Ckpt end... T1-bT1-b Undo T 1 (undo a,b)
cs4432recovery30 Example LOGLOG... T1aT1a T1bT1b T1cT1c T 1 cmt... ckpt- end ckpt-s T 1 Redo T1: (redo b,c)
cs4432recovery31 Recovery process: Backwards pass (end of log latest checkpoint start) –construct set S of committed transactions –undo actions of transactions not in S Undo pending transactions –follow undo chains for transactions in (checkpoint active list) - S Forward pass (latest checkpoint start end of log) –redo actions of S transactions backward pass forward pass start check- point
cs4432recovery32 Summary Consistency of data One source of problems: failures - Logging - Redundancy Another source of problems: Data Sharing..... next