Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 ICS 214A: Database Management Systems Fall 2002 Lecture 17: Checkpoints Professor Chen Li.

Similar presentations


Presentation on theme: "1 ICS 214A: Database Management Systems Fall 2002 Lecture 17: Checkpoints Professor Chen Li."— Presentation transcript:

1 1 ICS 214A: Database Management Systems Fall 2002 Lecture 17: Checkpoints Professor Chen Li

2 ICS214ANotes 172 Recovery is very, very SLOW ! Undo log: First RecordLast Record (1 year ago) We do not want to rescan all the log records! Some of them can be removed.... Crash

3 ICS214ANotes 173 Solution: Checkpoint Simple Version Periodically: (1) Do not accept new transactions (“quiescent”) (2) Wait until all current transactions finish (3) Flush all log records to disk (4) Flush all data buffers to disk (5) Write log record and flush the log (6) Resume accepting transactions

4 ICS214ANotes 174 Example: Undo log, quiescent ckpt Log:  Do a checkpoint Wait until both T1 and T2 finish (commit or abort); Then flush the data and log, and write to the log. Final Log …

5 ICS214ANotes 175 Recovery: Undo log, quiescent ckpt Log after a crash: Scan the log backwards from the end and identify incomplete transactions Once see a record, ignore record before this –Why? All transactions before this ckpt must have finished. Other operations same as before Example: –T3 is the only incomplete transaction –Undo F and E. Write

6 ICS214ANotes 176 Nonquiescent checkpoint (undo) We don’t want the system to “halt” to do a checkpoint How to accept xacts during a checkpoint? –Write (flush) log record, where T1,…,Tk are active (not finished) transactions. –Wait until them to finish (complete and abort). Meanwhile, accept new transactions. –After these k transaction complete, write (flush) a log record.

7 ICS214ANotes 177 Ex: Undo log, nonquiescent ckpt Undo Log:  Start checkpointing  continue  continue, accept new xacts, until T1 and T2 complete  end checkpointing

8 ICS214ANotes 178 Recovery: Undo log, nonquiescent ckpt Scan the log backwards from the end Case 1: meet a first –Then all incomplete xacts began after the previous log record –Thus we can scan backwards until the previous log record –Ignore log before this record Ex: –T3 is the only incomplete xact, and should be undone –Restore data element F back to 30.

9 ICS214ANotes 179 Recovery: Undo log, nonquiescent ckpt case 2 Scan the log backwards from the end Case 2: meet a first –Then all incomplete xacts include: Those incomplete xacts we met before this log record; and Those of (T1,…,Tk) that are incomplete –Thus we need to scan to the start of the earliest incomplete xact –Discard the previous log records –Undo incomplete xacts Ex: –Incomplete xacts: (T2, T3) T1 is complete! –Scan until the start of T2 (earliest)

10 ICS214ANotes 1710 Improvement Use pointers to chain together the log records of the same xact Then we can follow the chain to find the “start” record of this xact.

11 ICS214ANotes 1711 General rule: Undo log, nonquiescent ckpt Once an record has been written to disk, we can delete the log prior to the previous record

12 ICS214ANotes 1712 Next: checkpoint in Redo Logging

13 ICS214ANotes 1713 Complications For a xact whose log record is written on disk, –its changed data elements can be copied to disk much later Thus, between a and an –We must write to disk all DB elements that have been modified by committed xacts but not yet written to disk –Need to keep track of all the dirty buffers We can complete the ckpt without waiting for the active xacts (not completed) to complete (commit or abort), since they are not allowed to write their pages to disk at that time anyway

14 ICS214ANotes 1714 Quiescent checkpoint (redo) Write (flush) log record, where T1,…,Tk are active (uncommitted) xacts. Write to disk all DB elements that are written to buffers but not yet to disk by xacts that had already committed when the record was written to the log Write (flush) a log record.

15 ICS214ANotes 1715 Ex: redo, checkpoint, nonquiescent Redo Log:  Start checkpoint  continue  continue, accept new xacts, make sure A=5 by T1 is on disk  end checkpoint

16 ICS214ANotes 1716 Recovery: redo, nonquiescent (case 1) Redo Log: Search backwards the log Case 1: is seen before –All xacts committed before have their data element changes on disk. These xacts can be ignored –Xacts T1,…,Tk and those new xacts after that have committed need to be redone Find the earliest of the records Can use pointers to improve the performance Ex: –T2 and T3 need to be considered –Since both have “COMMIT” records  need to be redone

17 ICS214ANotes 1717 Recovery: redo, nonquiescent (case 1) Redo Log: Ex: –T2 and T3 need to be considered –Since T2 has a “COMMIT” records, it needs to be redone –T3 can be ignored

18 ICS214ANotes 1718 Recovery: redo, nonquiescent (case 2) Redo Log: … … Search backwards the log Case 2: is seen before –Not sure if xacts prior to this has their data element changes on disk. –Need to find the previous –Redo those committed xacts that start after the previous or among those Si’s Ex: –Look for the previous –T0 and T1 are the committed xacts  need to be redone –T2 and T3 are ignored

19 ICS214ANotes 1719 Next: Redo/Undo logging


Download ppt "1 ICS 214A: Database Management Systems Fall 2002 Lecture 17: Checkpoints Professor Chen Li."

Similar presentations


Ads by Google