120 likes | 147 Views
This chapter reviews the ACID properties of transaction processing, the role of Recovery Manager in ensuring Atomicity and Durability, log-based recovery techniques like Write-Ahead Logging, Undo/Redo operations, and checkpointing to minimize recovery time after system crashes.
E N D
Review: The ACID properties • Atomicity: All actions in the transaction happen, or none happen. • Consistency: If each transaction is consistent, and the DB starts consistent, it ends up consistent. • Isolation: Execution of one transaction is isolated from that of other transactions. • Durability: If a transaction commits, its effects persist. • The Recovery Manager guarantees Atomicity & Durability.
Motivation • Atomicity: • Transactions may abort (“Rollback”). • Durability: • What if DBMS stops running? (Why?) • Desired behavior after system restarts: • T1, T2 & T3 should be durable. • T4 & T5should be aborted (effects not seen). crash! T1 T2 T3 T4 T5
Assumptions • Concurrency control is in effect. • Strict 2PL, in particular. Why? • Updates are happening “in place”. • i.e. data is overwritten on (deleted from) the disk. • A simple scheme to guarantee Atomicity & Durability?
Handling the Buffer Pool • Force every write to disk? • Provides durability. • Poor response time; • Steal buffer-pool frames from uncommited transactions? • If not, poor throughput. • If so, how can we ensure atomicity? • How to support atomicity & durability with No Force & Steal? No Steal Steal Trivial Force Desired No Force
More on Steal and Force • STEAL (why enforcing Atomicity is hard) • To steal frame F:Current page in F (say P) is written to disk; some transaction holds lock on P. • What if the transaction with the lock on P aborts? • Must remember the old value of P at steal time (to support UNDO) • NO FORCE(why enforcing Durability is hard) • What if system crashes before a modified page is written to disk?
Log-Based Recovery • Log • Data structure to record the database modifications • A sequence of log records • <TID, Data ID, old value, new value>
Write-Ahead Logging (WAL) 1. Must force the log record for an update before the corresponding data page gets to disk. (stolen page) 2. Must write all log records for a transaction beforecommit. • #1 guarantees Atomicity. • #2 guarantees Durability.
Undo & Redo • Undo: restore to the old values • Redo: set to the new values • What to do for recovery given the following log? What if there is no <Ti, commit>? What to do after writing Ti’s results to the stable storage? • <Ti, start> • <Ti, A, 900, 1000> • <Ti, commit>
Checkpointing • Periodically, the DBMS creates a checkpoint, in order to minimize the time taken to recover in the event of a system crash. Write to log: • begin_checkpointrecord • Freeze the database • Output all records currently in memory • Output all results of committed transactions • end_checkpointrecord • Fuzzy checkpointing
Recovery • Backward analysis to find the latest <checkpoint> • Undo list • Redo list • Undo (backward) • Redo (forward from checkpoint)
Summary of Logging/Recovery • Recovery Manager guarantees Atomicity & Durability. • Use WAL to allow STEAL/NO-FORCE w/o sacrificing correctness. • Checkpointing: A quick way to limit the amount of log to scan on recovery.