Explain the UNDO/REDO recovery algorithm

Undo/Redo is a database transaction log for handling transaction crash recovery. This algorithm stores all the values and changes made during transactions in a separate memory in case of failure or crash. It utilizes the stored value to restore the loss due to failure.

This algorithm is a combination of two approaches

UNDO: It stands for undone and restores the data value items that are updated by any transaction to their previous value.

REDO: It stands for re-done and it set the value of all the data updated by the transaction to the new value.

Now let’s understand the algorithm using a simple example

Let a transaction T perform the following set of operations on the data items X, Y, and Z.

Update X=X+Y
Update Y=Y-100

Now, if, during the transaction execution, the statement “Update X+Y” suffers from failure, then the UNDO operation will perform, and it restores the value of “X” and then starts the transaction again.

Suppose the statement “commit” fails during the transaction execution. In that case, the REDO operation will be performed, which again tries to execute the statement commit and reset the new value of X.

The UNDO/REDO recovery algorithm is a very flexible algorithm but the only disadvantage it faces is that it requires more storage to store both old as well as newly updated values.