LOG BASED RECOVERY
Log-based recovery is a critical mechanism in a Database Management System (DBMS) to ensure data integrity and consistency in the event of failures.
To ensure atomicity, modifications made by an aborted transaction should not be visible in the database, while those made by a committed transaction should be. To achieve this, the user must first write stable storage information detailing the modifications, without directly altering the database.
This information will help ensure that all changes made by committed transactions are accurately reflected in the database.
Every operation performed on the database is recorded in the log. Before making any modifications to the database, an updated log record is created to document the change. An update log record, represented as <Ti, Xj, V1, V2>, includes the following fields:
Two main types of logs:
This rule ensures that all modifications are logged before they are applied to the database. Specifically, it requires that:
Periodic snapshots of the database state, which help reduce the amount of log data that must be processed during recovery. During recovery, the system only needs to consider transactions that were active at the time of the last checkpoint.
In this method, updates are not applied to the database until the transaction reaches its commit point.
The log must contain a record of all changes so that, in the event of a failure, the changes can be redone from the log.
Updates are applied to the database as soon as they are made, but the changes are also logged so they can be undone if necessary.
Both redo and undo information is maintained in the log. This approach allows for more immediate reflection of changes but requires more sophisticated logging and recovery mechanisms.
Determine the state of the transactions at the time of failure. Identify which transactions were committed, which were in progress, and which were aborted.
Replay the logged operations for all committed transactions to ensure that all their changes are reflected in the database.
The redo operation starts from the last checkpoint and applies all the redo log entries to the database.
Reverse the changes of all transactions that were active at the time of the failure but did not commit.
The undo operation involves reading the undo log entries and restoring the database to the state before those transactions began.
Consider a transaction T1 that modifies a data item X from value 10 to 20. The log entries might look like this:
In the event of a failure, the recovery process would: