/    /  DBMS- Database Modification

Database Modification

 

There are two types of modification :

  • Deferred-modification
  • Immediate-modification

 

There are two more types of log records :

(a) Undo: It uses a log record and sets the data item specified in the log record to the old value.

(b) Redo: It uses a log record and sets the data item specified in the log record to the new value.

Example-1:  Consider the following transactions :

       Let T1 is a transaction that transfers  50 from A to B.

       Let T2 is a transaction that withdraws 100 from C.

                        T1 : read(A);

                                    A = A -50;

                                    write(A)

                                    read(B);

                                    B = B + 50;

                                     write(B);

 

                         T2 : read(C);

                                   C = C – 100;

                                     write(C);

 

 

LOG  File :                < T1 start >

                         <T1, A, 1000, 950>

                         <T2, B, 2000,2050>

                         < T1  commit>

                         <T2  start>

                         <T2, C, 700,600>

                         < T2  commit >

 

State of System Log and Database :

LOG ➡                      ⬅ database ➡

                

 

< T1 start >

                 <T1, A, 1000, 950>

                 <T2, B, 2000,2050>

                          A= 950

                          B = 20

< T1  commit>

                 <T2  start>

                 <T2, C, 700,600>

                         C = 600

                 < T2  commit >

 

We will see now if the system crash occurs at various places and what is the remedy for it.

 

After a system crash has occurred, the system consults the log to determine which transactions need to be redone, and which need to be undone so as to ensure atomicity.

i) Transaction Ti needs to be undone if the log contains the record <Ti start> but does not contain either the record <Ti commit> or the record <Ti abort>.

ii) Transaction Ti needs to be redone, if the log contains the record <Ti start> and either the record <Ti commit> or the record <Ti abort>.

 

 

Reference Link

Database Modification