Rollback until log file empty 1. C2 - T2 on committed list 2. (W,2,C,100,50) C2 on list, do nothing 3. (S,2) T2 no longer active 4. (W,1,A,50,20) UNDO this update, T1not on the committed list 5. (S1) T1 no longer active
How to recover cont’d
Rollforward 6. S1 - no action 7. (W,1,A,50,20) T1 uncommitted - noaction 8. (S,2) no action 9. (W,2,C,100,50) Redo update10. (C,2) no action
11. done
Durability
•When write log buffer to log file - read afterwrite protocol in performing disk writesguarantees commit fails if error in diskwrite.
•When successful write, durability (write to2 different disks for extra durabilityguarantee)
Problems
•Potential problems with log files 1) durability - commits successful onlyonce log file written on disk 2) atomicity - Be sure dirty pages of datanot written to disk before log entry (iffailure and log entry not written?) else willnever UNDO or REDO if have to
Solutions
Can modify LRU replacement to ensure data notwritten to disk before log file
1. updated data page not written to disk untilcommit - no UNDO processing ever, no beforeimages needed in logs but what if lot ofupdates? can't keep all in memory
2. write ahead log guarantee (WAL) logsequence number - every log entry keeps trackof smallest LSN written to log file since lastwrite, keep track of updates to data pages(pgmax) cannot write page to disk unless pgmax < LSN
Recovery
•Recovery Checkpoints used so only have to rollback to a certainpoint
•T's short-lived (take a few seconds)therefore rollback is quick - only a few T'sactive that need to be UNDONE
• rollforward takes longer - many T's toREDO, keep track of start T's, etc.
•3 approaches for checkpoints
Commit consistent
1. Commit consistent -needed when count of logevents exceeds some limit Enter checkpoint state:
a) no new T's start until checkpoint complete
b) DB processing continues until all existing T'scommit and log entries on disk
c) current log buffer written to log file, all dirty pageswritten to disk
d) when a)-c) complete, special log entry CKPTentered ( these steps are the same as an orderly shutdownof the system )
Commit consistent cont’d
•To recover: Rollback until CKPT, then REDOcommitted since CKPT
•Problems
– But what if some transactions are long-lived?
– must wait a long-time for them to finish, withno new T's active
Cache-consistent
2. Cache-consistent checkpoint - aim toreduce time if long transactions
a) No new T's permitted to start
b) existing T's cannot start any new ops
c) current log buffer written to disk, all dirtydata pages to disk
d) log entry (CKPT, list of active T's) written onlog file on disk
Cache-consistent cont’d
•To recover:
– must rollback past checkpoint
–rollback the same as for commit consistent,then keep rolling back until list in CKPT allundone (if not committed yet)
– Rollback - given the list of active T's, removethose committed then left with a list of T's toUNDO
– Rollforward - REDO all updates by committedT's start at first op after last CKPT