Recovery
Recovery
Transaction T1 Log
Ti partially commits:
Write <Ti commit> to the log
DB updates by reading and executing the log:
<Ti start> …… <Ti commit>
Deferred Database Modification
How to use the log for recovery after a crash?
Redo: if both <Ti start> and <Ti commit> are there in the log.
Crashes can occur while
the transaction is executing the original updates, or
while recovery action is being taken
<T0 start>
<T0, A, 1000, 950>
<To, B, 2000, 2050>
A = 950
B = 2050
<T0 commit>
<T1 start>
<T1, C, 700, 600>
C = 600
B B , BC
<T1 commit>
BA
Note: BX denotes block containing X.
Immediate Database Modification (Cont.)
Recovery procedure :
Undo : <Ti, start > is in the log but <Ti commit> is not. Undo:
restore the value of all data items updated by Ti to their old
values, going backwards from the last log record for Ti
Redo: <Ti start> and <Ti commit> are both in the log. Redo:
sets the value of all data items updated by Ti to the new values,
going forward from the first log record for Ti
Both operations must be idempotent: even if the operation is executed
multiple times the effect is the same as if it is executed once
Undo operations are performed first, then redo operations. Why?
I M Recovery Example
<T0, start> <T0, start>
<T0, start>
<T0, A, 1000, 950> <T0, A, 1000, 950>
<T0, A, 1000, 950>
<T0, B, 2000, 2050> <T0, B, 2000, 2050>
<T0, B, 2000, 2050>
<T0, commit> <T0, commit>
<T1, start> <T1, start>
(a) <T1, C, 700, 600> <T1, C, 700, 600>
<T1, commit>
(b)
Recovery actions in each case above are: (c)
(a) undo (T0): B is restored to 2000 and A to 1000.
(b) undo (T1) and redo (T0): C is restored to 700, and then A and B are
set to 950 and 2050 respectively.
(c) redo (T0) and redo (T1): A and B are set to 950 and 2050
respectively. Then C is set to 600
Checkpoints
3. Need only consider the part of log following above start record.
Why?
4. After that, recover from log with the rules that we had before.
Example of Checkpoints
Tc Tf
T1
T2
T3
T4
T4 undone
Recovery With Concurrent Transactions
To permit concurrency:
All transactions share a single disk buffer and a single log
Concurrency control: Strict 2PL :i.e. Release eXclusive locks only
after commit. Why?
Logging is done as described earlier.
The checkpointing technique and actions taken on recovery have
to be changed (based on ARIES)
since several transactions may be active when a checkpoint is
performed.
Recovery With Concurrent Transactions (Cont.)
Checkpoints for concurrent transactions:
< checkpoint L>
L: the list of transactions active at the time of the checkpoint
We assume no updates are in progress while the checkpoint is carried
out
Recovery for concurrent transactions, 3 phases:
1. Initialize undo-list and redo-list to empty
2. Scan the log backwards from the end, stopping when the first
<checkpoint L> record is found.
For each record found during the backward scan: ANALYSIS
if the record is <Ti commit>, add Ti to redo-list
if the record is <Ti start>, then if Ti is not in redo-list, add Ti to undo-list
For every Ti in L, if Ti is not in redo-list, add Ti to undo-list
Recovery With Concurrent Transactions
Scan log backwards
Perform undo(T) for every transaction in undo-list
Stop when reach <T, start> for every T in undo-list. UNDO