Page: 5 – Concurrency Control & Commit

Concurrency + Recovery

  • Rule: Once a txn modifies data, no other txn can until it commits/aborts.

  • Ensured by Strict 2PL (Two-Phase Locking).

Commit

  • Txn is committed when commit log is written to stable storage.

  • Data blocks themselves may be flushed later (optimization).


Page: 6 – Redo & Undo from Log

  • redo(Ti) → apply new values of Ti.

  • undo(Ti) → restore old values of Ti.

Crash Cases:

  • ⟨start⟩ but no ⟨commit/abort⟩ → Undo.

  • ⟨start⟩ and ⟨commit⟩ → Redo.


Page: 7 – Checkpoints

Why? → Without checkpoints, recovery scans whole log = slow.

Checkpoint steps:

  1. Write all in-memory logs → disk.

  2. Write all dirty buffers → disk.

  3. Write <checkpoint L> where L = list of active txns.

During Recovery:

  • Only check txns active at last checkpoint or started later.

  • Saves time!


Page: 8 – Recovery Algorithm

Two phases after crash:

  1. Redo Phase

    • Scan log forward from last checkpoint.

    • Redo all updates.

    • Maintain an undo-list (txns not finished yet).

  2. Undo Phase

    • Scan backward for txns in undo-list.

    • Undo their actions, log compensation records.

    • Write <Ti abort> when done.

Repeating History Rule

  • Redo everything since checkpoint (even undone actions).

  • Simple + correct.

Updated on