Lecture: Lecture 18 - Reliability Management and Recovery
Related: Reliability Manager Log Records Undo Redo and Checkpoints · Write-Ahead Logging Commit Precedence and Disk-Write Protocols · Transactions and ACID Properties · Distributed Transaction Classification and Two-Phase Commit
Types of failures and the fail-stop model (Slides 28–30)
Recovery depends on what survived the crash (Slides 28, 30):
| Failure Type | Cause | What Is Lost | What Survives | Recovery Primitive |
|---|---|---|---|---|
| System failure | Software bug or power supply interruption | Main memory content (DBMS buffer) | Disk (both database and log) | Warm restart |
| Media failure | Failure of secondary memory (disk) device | Database content on disk (all or part) | Log (in stable storage) + last Dump | Cold restart |
Fail-stop model (Slides 29–30)
Under the fail-stop model, a DBMS halts immediately upon failure rather than continuing with corrupted state:
┌────────── Recovery ends ──────────┐
▼ │
[Normal Operation] ──FAIL──► [STOP] ──BOOT──► [RECOVERY]
▲ │
└────── FAIL ──────┘If another failure strikes while RECOVERY is running, the system halts again (STOP), reboots (BOOT), and restarts RECOVERY. Because UNDO and REDO are idempotent, restarting recovery does not corrupt the database. Once recovery ends, the system returns to normal transaction processing (Slide 30).
Warm Restart: transaction categories (Slides 31–34)
Consider a timeline with the time of the last checkpoint () and the time of failure () (Slide 32):
t_C (checkpoint) t_F (crash!)
──────────────────────┼─────────────────────────────┼──────────────────► time
T1: ├────────┤ (completed before t_C → NO ACTION)
T2: ├───────────────┤ (committed after t_C → REDO)
T3: ├───────────────────────────────────────────┤ active at t_F → UNDO
T4: ├───────────────┤ (committed after t_C → REDO)
T5: ├──────────────────┤ active at t_F → UNDOEvery transaction falls into one of three categories (Slide 33):
- Completed before the checkpoint (
T1): Concluded pages were already forced synchronously to disk during the checkpoint → no recovery action needed. - Committed after the checkpoint (
T2andT4): Committed before , so they must survive—even if some writes were still in RAM → REDO needed. (NoteT2began before , so its writes may span both sides of .) - Active at the time of failure (
T3andT5): Never committed before , so any dirty pages they leaked to disk must be erased → UNDO needed.
Why checkpoints are an optimization, not a requirement (Slide 34): A checkpoint record is not strictly necessary to enable recovery; it simply makes warm restart much faster. Without a checkpoint record, recovery would have to read the entire log all the way back to the last dump.
Warm Restart algorithm: step-by-step problem solving (Slides 35–43)
When given a log snippet ending in a failure, follow this exact 4-step procedure every time:
Step 1 — Find the last checkpoint (Slide 35)
Read the log backwards from the failure point until you locate the last checkpoint record CK(L).
Step 2 — Determine the final UNDO and REDO lists (Slides 35–36)
- 2a. Initialize at
CK(L):UNDO = L(every transaction active at the checkpoint)REDO = { }(empty)
- 2b. Scan FORWARD from
CK(L)to the failure:- On
B(T)(begin) → addTtoUNDO. - On
C(T)(commit) → moveTfromUNDOtoREDO. - On
A(T)(abort/rollback) → keepTinUNDO! (Even thoughTaborted normally, some of its rollback changes or dirty pages may not have been consistently reflected on disk before the crash.)
- On
At the end of Step 2:
UNDO= exact list of transactions to be undone.REDO= exact list of transactions to be redone.
(On Slides 37–41, this forward scan on the timeline above starts with UNDO = {T2, T3}, REDO = {} at ; adds T4 at ; moves T2 to REDO at ; adds T5 at ; and moves T4 to REDO at , yielding UNDO = {T3, T5} and REDO = {T2, T4}.)
Step 3 — Execute UNDO backwards (Slide 42)
- Read the log backwards from the time of failure until you reach the
B(T)record of the oldest transaction in theUNDOlist (even if thatB(T)is earlier than the last checkpoint). - For every
I,D, orUbelonging to a transaction inUNDO, apply its Undo action:I(T, O, AS)→DELETE OD(T, O, BS)→INSERT O = BS(write before state)U(T, O, BS, AS)→O = BS(write before state)
- Ignore transactions not in
UNDO(including those inREDOor completed beforeCK).
Step 4 — Execute REDO forward (Slide 43)
- Read the log forward starting from the
B(T)record of the oldest transaction in theREDOlist up to the failure. - For every
I,D, orUbelonging to a transaction inREDO, apply its Redo action:I(T, O, AS)→O = AS(write after state)D(T, O, BS)→DELETE OU(T, O, BS, AS)→O = AS(write after state)
- Notice that if a transaction in
REDOstarted beforeCK(L), scanning from itsB(T)ensures its pre-checkpoint updates are included too.
Why UNDO goes backwards and REDO goes forward
Suppose a transaction T updated the same object O3 twice: first 10 → 20 (U(T, O3, 10, 20)), then 20 → 30 (U(T, O3, 20, 30)).
- UNDO backwards: First restores
O3 = 20, then restoresO3 = 10— arriving at the true original value10. Undoing forwards would end at20and lose10! - REDO forward: Replays
O3 = 20, thenO3 = 30— arriving at the true final committed value30.
Worked Exam Trace #1 (Source Slides 44–50)
Given log snippet:
B(T1) B(T2) U(T2, O1, B1, A1) I(T1, O2, A2) B(T3) C(T1) B(T4) U(T3, O2, B3, A3) U(T4, O3, B4, A4) CK(T2, T3, T4) C(T4) B(T5) U(T3, O3, B5, A5) U(T5, O4, B6, A6) D(T3, O3, B7) A(T3) C(T5) I(T2, O6, A8)failure
Step 1 & Step 2 — Build UNDO and REDO lists (Slides 45–47)
At CK(T2, T3, T4): UNDO = {T2, T3, T4}, REDO = { }. (Notice T1 already committed at C(T1) before CK, so T1 is ignored.)
Scan forward from CK to failure:
Operation after CK | Effect | UNDO | REDO |
|---|---|---|---|
CK(T2, T3, T4) | Initialize from checkpoint | {T2, T3, T4} | { } |
C(T4) | Move T4 from UNDO to REDO | {T2, T3} | {T4} |
B(T5) | Add T5 to UNDO | {T2, T3, T5} | {T4} |
A(T3) | Abort keeps T3 in UNDO | {T2, T3, T5} | {T4} |
C(T5) | Move T5 from UNDO to REDO | {T2, T3} | {T4, T5} |
Final lists: UNDO = {T2, T3}, REDO = {T4, T5}.
Step 3 — UNDO backwards from failure to B(T2) (Slide 48)
T2 is older than T3 (B(T2) appears before B(T3)), so we scan backwards from failure all the way past CK until B(T2) and undo every action of T2 and T3:
| Order | Log record encountered (backwards) | Belongs to UNDO? | Action executed |
|---|---|---|---|
| a | I(T2, O6, A8) | Yes (T2) | DELETE O6 |
| — | C(T5) | Delimiter | skip |
| — | A(T3) | Delimiter | skip |
| b | D(T3, O3, B7) | Yes (T3) | INSERT O3 = B7 |
| — | U(T5, O4, B6, A6) | No (T5 in REDO) | skip |
| c | U(T3, O3, B5, A5) | Yes (T3) | O3 = B5 |
| — | B(T5), C(T4), CK(...) | Delimiters/system | skip |
| — | U(T4, O3, B4, A4) | No (T4 in REDO) | skip |
| d | U(T3, O2, B3, A3) | Yes (T3) | O2 = B3 |
| — | B(T4), C(T1), B(T3) | Delimiters | skip |
| — | I(T1, O2, A2) | No (T1 ignored) | skip |
| e | U(T2, O1, B1, A1) | Yes (T2) | O1 = B1 |
| stop | B(T2) | Oldest in UNDO reached | stop UNDO |
Notice how O3 had D(T3, O3, B7) after U(T3, O3, B5, A5): going backwards first re-inserts O3 = B7 and then overwrites O3 = B5, returning O3 to its pre-T3 state!
Step 4 — REDO forward from B(T4) to failure (Slide 49)
T4 is older than T5 (B(T4) appears before B(T5), even before CK!), so we scan forward from B(T4) to failure and redo every action of T4 and T5:
| Order | Log record encountered (forwards) | Belongs to REDO? | Action executed |
|---|---|---|---|
| start | B(T4) | Oldest in REDO | start REDO |
| a | U(T4, O3, B4, A4) | Yes (T4) | O3 = A4 |
| — | U(T3, O2, B3, A3), CK(...), C(T4), B(T5) | Not in REDO / delimiter | skip |
| — | U(T3, O3, B5, A5) | No (T3 in UNDO) | skip |
| b | U(T5, O4, B6, A6) | Yes (T5) | O4 = A6 |
| — | D(T3, ...), A(T3), C(T5), I(T2, ...) | Not in REDO / delimiter | skip |
(Slide 50 shows the timeline view of this exact example: T1 finished before , T4 started before and committed after, T5 ran after and committed, T3 aborted after , and T2 was still running at .)
Worked Exam Trace #2 (Added study practice trace outside the PDF)
(Added practice example from our study session, outside the source PDF)
Given log snippet:
B(T1) U(T1, O1, B1, A1) B(T2) CK(T1, T2) U(T2, O2, B2, A2) C(T1) B(T3) I(T3, O3, A3) A(T2)failure
- At
CK(T1, T2):UNDO = {T1, T2},REDO = { }. - Forward scan after
CK:C(T1)→ moveT1toREDO:UNDO = {T2},REDO = {T1}.B(T3)→ addT3toUNDO:UNDO = {T2, T3},REDO = {T1}.A(T2)→ stays inUNDO!- Final lists:
UNDO = {T2, T3},REDO = {T1}.
- UNDO backwards (from failure to
B(T2)):I(T3, O3, A3)→DELETE O3U(T2, O2, B2, A2)→O2 = B2
- REDO forward (from
B(T1)— beforeCK!):U(T1, O1, B1, A1)→O1 = A1
Cold Restart (Slides 51–53)
When a media failure destroys all or part of the database on disk (while the log in stable memory and the last dump survive), the DBMS performs a Cold Restart.
Standard 3-step Cold Restart (Slide 52)
- Restore from dump: Access the last Dump to restore the damaged portion of the database on disk.
- Replay forward from the dump: Starting from the
Dumprecord in the log, read the log forward and redo all actions on the database as well as transaction commits and rollbacks. - Perform a warm restart: Run the Warm Restart algorithm to undo any uncommitted work and bring the database to a consistent state.
Alternative 2-pass Cold Restart (Slide 53)
Instead of replaying uncommitted transactions in Step 2 only to undo them in Step 3, an alternative to Steps 2 and 3 performs only actions of committed transactions using two forward log reads starting from the Dump record:
- Pass 1 (build
REDOlist): Read the log forward from theDumprecord to detect all committed transactions (C(T)present) and place them in aREDOlist. - Pass 2 (selective redo): Read the log forward again from the
Dumprecord and redo only the actions of transactions in theREDOlist.
(Tradeoff: The 2-pass alternative reads the log twice instead of once, but avoids writing and then immediately undoing modifications from aborted or crashed transactions.)
Common exam traps and confusions
- Treating
A(T)likeC(T): SeeingA(T)in the log does not removeTfromUNDO! Aborted transactions stay inUNDObecause the crash may have occurred before all rollback effects reached disk. - Stopping UNDO or starting REDO at
CK(L): Never stopUNDOatCK(L)if a transaction inUNDObegan earlier (B(T)beforeCK), and never startREDOatCK(L)if a transaction inREDObegan beforeCK(likeT4in Slide 49 andT1in Trace #2). Both phases must reach theB(T)of the oldest transaction in their respective list. - Running UNDO forward instead of backwards: Always scan backwards during UNDO so earlier
BSvalues overwrite laterBSvalues on the same object, not the other way around. - Confusing Warm vs. Cold restart: Warm restart assumes the database on disk survived (only RAM was lost); Cold restart assumes disk data was damaged and starts from a Dump.
Retrieval questions with answers
1. Why must Step 3 (UNDO) read the log backwards, and why can it not stop at the checkpoint CK(L)?
If a transaction in UNDO modified the same object O multiple times, only scanning backwards guarantees that the oldest BS is written last, restoring O’s true initial state. It cannot stop at CK(L) because active transactions at the checkpoint (T ∈ L) may have made modifications before CK(L) that were already evicted to disk under a steal policy.
2. Trace this log snippet: B(T1) U(T1, O1, B1, A1) CK(T1) B(T2) U(T2, O1, B2, A2) I(T2, O2, A3) A(T1) B(T3) D(T3, O3, B4) C(T3) failure. What are UNDO, REDO, and the exact UNDO/REDO steps?
- At
CK(T1):UNDO = {T1},REDO = { }. - Forward scan:
B(T2)addsT2;A(T1)keepsT1inUNDO;B(T3)addsT3;C(T3)movesT3toREDO. - Final lists:
UNDO = {T1, T2},REDO = {T3}. - UNDO (backwards from failure to
B(T1)):DELETE O2(fromI(T2, O2, A3)),O1 = B2(fromU(T2, O1, B2, A2)),O1 = B1(fromU(T1, O1, B1, A1)). - REDO (forward from
B(T3)):DELETE O3(fromD(T3, O3, B4)).
3. When is the 2-pass Cold Restart alternative preferable to the standard 3-step Cold Restart?
When the log since the last dump contains many aborted or active-at-crash transactions, the 2-pass method avoids applying and then undoing all of their database modifications, at the cost of scanning the log forward twice instead of once (plus a warm restart).