[计算机软件及应用]斯坦福_数据库系统实现_Notes10.ppt

[计算机软件及应用]斯坦福_数据库系统实现_Notes10.ppt

[计算机软件及应用]斯坦福_数据库系统实现_Notes10

CS 245 Notes 10 * Logging Logical Actions Logical action typically span one block (physiological actions) Undo/redo log entry specifies undo/redo logical action Challenge: making actions idempotent Example (bad): redo insert ? key inserted multiple times! CS 245 Notes 10 * Solution: Add Log Sequence Number Log record: LSN=26 OP=insert(5,v2) into P ... 3, v1 sem lsn=25 ... 3, v1 sem lsn=26 ... 5, v2 CS 245 Notes 10 * Still Have a Problem! 3, v1 lsn=24 ... 4, v2 3, v1 lsn=25 ... 3, v1 lsn=26 ... 5, v3 T1 Del 4 T2 Ins 5 CS 245 Notes 10 * Still Have a Problem! 3, v1 lsn=24 ... 4, v2 3, v1 lsn=25 ... 3, v1 lsn=26 ... 5, v3 T1 Del 4 T2 Ins 5 3, v1 lsn=?? ... 5, v3 4, v2 undo Del 4 CS 245 Notes 10 * Still Have a Problem! 3, v1 lsn=24 ... 4, v2 3, v1 lsn=25 ... 3, v1 lsn=26 ... 5, v3 T1 Del 4 T2 Ins 5 3, v1 lsn=?? ... 5, v3 4, v2 undo Del 4 Make log entry for undo lsn=27 CS 245 Notes 10 * Compensation Log Records Log record to indicate undo (not redo) action performed Note: Compensation may not return page to exactly the initial state CS 245 Notes 10 * At Recovery: Example lsn=21 T1 a1 p1 lsn=35 T1 a2-1 p2 lsn=27 T1 a2 p2 ... ... ... ... Log: CS 245 Notes 10 * What to do with p2 (during T1 rollback)? If lsn(p2)27 then ... ? If 27 ? lsn(p2) 35 then ... ? If lsn(p2) ? 35 then ... ? Note: lsn(p2) is lsn of p copy on disk CS 245 Notes 10 * Recovery Strategy [1] Reconstruct state at time of crash Find latest valid checkpoint, Ck, and let ac be its set of active transactions Scan log from Ck to end: For each log entry [lsn, page] do: if lsn(page) lsn then redo action If log entry is start or commit, update ac CS 245 Notes 10 * Recovery Strategy [2] Abort uncommitted transactions Set ac contains transactions to abort Scan log from end to Ck : For each log entry (not undo) of an ac transaction, undo action (making log entry) For ac transactions not fully aborted, read their log entries older than Ck and undo their actions CS 245 Notes 10 * Example: What To Do Aft

文档评论(0)

1亿VIP精品文档

相关文档