lect(10)Crash Recovery part(2) (1).pptx
Document Details
Uploaded by StylishSpessartine
جامعة العلوم والتقانة
Tags
Full Transcript
Database Management Systems Crash Recovery part(2) Chapter 20 Checkpointing Periodically, the DBMS creates a checkpoint, in order to minimize the time taken to recover in the event of a system crash. Write to log: – begin_checkpoint record: Indicates when chkpt began. –...
Database Management Systems Crash Recovery part(2) Chapter 20 Checkpointing Periodically, the DBMS creates a checkpoint, in order to minimize the time taken to recover in the event of a system crash. Write to log: – begin_checkpoint record: Indicates when chkpt began. – end_checkpoint record: Contains current Xact table and dirty page table. – Store LSN of chkpt record in a safe place (master record). The Big Picture: What’s Stored Where Simple Transaction Abort For now, consider an explicit abort of a Xact. – No crash involved. We want to “play back” the log in reverse order, UNDOing updates. – Get lastLSN of Xact from Xact table. – Can follow chain of log records backward via the prevLSN field. – Before starting UNDO, write an Abort log record. For recovering from crash during UNDO! Abort, cont. Before restoring old value of a page, write a CLR: – You continue logging while you UNDO!! – CLR has one extra field: undonextLSN Points to the next LSN to undo (i.e. the prevLSN of the record we’re currently undoing). – CLRs never Undone (but they might be Redone when repeating history: guarantees Atomicity!) At end of UNDO, write an “end” log record. Transaction Commit Write commit record to log. All log records up to Xact’s lastLSN are flushed. – Guarantees that flushedLSN ≥lastLSN. Commit() returns. Write end record to log. Crash Recovery: Big Picture Recovery: The Analysis Phase Scan log forward from checkpoint. − End record: Remove Xact from Xact table. − Other records: Add Xact to Xact table, set lastLSN=LSN, change Xact status on commit. − Update record: If P not in Dirty Page Table, Add P to D.P.T., set its recLSN=LSN. Recovery: The REDO Phase We repeat History to reconstruct state at crash: – Reapply all updates (even of aborted Xacts!), redo CLRs. Scan forward from log rec containing smallest recLSN in D.P.T. For each CLR or update log recLSN, REDO the action unless: – Affected page is not in the Dirty Page Table, or – Affected page is in D.P.T., but has recLSN > LSN, or – pageLSN (in DB) ≥ LSN. To REDO an action: – Reapply logged action. – Set pageLSN to LSN. No additional logging! Recovery: The UNDO Phase ToUndo={ l | l a lastLSNof a “loser” Xact} Repeat: – Choose largest LSN among ToUndo. – If this LSN is a CLR and undonextLSN==NULL Write an End record for this Xact. – If this LSN is a CLR, and undonextLSN != NULL Add undonextLSN to ToUndo – Else this LSN is an update. Undo the update, write a CLR, add prevLSN to ToUndo. Until ToUndo is empty. Example of Recovery The End