Lecture: Lecture 18 - Reliability Management and Recovery
Related: Transactions and ACID Properties · Buffer Manager and Page Replacement · Write-Ahead Logging Commit Precedence and Disk-Write Protocols · Warm Restart Problem Solving and Cold Restart
Why reliability management is needed
Database management systems keep active data pages in volatile main memory (the DBMS buffer) because RAM is orders of magnitude faster than secondary disk storage. That creates two crash hazards whenever power fails or software crashes before modified pages are safely synchronized with disk:
- Partial writes on disk (Atomicity hazard): Under a steal buffer policy, the buffer manager may write an uncommitted transaction’s modified page to disk before the transaction finishes. If the system crashes before commit, that partial change must be erased.
- Lost committed writes (Durability hazard): Under a no-force policy, a transaction may commit while some of its modified pages still sit only in RAM. If the system crashes before those pages are flushed to disk, those committed updates vanish unless they can be reconstructed.
Inside the DBMS architecture (Slide 2), the Reliability Manager interacts directly with the Buffer Manager to guarantee the atomicity and durability ACID properties (Slide 3). It implements the transactional commands—begin transaction (B, usually implicit), commit work (C), and rollback work (A, for abort)—and provides the two recovery primitives: warm restart (for main memory failures) and cold restart (for disk failures). To prepare for recovery, it maintains the log file on stable memory and periodically coordinates checkpoints and dumps (Slide 4), generating extra read/write requests to the buffer manager when needed.
Stable memory and the log file (Slides 5–6)
Stable memory
Stable memory is an abstraction for storage that is completely resistant to failure (Slide 5). Because real physical hardware can always fail, stable memory is approximated using redundancy (such as mirrored disks or RAID) and robust write protocols. In the recovery model, failures in stable memory itself are considered catastrophic.
The log file
The log file is a sequential, append-only archive written in stable memory that records all DBMS transaction and system activities in strict chronological order (Slides 4, 6).
- Analogy: Think of the database on disk as an accounting ledger and the log file as a fireproof black-box flight recorder. Every change is appended to the black box as it happens.
- Limit of the analogy: Unlike an airplane flight recorder—which investigators only inspect after an incident—the DBMS actively reads its log during restart to repair the database to a consistent state.
- Sequential and interleaved writing (Slide 6): Log records are appended sequentially into the current log block. Because multiple transactions run concurrently, records belonging to different transactions appear interleaved in execution order.
Log record types (Slides 7–10)
Every entry in the log is either a transaction record or a system record (Slide 6).
1. Transaction records (Slides 7–8)
Transaction records describe the activities performed by each transaction (identified by its Transaction Identifier T) in execution order:
- Transaction delimiters:
B(T)— Begin transactionTC(T)— Commit transactionTA(T)— Abort / Rollback transactionT
- Data modifications on written object
O(identified by its Record Identifier,RID):I(T, O, AS)— Insert: records only the After State (AS), becauseOdid not exist before the insertion.D(T, O, BS)— Delete: records only the Before State (BS), soOcan be restored if undone.U(T, O, BS, AS)— Update: records both the Before State (BS) (value ofObefore modification) and the After State (AS) (value ofOafter modification).
2. System records (Slide 9)
System records capture administrative operations that save state to disk or tertiary/off-line storage:
Dump— marks the completion of a database backup copy (recording date/time and dump device, Slide 16).CK(L)— Checkpoint, where is the set of Transaction Identifiers (TIDs) of all transactions currently active when the checkpoint is recorded.
Source log timeline example (Slide 10)
──|────|────────|──────|─────|─────────|──────────|─────────|──────────|──► time
DUMP B(T1) B(T2) CK U(T2,O2, I(T1,O1, C(T1) D(T2,O3,
BS2,AS2) AS1) BS3) ▲
Top of the logNotice how T1 and T2 interleave chronologically, CK sits in the stream after both B(T1) and B(T2) have started, and the newest record at the right is called the top of the log.
Undoing, redoing, and idempotency (Slides 11–12)
During recovery, the Reliability Manager repairs the database by applying Undo (erasing uncommitted changes) or Redo (re-applying committed changes) to logged data modification records (Slide 11):
| Logged Action | UNDO action (revert) | REDO action (re-apply) |
|---|---|---|
insert O (I(T, O, AS)) | delete O | write the After State (AS) of O |
update O (U(T, O, BS, AS)) | write the Before State (BS) of O | write the After State (AS) of O |
delete O (D(T, O, BS)) | write the Before State (BS) of O | delete O |
The idempotency property (Slide 12)
Both UNDO and REDO are idempotent: repeating either operation an arbitrary number of times yields the exact same final outcome as applying it once:
- Why this holds: Log records store absolute Before States (
BS) and After States (AS), not relative deltas. OverwritingOwithBS = 500twice leavesO = 500, and deleting an already deletedOleavesOabsent. - Why this matters: If the system crashes again during the recovery process, the DBMS can restart recovery from scratch without corrupting the database by undoing or redoing an already-processed record.
- Contrast (added study example outside the PDF): Suppose a log instead stored relative deltas such as “add 10 to
O” (whereOstarted at50and reached60). If recovery crashed halfway through redoing or undoing and restarted from the beginning, re-applying+10or-10multiple times would leaveOat70,80, or30instead of the true state.
Checkpoints (Slides 13–15)
Reading all the way back to the last dump after every minor crash becomes prohibitively slow as the log grows. A checkpoint is an operation periodically requested by the Reliability Manager to the Buffer Manager so warm restarts can scan a much shorter suffix of the log (Slide 13).
Step-by-step execution of a checkpoint (Slide 14)
- Record active TIDs and pause commits: Collect the TIDs of all currently active transactions into set . Once the checkpoint begins, no transaction is allowed to commit until the checkpoint ends.
- Synchronously flush concluded transactions: Write all modified buffer pages belonging to concluded transactions (already committed or aborted) to disk synchronously using the buffer manager’s
forceprimitive. - Synchronously write the checkpoint record: At the end of step 2, synchronously write (
force)CK(L)containing the active transaction set onto the log.
State guaranteed after a checkpoint (Slide 15)
- Committed transactions finished before
CK(L): Their effects are permanently stored on disk, so recovery never needs to redo them. - Active transactions listed in
L: The disk state of data pages written by active transactions is unknown—some modified pages may have been written to disk by the buffer manager, while others may still reside only in memory. Consequently, recovery must still examine every transaction inL.
Tradeoff: Frequent checkpoints shorten crash recovery time by bounding how far back REDO needs to look, at the cost of periodic commit stalls and synchronous disk writes (force) during normal execution.
Dumps (Slide 16)
A dump creates a complete (or incremental) backup copy of the database, typically performed when the system is offline, and stores it on stable memory (tertiary or off-line storage). Once the backup finishes, a Dump record is written into the log file containing:
- the date and time of the dump, and
- the dump device used.
Whereas checkpoints speed up warm restarts after RAM loss, dumps provide the baseline snapshot needed for cold restarts after disk/media loss.
Common confusions
- Checkpoints do NOT flush everything to disk: Step 2 only forces pages of concluded (committed or aborted) transactions. Pages modified by active transactions may or may not be on disk, which is why their state is explicitly described as unknown (Slide 15).
- Checkpoints do NOT eliminate scanning before
CK(L)forUNDO: If an active transactionTinLbegan before the checkpoint and later crashes without committing, its pre-checkpoint modifications might already be on disk, soUNDOmust still walk backwards pastCK(L)toB(T). - State logging vs. operation/delta logging: Idempotency holds here because
I,D, andUlog fullBSandASvalues rather than relative increments.
Retrieval questions with answers
1. Suppose a log recorded relative changes like “add 10 to O” instead of storing BS and AS. What would go wrong if the database crashed during recovery and had to restart recovery?
Relative updates are not idempotent. Restarting recovery after a second crash would re-apply the +10 (or -10 during undo) multiple times to the same object, corrupting its value. State-based BS/AS records guarantee and .
2. After a checkpoint CK(T2, T3) completes, why can the DBMS safely ignore T1 (which committed before the checkpoint), while it still has to track T2 and T3?
Step 2 of the checkpoint synchronously forced all pages of concluded transactions (T1) to disk, so T1’s changes are permanently stored and require neither redo nor undo. By contrast, T2 and T3 were still active during the checkpoint: the disk state of their modified pages is unknown, and we do not yet know whether each will eventually commit or abort.
3. Why does an Insert log record I(T, O, AS) omit BS, whereas a Delete log record D(T, O, BS) omits AS?
Before an insert, object O did not exist, so undoing it only requires delete O (no BS is needed). After a delete, object O no longer exists, so redoing it only requires delete O (no AS is needed), while undoing it restores BS.