Logging and ARIES
ARIES Example LSNTypeTidPrevLSNData 1SOT1 2UP11A 3 12B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E WA,B CP WC WD WB WA WE CRASH Flush
ARIES Data Structures WA,B CP WC WD WB WA WE CRASH Flush lastLSNTID 11 xactionTable pgNorecLSN dirtyPgTable xactionTable dirtyPgTable Checkpoint PagepageLSN A? B? C? D? E? Disk lastLSNTID 21 lastLSNTID 31 lastLSNTID lastLSNTID 133 pgNorecLSN A2 B3 pgNorecLSN A2 B3 C6 PagepageLSN A2 B3 C6 D? E? pgNorecLSNpgNorecLSN D8 pgNorecLSN D8 B10 pgNorecLSN D8 B10 A11 pgNorecLSN D8 B10 A11 E13 xactionTable3 - 1 dirtyPgTableA - 2, B - 3
Crash Recovery Phases 1.Analysis –Find earliest useful log record –Rebuild xactionTable and dirtyPgTable –Determine winners & losers 2.Redo –Redo all updates, even from losers (“repeat history”) –Why? 3.Undo –Undo Losers
Analysis LSNTypeTidPrevLSNData 1SOT1 2UP11A 3 12B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E
Analysis LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E lastLSNTID 31 pgNorecLSN A2 B3 PagepageLSN A2 B3 C6 D? E? xactionTabledirtyPgTable Disk
Analysis LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E lastLSNTID pgNorecLSN A2 B3 PagepageLSN A2 B3 C6 D? E? xactionTabledirtyPgTable Disk
Analysis LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E lastLSNTID pgNorecLSN A2 B3 C6 PagepageLSN A2 B3 C6 D? E? xactionTabledirtyPgTable Disk
Analysis LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E lastLSNTID pgNorecLSN A2 B3 C6 PagepageLSN A2 B3 C6 D? E? xactionTabledirtyPgTable Disk
Analysis LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E lastLSNTID pgNorecLSN A2 B3 C6 D8 PagepageLSN A2 B3 C6 D? E? xactionTabledirtyPgTable Disk
Analysis LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E lastLSNTID 133 pgNorecLSN A2 B3 C6 D8 E13 PagepageLSN A2 B3 C6 D? E? xactionTable dirtyPgTable Disk Not the same as just before crash (note disk state)
Redo Where to begin? –Checkpoint? –Min(recLSN)! What to REDO? pgNorecLSN A2 B3 C6 D8 E13 dirtyPgTable PagepageLSN A2 B3 C6 D? E? Disk
Redo Example LSNTypeTidPrevLSNData 1SOT1 2UP12A 3 13B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E pgNorecLSN A2 B3 C6 D8 E13 Redo UNLESS Page is not in dirtyPgTable If LSN < recLSN If LSN <= pageLSN DirtyPgTable PagepageLSN A2 B3 C6 D? E? Disk
Redo Example LSNTypeTidPrevLSNData 1SOT1 2UP12A 3 13B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E pgNorecLSN A2 B3 C6 D8 E13 Redo UNLESS Page is not in dirtyPgTable If LSN < recLSN If LSN <= pageLSN DirtyPgTable PagepageLSN A2 B3 C6 D? E? Disk
Redo Example LSNTypeTidPrevLSNData 1SOT1 2UP12A 3 13B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E pgNorecLSN A2 B3 C6 D8 E13 Redo UNLESS Page is not in dirtyPgTable If LSN < recLSN If LSN <= pageLSN DirtyPgTable PagepageLSN A2 B3 C6 D? E? Disk
Redo Example LSNTypeTidPrevLSNData 1SOT1 2UP12A 3 13B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E pgNorecLSN A2 B3 C6 D8 E13 Redo UNLESS Page is not in dirtyPgTable If LSN < recLSN If LSN <= pageLSN DirtyPgTable PagepageLSN A2 B3 C6 D? E? Disk
Redo Example LSNTypeTidPrevLSNData 1SOT1 2UP12A 3 13B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E pgNorecLSN A2 B3 C6 D8 E13 Redo UNLESS Page is not in dirtyPgTable If LSN < recLSN If LSN <= pageLSN DirtyPgTable PagepageLSN A2 B3 C6 D? E? Disk
Redo Example LSNTypeTidPrevLSNData 1SOT1 2UP12A 3 13B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E pgNorecLSN A2 B3 C6 D8 E13 Redo UNLESS Page is not in dirtyPgTable If LSN < recLSN If LSN <= pageLSN DirtyPgTable PagepageLSN A2 B3 C6 D? E? Disk
Redo Example LSNTypeTidPrevLSNData 1SOT1 2UP12A 3 13B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E pgNorecLSN A2 B3 C6 D8 E13 Redo UNLESS Page is not in dirtyPgTable If LSN < recLSN If LSN <= pageLSN DirtyPgTable PagepageLSN A2 B3 C6 D? E? Disk Buffer/disk pages same as pre-crash
Undo Walk backwards, following prevLSNs to UNDO losers LSNTypeTidPrevLSNData 1SOT1 2UP11A 3 12B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E lastLSNTID 133 xactionTable
Undo Walk backwards, following prevLSNs to UNDO losers LSNTypeTidPrevLSNData 1SOT1 2UP11A 3 12B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E lastLSNTID 133 xactionTable
Undo Walk backwards, following prevLSNs to UNDO losers LSNTypeTidPrevLSNData 1SOT1 2UP11A 3 12B 4CP 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E lastLSNTID 133 xactionTable
What does UNDO do? Why is it safe to undo an op from middle of log? What if the operation split a B+Tree block?
Crash during UNDO phase? –Example: T1 starts T1 deletes tuple, modifies heapfile, B+Tree index DB writes all dirty pages to disk checkpoint crash –Nothing to redo –Undo phase starts to modify heapfile/B+Tree, writes some pages to disk, crash again. –Will the 2 nd recovery work correctly?
UNDO with CLR LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E Losers: 3
UNDO with CLR LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E
UNDO with CLR LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E 14CLR3E
UNDO with CLR LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E 14CLR310E
UNDO with CLR LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E 14CLR310E 15CLR35B
UNDO with CLR LSNTypeTidPrevLSNData 5SOT3 6UP13C 7SOT2 8UP27D 9EOT16 10UP35B 11UP28A 12EOT211 13UP310E 14CLR310E 15CLR35B 16EOT3-
REDO with CLR REDO CLRs on crash recovery –Just like redo of ordinary update –CLR is the physical redo version of the logical undo –Each CLR has an entire undo’s worth of redo info Thus redo w/ CLRs yields action consistency –After processing CLR, update lastLSN field in xactionTable to point to prevLSN of CLR Allows UNDO to start from the right place