Log-Based Recovery (Immediate DB Modification + Strict 2PL): Failure at T2 : commit
We analyze a log-based recovery system under immediate database modification (i.e., updates are applied to the database pages right away) together with strict 2PL (so updates are not made durable until the transaction is allowed to release locks, but pages/updates may still be in memory or on disk depending on the buffer flush). A failure occurs at the statement T2 : commit, meaning the commit record may or may not have reached the stable log; the safe recovery behavior is determined by which log records are guaranteed to be stable at crash time.
log-based recovery immediate modification strict 2PL commit record redo/undo.
Because updates are immediate, at crash time the database might already reflect some changes from T1 and T2 (and possibly other transactions depending on timing), even if they were not committed.
Ordering schedule S′ (from the prompt)
T1:R(A); A := A + 5; commit;T2:R(B); B := B + 5; commit;← failure happens hereT3:R(C); C := C + 5; C := C + 5; commit;T4:R(A); A := A + 5; R(D); D := D + 5; commit;All start withA=B=C=D=0. There is a single log and a common disk buffer.
Key recovery classification at the time of the crash
At the moment of failure at T2 : commit, the system must treat:
T1as committed (its commit statement occurred earlier)T2as possibly not committed (crash occurs during/at commit)T3andT4as uncommitted with respect to the crash (their commits occur after)
Therefore, the standard log-based recovery idea is:
- Redo all updates from transactions that are known to have committed (stable commit log record present).
- Undo all updates from transactions that are not known to have committed (i.e., no stable commit log record).
This yields the correct final state regardless of whether some updates from uncommitted transactions were written to disk/buffer.
Crash-time transaction status
T1 completes
Before crashT1 executes A := A+5 and reaches commit."
T2 commit not fully completed
At failure pointSystem crashes at the commit statement of T2; T2’s commit is not guaranteed stable."
T3 and T4 incomplete
After crash (during recovery)Their commit statements are later than the crash, so they are treated as uncommitted."
Step-by-step recovery outcome (what happens on disk pages)
Under immediate database modification, the database might already contain:
T1’s update toA- possibly
T2’s update toB(since it happened beforeT2 : commitis reached) - possibly
T3’s update toC - possibly
T4’s updates toAandD
However, recovery correctness depends on log status, not on what is on disk at crash.
We can reason transaction by transaction.
1) Transaction T1
T1 updates: A := A + 5 then commits earlier.
So T1 is committed at crash time. Therefore, its effects must be present after recovery, achieved by redo (or by leaving them if already present, depending on the precise recovery algorithm, but the net effect is “keep T1’s update”).
- Initial:
A=0 - After
T1:A=5
So we expect: A contains the contribution from T1: +5. redo/undo
2) Transaction T2 (failure at its commit statement)
T2 updates: B := B + 5, then reaches commit where the crash occurs.
Since the crash occurs at T2 : commit, the commit record for T2 may be absent from the stable log (worst-case) or may be present (best-case). Robust recovery typically assumes it is not safe to treat T2 as committed unless the commit record is stable.
Thus, recovery treats T2 as uncommitted and performs undo of its updates.
T2update was:B := B + 5(based on the current value ofBat the time of execution; initialBis 0)- Undo will restore
Bback to the pre-T2value, i.e., subtract the +5 effect.
Net effect: B becomes 0 after recovery.
This is the crucial behavior: even if B := B + 5 is already on disk because updates were immediate, undo removes it.
undo.
3) Transaction T3
T3 is not committed at crash time (its commit is after crash).
Its updates:
C := C + 5twice
Starting from initialC=0, it would have producedC=10if not rolled back.
Recovery will undo all T3 effects, returning:
Cback to0.
compensation log record.
4) Transaction T4
T4 is also uncommitted at crash time.
Its updates:
A := A + 5D := D + 5
So if those updates reached disk before crash, they would have temporarily changed:
Aby +5Dby +5
But recovery will undo them, returning:
Ato whatever state remains after committed transactions onlyDback to0
Net effect: A retains only committed contributions (from T1), and D becomes 0.
Database values after recovery (crash at T2 commit)
Assuming recovery treats T2 as uncommitted (standard safe assumption when crash occurs at/around commit).
What the log-based recovery performs after the crash
- 1Step 1
Mark
T1as committed (its commit already occurred earlier), and treatT2(crash at its commit) as uncommitted;T3andT4are uncommitted because their commit statements occur after the crash. - 2Step 2
Reapply
T1’s update toAusing its log record(s), ensuringA := A + 5is reflected on stable pages. - 3Step 3
For
T2,T3, andT4, reverse their effects using the before-images/undo information in the log so that their partial changes are removed from pages. - 4Step 4
After undo finishes for uncommitted transactions and redo is applied for committed ones, the database corresponds to a state consistent with committed work only.
Pro Tip
With immediate modification, you must expect uncommitted updates to appear in the database at crash time; recovery still guarantees correctness via undo using the log. So the presence of an on-disk change does not mean the transaction committed.
Warning about `T2 : commit` timing
If the system crashes exactly at T2 : commit, you cannot reliably assume the commit record is stable. The conservative (and typical in exam settings) assumption is: T2 is treated as uncommitted, so its B := B + 5 is undone.
Consolidated final answer (net effect)
Given the above, after recovery:
A: onlyT1’s committed update remains
B:T2is treated as uncommitted at crash-at-commit, so its update is undone
C:T3is uncommitted, undo both updates
D:T4is uncommitted, undo
Therefore, the post-recovery database state is:
Edge cases & how the answer would change
Knowledge Check
A failure occurs at T2 : commit under immediate database modification. Which transactions are treated as committed during recovery in the conservative (typical) assumption?