Failure Recovery
description
Transcript of Failure Recovery
![Page 1: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/1.jpg)
1
Failure Recovery
CheckpointingUndo/Redo Logging
Source: slides by Hector Garcia-Molina
![Page 2: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/2.jpg)
2
Recovery is very, very
SLOW !Redo log:
First T1 wrote A,B LastRecord Committed a year ago
Record(1 year ago) --> STILL, Need to redo after crash!!
... ... ...
Crash
![Page 3: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/3.jpg)
3
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
![Page 4: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/4.jpg)
4
Example: what to do at recovery?
Redo log (disk):
<T1
,A,1
6>
<T1
,com
mit
>
Ch
eck
poin
t
<T2
,B,1
7>
<T2
,com
mit
>
<T3
,C,2
1>
Crash... ... ... ...
...
...
Start from last checkpoint and move forwardin the log file redoing updates for committedtransactions.
![Page 5: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/5.jpg)
5
Key drawbacks:
Undo logging: data must be written to disk immediately after a transaction finishes, which can increase number of disk I/O's
Redo logging: need to keep all modified blocks in memory until transaction commits and log is flushed, which can increase the number of buffers required
![Page 6: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/6.jpg)
6
Solution: undo/redo logging!
Update record in the log has the format
<T, X, new X val, old X val>
![Page 7: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/7.jpg)
7
Rules
Buffer containing X can be flushed to disk either before or after T commits
Log record must be flushed to disk before corresponding updated buffer is (WAL)
![Page 8: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/8.jpg)
8
Recovery with Undo/Redo Logging
1. Redo all committed transactions in order from earliest to latest
handles committed transactions with some changes not yet on disk
2. Undo all incomplete transactions in order from latest to earliest
handles uncommitted transactions with some chnages already on disk
![Page 9: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/9.jpg)
9
Non-quiescent Checkpoint
Simple checkpointing scheme requires system to "quiesce" (reach a point with no active transactions), ensured by preventing new transactions from starting for a while
Avoid this behavior with non-quiescent checkpointing: write a "start checkpoint" record to the log later write an "end checkpoint" record to the log
Details vary depending on whether undo, redo, or undo/redo logging
![Page 10: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/10.jpg)
10
Non-quiescent Checkpoint for Undo/Redo
write "start checkpoint" listing all active transactions to log
flush log to disk write to disk all dirty buffers (contain a
changed DB element), whether or not transaction has committed this implies some log records may need to be
written to disk (WAL) write "end checkpoint" to log flush log to disk
![Page 11: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/11.jpg)
11
Non-quiescent checkpoint for undo/redo
LOG
for undo dirty buffer
pool pagesflushed
start ckptactive T's:T1,T2,...
endckpt
.........
...
![Page 12: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/12.jpg)
12
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 passstart
check-point
![Page 13: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/13.jpg)
13
Examples what to do at recovery time?
no T1 commit
LOG
T1,-a
...CkptT1
...Ckptend
...T1-b
...
Undo T1 (undo a,b)
![Page 14: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/14.jpg)
14
Example
LOG
...T1
a... ...
T1
b... ...
T1
c...
T1
cmt...
ckpt-end
ckpt-sT1
Redo T1: (redo b,c)
![Page 15: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/15.jpg)
15
Real world actions
E.g., dispense cash at ATMTi = a1 a2 …... aj …... an
$
![Page 16: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/16.jpg)
16
Solution
(1) execute real-world actions after commit
(2) try to make idempotent
![Page 17: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/17.jpg)
17
Media failure (loss of non-volatile storage)
A: 16
Solution: Make copies of data!
![Page 18: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/18.jpg)
18
Example 1 Triple modular redundancy
Keep 3 copies on separate disks Output(X) --> three outputs Input(X) --> three inputs + vote
X1 X2 X3
![Page 19: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/19.jpg)
19
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
![Page 20: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/20.jpg)
20
Example 3: DB Dump + Log
backupdatabase
activedatabase
log
• If active database is lost,– restore active database from backup– bring up-to-date using redo entries in log
![Page 21: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/21.jpg)
21
When can log be discarded?
check-point
dbdump
lastneededundo
not needed formedia recovery
not needed for undoafter system failure
not needed forredo after system failure
log
time
![Page 22: Failure Recovery](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815adc550346895dc8a84c/html5/thumbnails/22.jpg)
22
Summary
Consistency of data One source of problems: failures
- Logging- Redundancy
Another source of problems: Data Sharing..... next