Understand how transaction logs are used to ensure atomicity and durability.
Log-Based Recovery is the most common technique used by database systems to ensure the ACID properties of atomicity and durability in the face of failures. The core of this method is the maintenance of a sequential log file, stored on stable storage like a hard disk. This log file contains a record for every single operation that modifies the database. Each log record typically includes the transaction ID, the type of operation (e.g., write), the data item being modified, its old value (before image), and its new value (after image). The log also records the start, commit, and abort events for each transaction. A critical rule is the 'write-ahead logging' (WAL) protocol: before a data modification is written to the actual database on disk, the corresponding log record must first be written to the log file on disk. This ensures that even if the system crashes during the database write, the log contains the information needed to fix it. After a crash, the recovery manager analyzes the log. For any transaction that has a 'commit' record in the log, its changes are 'redone' to ensure they are on disk (durability). For any transaction that was active but does not have a 'commit' record, its changes are 'undone' by using the 'before image' values in the log, thus ensuring atomicity. This undo/redo process guarantees that the database can be restored to a consistent state.