Recovarability using log files

Consider the following log sequence of two transactions on a bank account, with  initial balance 12000,  that transfer 2000 to a mortgage payment and then apply  a 5% interest

1. T1 start
2. T1 B old=1200 new=10000
3. T1 M old=0 new=2000
4. T1 commit
5. T2 start
6. T2 B old=10000 new=10500
7. T2 commit

.    

Suppose the database system crashes just before log record 7 is written. When  the system is restarted, which one statement is true of the recovery procedure?

(A) We must redo log record 6 to set B to 10500

(B) We must undo log record 6 to set B to 10000 and then redo log records 2   and 3 

(C) We need not redo log records 2 and 3 because transaction T1 has committed

(D) We can apply redo and undo operations in arbitrary order because they are idempotent. 

Answer

The log file given in question is example of  type deferred update mode. In this case, old value and new value of a variable is stored. If a transactions is not committed, its operations need to be undone and if a transaction is committed, its operations need to be redone. But first we need to undone the uncommitted transaction and then redone the committed transaction. Because if we undo the uncommitted transaction later, the value updated by committed transaction may be lost. So the correct option is B.

1Comment
Mohit Lalwani @monty12
27 Jun 2016 08:48 pm

T1 is commit before crash and T2 not commit because of crash(7);
and check point  is not use;
there is commit T1 so only 2, 3 redo;
no commit of T2 because of crash only 6 undo;