Professional Documents
Culture Documents
a2 a2 - 100
a10 a10 + 100
. . .
. . .
a2 500 400 400
. . .
. . .
a10 1000 1000 1100
A: 800
A: 800
B: 800
B: 800
memory disk
CS3223 – Crash Recovery 7
T1: Read (A);
A A-100
Write (A);
Read (B);
B B+100
Write (B);
A: 800 700
A: 800
B: 800
B: 800
memory disk
CS3223 – Crash Recovery 8
T1: Read (A);
A A-100
Write (A);
Read (B);
B B+100
Updated A value is written to disk.
Write (B); This may be triggered ANYTIME
by explicit command or DBMS or OS
A: 800 700
A: 800 700
B: 800
B: 800
memory disk
CS3223 – Crash Recovery 9
T1: Read (A);
A A-100
Write (A);
Read (B);
B B+100
Write (B);
A: 800 700
A: 800 700
B: 800 900
B: 800
memory disk
CS3223 – Crash Recovery 10
T1: Read (A);
A A-100
Write (A);
Read (B);
B B+100
Failure before commit
Write (B);
(memory content lost
before disk updated)!
A: 800 700
A: 800 700
B: 800 900
B: 800
memory disk
CS3223 – Crash Recovery 11
What is the disk content before
the crash?
Disk not updated yet
A = 700; B = 800?
A = 800; B = 700?
Disk fully updated
A: 700 A = 800; B = 800?
Disk partially updated
B: 800
disk
Need atomicity: execute all
actions of a transaction or
none at all
CS3223 – Crash Recovery 12
Recovery Manager
• Recovery Manager guarantees atomicity and durability
properties of Xacts
• Undo: remove effects of aborted Xact to preserve atomicity
• Redo: re-installing effects of committed Xact for durability
• Processes three operations:
• Commit(T) - install T’s updated “pages” into disk
• Abort(T) - restore all data that T updated to their prior values
• Restart - recover database to a consistent state from system failure
• abort all active Xacts at the time of system failure
• installs updates of all committed Xacts
need to remember old values
• Desirable properties:
• Add little overhead to the normal processing of Xacts
• Recover quickly from a failure
<T1, start>
A:800 A:800
B:800 B:800
<T1, start>
<T1, start>
<T1, A, 800>
A:800 700 A:800
B:800 900 B:800
<T1, start>
<T1, A, 800>
A:800 700 A:800 700
B:800 900 B:800
<T1, start>
<T1, A, 800>
A:800 700 A:800 700 <T1, B, 800>
B:800 900 B:800
<T1, start>
<T1, A, 800>
A:800 700 A:800 700 <T1, B, 800>
B:800 900 B:800 900
<T1, start>
<T1, A, 800>
A:800 700 A:800 700 <T1, B, 800>
B:800 900 B:800 900 <T1, commit>
memory A: 800
B: 800 DB
A: 800 700
B: 800 900
Log: Log
<T1,start>
<T1, A, 800>
<T1, B, 800>
A: 800 700
B: 800 900
Log: A: 800
<T1,start> B: 800
<T1, A, 800>
<T1, B, 800>
log
CS3223 – Crash Recovery 31
Undo Logging
T1: Read (A); A A-100
Write (A);
Read (B); B B+100
Write (B);
A: 800 700
B: 800 900 <T1, Start>
Log: A: 800 <T1, A, 800>
<T1,start> B: 800 <T1, B, 800>
<T1, A, 800>
<T1, B, 800>
log
CS3223 – Crash Recovery 32
Undo Logging
T1: Read (A); A A-100
Write (A);
Read (B); B B+100
Write (B);
A: 800 700
B: 800 900 <T1, Start>
Log: A: 800 700 <T1, A, 800>
<T1,start> B: 800 <T1, B, 800>
<T1, A, 800>
<T1, B, 800>
log
CS3223 – Crash Recovery 33
Undo Logging
T1: Read (A); A A-100
Write (A);
Read (B); B B+100
Write (B);
A: 800 700
B: 800 900 <T1, Start>
Log: A: 800 700 <T1, A, 800>
<T1,start> B: 800 900 <T1, B, 800>
<T1, A, 800>
<T1, B, 800>
log
CS3223 – Crash Recovery 34
Undo Logging
T1: Read (A); A A-100
Write (A);
Read (B); B B+100
Write (B);
A: 800 700
B: 800 900 <T1, Start>
Log: A: 800 700 <T1, A, 800>
<T1,start> B: 800 900 <T1, B, 800>
<T1, A, 800> <T1, Commit>
<T1, B, 800>
<T1, commit> log
CS3223 – Crash Recovery 35
Recovery rules: Undo logging
(1)Let S = set of transactions with <Ti, start> in log, but
no <Ti, commit> (or <Ti, abort>) record in log
• What about those with Commit/Abort? commited transactions
dont care since updates
alr on disk
(2) For each <Ti, X, v> in log,
aborted txs
in reverse order (latest earliest) do: have already
been undone
- if Ti S then - X v
- Update disk
(3) For each Ti S do
- write <Ti, abort> to log
CS3223 – Crash Recovery 36
What if failure during recovery?
No problem! Undo is idempotent
A: 800 A: 800
B: 800 B: 800
memory DB LOG
Redo log: <TID, Object, newValue>
CS3223 – Crash Recovery 39
Redo logging (deferred modification)
T1: Read(A); A A-100; write (A);
Read(B); B B+100; write (B);
<T1, start>
<T1, A, 700>
A: 800 700 A: 800 <T1, B, 900>
B: 800900 B: 800 <T1, commit>
memory DB LOG
<T1, start>
<T1, A, 700>
A: 800 700 output A: 800 700 <T1, B, 900>
B: 800900 B: 800 <T1, commit>
memory DB LOG
Rules:
1) Page X can be flushed before or after Ti commit
2) Log record flushed before corresponding updated page (WAL)
3) All log records flushed at commit
• Backwards pass
• construct set S of committed transactions
• undo actions of transactions not in S
• Forward pass
• redo actions of S transactions
<T2,commit>
<T1,A,16>
<T3,C,21>
<T2,B,17>
Checkpoint Crash
... ... ... ... ... ...
tradeoff
L
O T1 ckpt-s T1 ckpt- T1 T1
... ... T1 ... ... ... ... ...
G a b end c cmt
A: 16
X1 X2 X3
backup active
database database
log