Q 16.1 Explain why log records for transactions on the undo-list must be processed in reverse order, whereas redo is performed in a forward direction.
Answer:
- Undo (Reverse Order): Undo operations restore the old value of data items using update log records like
<T_i, X_j, V_1, V_2>. If a transaction modified the same item multiple times (e.g., value changed from ), processing the log records in reverse order ensures that the original value () is restored correctly (). Processing in forward order would incorrectly restore an intermediate value (). - Redo (Forward Order): Redo operations apply the new value () from update log records. Processing the log in forward order ensures that the history of updates is replayed exactly as it happened (this is called repeating history). This guarantees that the database reflects the correct final state for all committed transactions and completed rollbacks, applying updates in the sequence they originally occurred.
Q 16.2 Explain the purpose of the checkpoint mechanism. How often should checkpoints be performed? How does the frequency of checkpoints affect:
- System performance when no failure occurs?
- The time it takes to recover from a system crash?
- The time it takes to recover from a media (disk) failure?
Answer:
Purpose: The checkpoint mechanism reduces the overhead associated with recovery after a system crash. It limits the amount of log that needs to be searched and processed during recovery. By periodically recording active transactions and ensuring modified buffer blocks are written to disk, it avoids reprocessing the entire log and unnecessarily redoing updates already reflected in the database (Section 16.3.6).
Frequency Effects:
- System performance (no failure): More frequent checkpoints slightly decrease performance during normal operation. This is because checkpointing involves overhead: writing log records from memory to stable storage, flushing all modified buffer blocks to disk, and temporarily pausing some update actions (in the simple scheme described).
- System Crash Recovery Time: More frequent checkpoints significantly decrease the time needed to recover from a system crash. Recovery only needs to process the log starting from the last checkpoint record, reducing the number of undo and redo operations required.
- Media (Disk) Failure Recovery Time: Checkpoints, as described for system crash recovery (Section 16.3.6), have no direct effect on the time to recover from media failure. Media failure recovery relies on archival backups (like full database dumps) and the logs taken since the last backup (mentioned implicitly in Sections 16.2.1, 16.3.1). Checkpoint frequency doesn’t change this dependency.