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 TypeCauseWhat Is LostWhat SurvivesRecovery Primitive
System failureSoftware bug or power supply interruptionMain memory content (DBMS buffer)Disk (both database and log)Warm restart
Media failureFailure of secondary memory (disk) deviceDatabase content on disk (all or part)Log (in stable storage) + last DumpCold 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       → UNDO

Every transaction falls into one of three categories (Slide 33):

  1. Completed before the checkpoint (T1): Concluded pages were already forced synchronously to disk during the checkpoint → no recovery action needed.
  2. Committed after the checkpoint (T2 and T4): Committed before , so they must survive—even if some writes were still in RAM → REDO needed. (Note T2 began before , so its writes may span both sides of .)
  3. Active at the time of failure (T3 and T5): 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) → add T to UNDO.
    • On C(T) (commit) → move T from UNDO to REDO.
    • On A(T) (abort/rollback) → keep T in UNDO! (Even though T aborted normally, some of its rollback changes or dirty pages may not have been consistently reflected on disk before the crash.)

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 the UNDO list (even if that B(T) is earlier than the last checkpoint).
  • For every I, D, or U belonging to a transaction in UNDO, apply its Undo action:
    • I(T, O, AS) → DELETE O
    • D(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 in REDO or completed before CK).

Step 4 — Execute REDO forward (Slide 43)

  • Read the log forward starting from the B(T) record of the oldest transaction in the REDO list up to the failure.
  • For every I, D, or U belonging to a transaction in REDO, apply its Redo action:
    • I(T, O, AS) → O = AS (write after state)
    • D(T, O, BS) → DELETE O
    • U(T, O, BS, AS) → O = AS (write after state)
  • Notice that if a transaction in REDO started before CK(L), scanning from its B(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 restores O3 = 10 — arriving at the true original value 10. Undoing forwards would end at 20 and lose 10!
  • REDO forward: Replays O3 = 20, then O3 = 30 — arriving at the true final committed value 30.

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 CKEffectUNDOREDO
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:

OrderLog record encountered (backwards)Belongs to UNDO?Action executed
aI(T2, O6, A8)Yes (T2)DELETE O6
—C(T5)Delimiterskip
—A(T3)Delimiterskip
bD(T3, O3, B7)Yes (T3)INSERT O3 = B7
—U(T5, O4, B6, A6)No (T5 in REDO)skip
cU(T3, O3, B5, A5)Yes (T3)O3 = B5
—B(T5), C(T4), CK(...)Delimiters/systemskip
—U(T4, O3, B4, A4)No (T4 in REDO)skip
dU(T3, O2, B3, A3)Yes (T3)O2 = B3
—B(T4), C(T1), B(T3)Delimitersskip
—I(T1, O2, A2)No (T1 ignored)skip
eU(T2, O1, B1, A1)Yes (T2)O1 = B1
stopB(T2)Oldest in UNDO reachedstop 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:

OrderLog record encountered (forwards)Belongs to REDO?Action executed
startB(T4)Oldest in REDOstart REDO
aU(T4, O3, B4, A4)Yes (T4)O3 = A4
—U(T3, O2, B3, A3), CK(...), C(T4), B(T5)Not in REDO / delimiterskip
—U(T3, O3, B5, A5)No (T3 in UNDO)skip
bU(T5, O4, B6, A6)Yes (T5)O4 = A6
—D(T3, ...), A(T3), C(T5), I(T2, ...)Not in REDO / delimiterskip

(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

  1. At CK(T1, T2): UNDO = {T1, T2}, REDO = { }.
  2. Forward scan after CK:
    • C(T1) → move T1 to REDO: UNDO = {T2}, REDO = {T1}.
    • B(T3) → add T3 to UNDO: UNDO = {T2, T3}, REDO = {T1}.
    • A(T2) → stays in UNDO!
    • Final lists: UNDO = {T2, T3}, REDO = {T1}.
  3. UNDO backwards (from failure to B(T2)):
    • I(T3, O3, A3) → DELETE O3
    • U(T2, O2, B2, A2) → O2 = B2
  4. REDO forward (from B(T1) — before CK!):
    • 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)

  1. Restore from dump: Access the last Dump to restore the damaged portion of the database on disk.
  2. Replay forward from the dump: Starting from the Dump record in the log, read the log forward and redo all actions on the database as well as transaction commits and rollbacks.
  3. 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:

  1. Pass 1 (build REDO list): Read the log forward from the Dump record to detect all committed transactions (C(T) present) and place them in a REDO list.
  2. Pass 2 (selective redo): Read the log forward again from the Dump record and redo only the actions of transactions in the REDO list.

(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

  1. Treating A(T) like C(T): Seeing A(T) in the log does not remove T from UNDO! Aborted transactions stay in UNDO because the crash may have occurred before all rollback effects reached disk.
  2. Stopping UNDO or starting REDO at CK(L): Never stop UNDO at CK(L) if a transaction in UNDO began earlier (B(T) before CK), and never start REDO at CK(L) if a transaction in REDO began before CK (like T4 in Slide 49 and T1 in Trace #2). Both phases must reach the B(T) of the oldest transaction in their respective list.
  3. Running UNDO forward instead of backwards: Always scan backwards during UNDO so earlier BS values overwrite later BS values on the same object, not the other way around.
  4. 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) adds T2; A(T1) keeps T1 in UNDO; B(T3) adds T3; C(T3) moves T3 to REDO.
  • Final lists: UNDO = {T1, T2}, REDO = {T3}.
  • UNDO (backwards from failure to B(T1)): DELETE O2 (from I(T2, O2, A3)), O1 = B2 (from U(T2, O1, B2, A2)), O1 = B1 (from U(T1, O1, B1, A1)).
  • REDO (forward from B(T3)): DELETE O3 (from D(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).