Page 195 - DCAP402_DCAO204_DATABASE MANAGEMENT SYSTEM_MANAGING DATABASE
P. 195

Database Management Systems/Managing Database




                    Notes          When recovering after failure:
                                   1.  Transaction T  needs to be undone if the log contains the record
                                                  i
                                       <T  start>, but does not contain the record <T  commit>.
                                          i                                 i
                                   2.  Transaction T  needs to be redone if the log contains both the record <T  start> and the
                                                   i                                              i
                                       record <T  commit>.
                                               i
                                   Undo operations are performed first, then redo operations.


                                          Example: Consider the log as it appears at three instances of time.
                                   <T  start>              <T  start>         <T  start>
                                     1                       1                  1
                                   <T , X 10000, 9000>     <T , X 10000, 9000>  <T , X 10000, 9000>
                                     1                       1                  1
                                   <T , Y 8000, 9000>      <T , Y 8000, 9000>  <T , Y 8000, 9000>
                                     1                       1                  1
                                                           <T , Commit>       <T , Commit>
                                                             1                  1
                                                           <T  start>         <T  start>
                                                             2                  2
                                                           <T  , Z 20000, 19000>  <T  , Z 20000, 19000>
                                                             2                  2
                                                                              <T , Commit>
                                                                                2
                                          (a)                        (b)             (c)
                                   Recovery actions in each case above are:
                                   1.  undo (T ): Y is restored to 8000 and X to 10000.
                                              1
                                   2.  undo (T ) and redo (T ): Z is restored to 20000, and then X and Y are set to 9000 and 9000
                                              2          1
                                       respectively.
                                   3.  redo (T ) and redo (T ): X and Y are set to 9000 and 9000 respectively. Then Z is set to 19000
                                             1          2
                                   Checkpoints

                                   The following problem occurs during recovery procedure:
                                   Searching the entire log is time-consuming as we are not aware of the consistency of the database
                                   after restart. Thus, we might unnecessarily redo transactions, which have already output their
                                   updates to the database.

                                   Thus, we can streamline recovery procedure by periodically performing check pointing. Check
                                   pointing involves:
                                   1.  Output of all the log records currently residing in the non-volatile memory onto stable
                                       storage.
                                   2.  Output all modified buffer blocks to the disk.
                                   3.  Write a log record < checkpoint> on a stable storage.

                                   During recovery we need to consider only the most recent transactions that started before the
                                   checkpoint and is not completed till, checkpoint and transactions started after check point. Scan
                                   backwards from end of log to find the most recent <checkpoint> record. Continue scanning
                                   backwards till a record <T  start> is found. Need only consider part of the log following above
                                                        i
                                   start record. The earlier part of the log may be ignored during recovery, and can be erased
                                   whenever desired. For all transactions (starting from  T  or later) with no <T  commit>, execute
                                                                               i                i
                                   undo (T  ). (Done only in case immediate modification scheme is used). Scanning forward in the
                                         i
                                   log, for all transactions starting from T  or later with a <T  commit>, execute redo(T ).
                                                                  i              i                    i





          188                               LOVELY PROFESSIONAL UNIVERSITY
   190   191   192   193   194   195   196   197   198   199   200