1 / 22

Database Recovery Techniques

Database Recovery Techniques. Transaction failures Logical errors : transaction cannot complete due to some internal error conditions (bad input, data not found, overflow, etc.) System errors : the database system must terminate an active transaction due to an error condition (e.g., deadlock).

dbabcock
Télécharger la présentation

Database Recovery Techniques

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Database Recovery Techniques

  2. Transaction failures Logical errors: transaction cannot complete due to some internal error conditions (bad input, data not found, overflow, etc.) System errors: the database system must terminate an active transaction due to an error condition (e.g., deadlock). System crash: a power failure or other hardware/software failure causes the system to crash and the loss of the content of volatile storage (in RAM) and bring transaction processing to a halt. Fail-stop assumption: non-volatile storage (hard disk) contents are assumed to be not corrupted by system crash Database systems have numerous integrity checks to prevent corruption of disk data Disk failure: A disk block loses its content as a result of either a head crash or failure during a data transfer operation. Destruction is assumed to be detectable: disk drives use checksums to detect failures Failure Classification

  3. Recovery Algorithms • To determine how the system should recover from failures, we need to identify the failure modes of those devices storing data. • We can propose algorithms to ensure database consistency and transaction atomicity despite failures. • These are called Recovery Algorithms. • Recovery algorithms are techniques to ensure database consistency and transaction atomicityand durability despite failures • Recovery algorithms have two parts: • Actions taken during normal transaction processing to ensure enough information exists to recover from failures • Actions taken after a failure to recover the database contents to a state that ensures atomicity, consistency and durability

  4. Example of Data Access buffer Buffer Block A input(A) X A Buffer Block B Y output(B) B read(X) write(Y) disk x2 x1 y1 work area of T2 work area of T1 memory

  5. Log-Based Recovery

  6. Log-based recovery is the most widely used structure. The log is a sequence of log records, recording all update activities in the database. The Log is kept on stable storage An update log record represents a single database write operation. It has the following fields Transaction Identifier is the unique identifier of the transaction that performed the write operation Data Item Identifier is the unique identifier of the data item written. Typically, it is the location of the data item on the disk Old value is the value of the data item prior to its write. New value is the value that the data item will have after the write. Log-Based Recovery

  7. Other special log records exist to record significant events during transaction processing, such as: Starting a transaction: when transaction Tistarts, it registers itself by a log record <Tistart> Writing new values: Before Tiexecutes write(X), a log record <Ti, X, V1, V2>is written, where V1 is the value of X before the write, andV2is the value to be written to X. the Log record notes that Ti has performed a write on data item Xj . Xjhad value V1before the write, and will have value V2after the write. Committing a transaction: When Tifinishes its last statement, the log record <Ticommit> is written. Aborting a transaction: Transaction Ti has aborted <Ti abort>. We assume for now that log records are written directly to stable storage (that is, they are not buffered) Two approaches for modifying the database when using logs Deferred database modification Immediate database modification Log-Based Recovery

  8. Log-Based RecoveryDeferred Modification

  9. The deferred database modification scheme records all modifications to the log, but defers all the writes to after partial commit. Assume that transactions execute serially Transaction starts by writing <Tistart>record to log. A write(X) operation results in a log record <Ti, X, V>being written, where V is the new value for X Note: old value is not needed for this scheme The write is not performed on X at this time, but is deferred. When Tipartially commits, <Ticommit> is written to the log Finally, the log records are read and used to actually execute the previously deferred writes. Deferred Database Modification

  10. During recovery after a crash, a transaction needs to be redone if and only if both <Tistart> and <Ti commit> are there in the log. Redoing a transaction Ti(redoTi) sets the value of all data items updated by the transaction to the new values. Crashes can occur while the transaction is executing the original updates, or while recovery action is being taken example transactions T0and T1(T0executes before T1): T0: read (A) T1: read (C) A: - A - 50C:- C- 100 write (A)write (C) read (B) B:- B + 50 write (B) Deferred Database Modification

  11. Below we show the log as it appears at three instances of time. If log on stable storage at time of crash is as in case: (a) No redo actions need to be taken (b) redo(T0) must be performed since <T0 commit> is present (c) redo(T0) must be performed followed by redo(T1) since <T0commit> and <Ti commit> are present Deferred Database Modification

  12. Log-Based RecoveryImmediate Modification

  13. The immediate database modification scheme allows database updates of an uncommitted transaction to be made when the writes are issued. Since undoing a transaction may be needed, update logs must have both old value and new value Rule: The update record must be written to the log file before data item is actually written in the database The log record is output directly to stable storage Output of updated blocks (output (B)) can take place at any time before or after transaction commit. Order in which blocks are output to the disk can be different from the order in which they are written to the memory (see example). Immediate Database Modification

  14. Recovery procedure has two operations instead of one: undo(Ti) restores the value of all data items updated by Ti to their old values, going backwards from the last log record for Ti redo(Ti) sets the value of all data items updated by Tito the new values, going forward from the first log record for Ti Both operations must be idempotent That is, even if the operation is executed multiple times the effect is the same as if it is executed once Needed since operations may get re-executed during recovery When recovering after failure: Transaction Tineeds to be undone if the log contains the record <Tistart>, but does not contain the record <Ticommit>. Transaction Tineeds to be redone if the log contains both the record <Tistart> and the record <Ti commit>. Undo operations are performed first, then redo operations. Immediate Database Modification

  15. Below we show the log as it appears at three instances of time. Recovery actions in each case above are: (a) undo (T0): B is restored to 2000 and A to 1000. (b) undo (T1) and redo (T0): C is restored to 700, and then A and B are set to 950 and 2050 respectively. (c) redo (T0) and redo (T1): A and B are set to 950 and 2050 respectively. Then C is set to 600 Immediate DB Modification Recovery Example

  16. Checkpoints

  17. Problems in recovery procedure as discussed earlier : searching the entire log is time-consuming we might unnecessarily redo transactions which have already output their updates to the database. Reduce this effect: Streamline recovery procedure by periodically performing checkpointing Output all log records currently residing in main memory onto stable storage. Output all modified buffer blocks to the disk. Write a log record < checkpoint> onto stable storage. Checkpoints

  18. During recovery we need to consider only the most recent transaction Ti that started before the checkpoint, and transactions that started after Ti. Scan backwards from end of log to find the most recent <checkpoint> record Continue scanning backwards till a record <Ti start> is found. Need only consider the part of log the follows the start record. Earlier part of log can be ignored during recovery, and can be erased whenever desired. For all transactions (starting from Ti or later) with no <Ticommit>, execute undo(Ti).(Done only in case of immediate modification.) Scanning forward in the log, for all transactions starting from Tior later with a <Ticommit>, execute redo(Ti). Checkpoints

  19. T1 can be ignored (updates already output to disk due to checkpoint) T2 and T3 redone. T4 undone Example of Checkpoints Tf Tc T1 T2 T3 T4 system failure checkpoint

  20. Deferred Update • Start from the last checkpoint: • If a transaction has committed before checkpoint  Do nothing. • If a transaction has committed after checkpoint  Redo it. • If a transaction has not committed after checkpoint  Do nothing

  21. Immediate Update • Start from the last checkpoint: • If a transaction has committed before checkpoint Do nothing. • If a transaction has committed after checkpoint  Redo it. • If a transaction has not committed after checkpoint  Undo it

  22. The End of Chapter 

More Related