Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Recovery Control (Chapter 17) Redo Logging CS4432: Database Systems II.

Similar presentations


Presentation on theme: "1 Recovery Control (Chapter 17) Redo Logging CS4432: Database Systems II."— Presentation transcript:

1 1 Recovery Control (Chapter 17) Redo Logging CS4432: Database Systems II

2 Disadvantage of Undo Logging This forces the DBMS to make many I/Os –Especially for small transactions 2 Cannot consider T committed and write this log rec until all T’s updates are written to disk

3 Rules for Redo Logging 3 For every write action, generate redo log record. – : Transaction T has modified X and new value is v Flush log at commit. Before modifying any value X on disk (Output(X)) –All log records of T (including commit) must be on disk before X is modified on disk Write log record after DB modifications have been written to disk.

4 Example 4 That is the new value No Output can be done until the Log is flushed to disk containing all T’s records and its

5 Redo Logging: Recovery Rules Check the log T with no –Can be ignored (do nothing) –Because T did not write anything to disk T with –Can be ignored (do nothing) –Because T wrote all its data to disk T with but no –Redo its actions (Start from and move forward) 5

6 Example 6  is not written on disk yet  Do Nothing

7 Example 7  is on disk, No  Redo T  Copy 16 to A  Copy 16 to B  Add to log and write to disk

8 Disadvantage of Redo Logging Delayed I/Os –Needs to keep all modified blocks in memory until T commits Bad especially for large transactions 8 Cannot write anything of T’s updates to disk until it commits.

9 9 Next: Undo/Redo Logging & Checkpoints

10 Undo/Redo Logging Stores more data in its log to offer more flexibility –Log record: 10 Transation Ti has updated X, the old value is oldVal and the new value is newVal In Recovery –Some transactions will be undone (incomplete ones) –Some transactions will be redone (complete ones)

11 Undo/Redo Logging For every write action, generate log record. – : Transaction T has modified X from old to new Before writing any object X to disk (Output(x)), its log record must be on disk 11 Yes A block containing X can now move to disk either before or after the commit

12 Example 12 At this point it is allowed to write either A or B to disk At this point T is considered completed although some of its data are not written yet to disk

13 Undo/Redo Logging: Recovery Rules If is in the log (on disk) –It means T is be completed –Some data may be written to disk, others may not If is not in the log (not on disk) –Still some data may be written to disk 13 Redo T (top-down)Undo T (bottom-up)

14 14 Redo Phase 1.Decide on which transactions to redo (can be many) 2.Take one forward pass (top-down) and redo them Undo/Redo Logging: Recovery Rules Undo Phase 1.Decide on which transactions to undo (can be many) 2.Take one backward pass (bottom-up) to undo them

15 15 Example crash Redo T2Undo T1, T3 Log on disk

16 Example 16 The record is not written yet to disk T is considered incomplete and will be undone - Return B to 8 - Return A to 8

17 Example 17 The record is on disk T is considered complete and will be redone - Copy 16 to A - Copy 16 to B

18 18 Recovery Control (Chapter 17) Checkpointing CS4432: Database Systems II

19 Checkpointing When restart from a crash –Recovery Manager needs to check the entire log to decide Which Trnx to undo (if Undo logging) Which Trnx to redo (if Redo logging) Which Trnx ro undo/redo (if Undo/Redo logging) Checking the entire log is very expensive Need points before which everything is guaranteed to be correct –These points are called “checkpoints” 19

20 20 Recovery is very, very SLOW ! log: FirstT1 wrote A,BLast RecordCommitted a year agoRecord (1 year ago)--> STILL, Need to redo after crash!!... Crash

21 21 Solution: Checkpoint Periodically: (1) Do not accept new transactions (2) Wait until all transactions finish (commit or abort) (3) Flush all log records to disk (log) (4) Flush all buffers to disk (DB) (5) Write “ checkpoint ” record on disk (log) (6) Resume transaction processing simple checkpoint

22 22 Example: what to do at recovery? Undo or Redo log (disk): Checkpoint Crash... Check only to the last checkpoint

23 23 More Complex Checkpointing Mechanism The simple mechanism does not accept new transactions during checkpointing May not be acceptable for some systems A more complex mechanism allows accepting new transactions while doing the checkpointing

24 We Are Done…


Download ppt "1 Recovery Control (Chapter 17) Redo Logging CS4432: Database Systems II."

Similar presentations


Ads by Google