Crash Recovery

Document Sample
Crash Recovery Powered By Docstoc
					Crash Recovery

          Chapter 22.3
   Main memory locations which are used
    to transfer data to and from secondary
   Dirty bit and dirty page
       Dirty bit and pinCount are initially set to 0
   Replacement strategies:
       First-in-first-out (FIFO)
       Least recently used (LRU)

                    Marina G. Erechtchoukova        2
Buffer management
   A steal policy: buffer manager writes a
    buffer to disk before a transaction
   Alternative policy: no-steal
   A force policy: all pages updated by a
    transaction are immediately written to
    disk when the transaction commits.
   Alternative policy: no-force

               Marina G. Erechtchoukova   3
Recovery Facilities
   Backup mechanism
   Logging
   Checkpoints
   Recovery algorithms

               Marina G. Erechtchoukova   4
The Log
   History of actions executed by the
   Stable storage
   Log tail
   Actions are recorded in chronological

                Marina G. Erechtchoukova    5
Log Sequence Number
    Monotonically increasing order
    Every page (object) contains
    PageLSN - the most recent LSN
     from the log

               Marina G. Erechtchoukova   6
Actions recorded to the Log
   Start
   Updating an object:
       Update record is appended to the log tail
       pageLSN is set to the current LSN
   Commit:
       Commit record is appended to the log
       Log tail is written to stable storage

                   Marina G. Erechtchoukova         7
Actions recorded to the Log
   Abort:
       Abort log record is appended to the log
       Undo is initiated
   End
   Undoing updates:
       After the action described in update log
        record is undone, a compensation log
        record (CLR) is appended to the log.

                   Marina G. Erechtchoukova        8
Update Log Record
   Common fields for all log records:
       LSN, prevLSN, transID, type
   Fields for update records only:
       PageID
       Length of changes in bytes
       Offset (start byte)
       Before-image
       After-image

                  Marina G. Erechtchoukova   9
Compensation Log Record
   Is written just before the action
    recorded in Update log record is
   The same fields as for Update record
   Field undonextLSN:
       LSN from prevLSN of correspondent
        Update log record

                  Marina G. Erechtchoukova   10
The Write-Ahead Log Protocol
       All Update log records must be written
        to stable storage first
       Log records:
         Transaction records
         Systems records

                   Marina G. Erechtchoukova   11
        A point of synchronization between
         database and transaction log
        All buffers are force-written to secondary
        Checkpoints in AREIS:
    1.     Begin_checkpoint record
    2.     End_checkpoint record
    3.     Master record holds LSN of the
           begin_checkpoint record

                     Marina G. Erechtchoukova         12
Recovery Using Deferred Update
Updates are not written to the database
  until the transaction T commits
 T starts:

       Start log record
   T commits:
       Commit log record;
       Log tail is force-written to disk;
       Updates are implemented

                      Marina G. Erechtchoukova   13
Recovery Using Deferred Update
   T aborts:
       Abort log record;
       Ignore the log records related to T
   Recovery after the crash:
       Most recent checkpoint
       Transactions with Start and Commit log records
        are redone
       Transactions with Start and Abort log records are
       Transactions that have neither Commit nor Abort
        log records receive Abort log records
                     Marina G. Erechtchoukova          14
Recovery Using Immediate Update
 Updates are written to the database as they
  T starts:
        Start log record
    T writes:
        Update log record;
        Update is written to the buffer;
        Update is applied to the database when the buffer
         content is transferred to secondary storage
    T commits:
        Commit log record

                      Marina G. Erechtchoukova         15
Recovery Using Immediate
Update (cont…)
   T aborts:
       Updates are undone in reverse order
   Recovery after the crash:
       Most recent checkpoint
       Transactions with Start and Commit log
        records are redone
       Transactions with Start log record that
        don’t have Commit log record are undone

                  Marina G. Erechtchoukova    16
     Recovery (Example 10)


                              tc                    tf

                         Marina G. Erechtchoukova        17
   Algorithm for Recovery and Isolation
    Exploiting Semantics
   Works with steal, no-force policies
   Three main phases:
       Analysis
       Redo
       Undo

                   Marina G. Erechtchoukova   18
Basic Principles
   Write-ahead logging
   Repeating history during Redo
   Logging of all changes during
    Undo phase

               Marina G. Erechtchoukova   19
Analysis Phase
   Scan log from the checkpoint to the
   Main goal:
       To determine the point in the log at
        which to start the Redo step
       To determine dirty pages at the
        moment of the crash
       To identify active transactions at the
        time of the crash

                   Marina G. Erechtchoukova      20
Analysis Step Result
   Transaction Table contains accurate list
    of transactions active at the moment of
    the crash
    (actions must be undone)
   Dirty Page Table contains list of
    modified pages that must be recorded
    to secondary storage
    (actions must be redone)

                 Marina G. Erechtchoukova   21
Redo Phase
   Repeating history paradigm
   Redo(Redo(A)) = Redo(A)
   Redo actions are recorded to the log
   The result:
       The database is brought to the state as
        before the crash

                   Marina G. Erechtchoukova       22
Undo Phase
   Scans backward from the end of the
   Undo(Undo(A)) = Undo(A)
   For every Undo action the CLR is
    added to the log
   Removes all changes caused by
    incomplete transactions

               Marina G. Erechtchoukova   23

Shared By: