In the previous chapters, you learned how to identify a recoverable schedule and what kind of failures can occur in DBMS. In this chapter, you will learn how to recover a failed transaction using Log-based recovery in DBMS. When a transaction fails, it is important to rollback the transaction so that changes made by failed transaction doesn’t store in the database, this is important to maintain the integrity of database.
What is log-based recovery in DBMS?
- As the name suggests, log is a sequence of records that is maintained in a stable storage devices to note down all the changes made by transactions in a sequential manner. This log is used to recover the transaction in case of failure.
- Any operation performed by transaction on database is recorded in the log.
- It is important to record the log before the actual operation performed on the database, this make sure that if an operation fail, it is already recorded in the log.
How the logs are maintained?
Let’s take an example to understand the log-based recovery in DBMS:
A transaction T1 is modifying the Department of an employee, for this operation, the following log is maintained:
Log entry to mark the start of the transaction:
<T1, Start>
Just before the transaction modifies the department of the employee from “Sales” To “Marketing”, the following log is maintained:
<T1, Department, 'Sales', 'Marketing' >
Log entry to mark the successful end of the transaction:
<T1, Commit>
Logs for different database modification approaches
There are two database modification approaches used by the transactions. Here we will learn how the logs are maintained for each approach:
1. Deferred Database Modification
In this approach, the transaction does not commit the changes the database, until it is completed successfully.
In this approach, all the logs are created at once and stored in the database.
2. Immediate Database Modification
In this approach, the transaction make change immediately after an operation is performed by the transaction.
In this approach, logs are recorded just before the transaction is going to perform an operation in database.
Recovery using Log Records
In case of a transaction failure, the log is referenced to recover the transaction and rollback or redone all the changes done by the transaction.
- If the log contains the entry
<Tn, Start>
and<Tn, Commit>
or<Tn, Start>
and<Tn, Abort>
then the transaction Tn needs to be redone based on the log entries for each operation recorded in the log. - If the log contains the entry
<Tn, Start>
but doesn’t contain an entry for<Tn, Commit>
or<Tn, Abort>
then the transaction needs to be rolled back.
Leave a Reply