recovery review the acid properties
play

Recovery Review: The ACID properties A tomicity: All actions in the - PowerPoint PPT Presentation

Recovery Review: The ACID properties A tomicity: All actions in the Xaction happen, or none happen. n C onsistency: If each Xaction is consistent, and the DB starts n consistent, it ends up consistent. I solation: Execution of one Xaction is


  1. Recovery

  2. Review: The ACID properties A tomicity: All actions in the Xaction happen, or none happen. n C onsistency: If each Xaction is consistent, and the DB starts n consistent, it ends up consistent. I solation: Execution of one Xaction is isolated from that of other Xacts. n D urability: If a Xaction commits, its effects persist. n CC guarantees Isolation and Consistency. n The Recovery Manager guarantees Atomicity & Durability. n

  3. Why is recovery system necessary? Transaction failure : n • Logical errors : application errors (e.g. div by 0, segmentation fault) • System errors : deadlocks System crash : hardware/software failure causes the system to n crash. Disk failure : head crash or similar disk failure destroys all or n part of disk storage n Lost data can be in main memory or on disk

  4. Storage Media Volatile storage : n • does not survive system crashes • examples: main memory, cache memory Nonvolatile storage : n • survives system crashes • examples: disk, tape, flash memory, non-volatile (battery backed up) RAM Stable storage : n • a “mythical” form of storage that survives all failures • approximated by maintaining multiple copies on distinct nonvolatile media

  5. Recovery and Durability To achieve Durability: Put data on stable storage n To approximate stable storage make two copies of n data Problem: data transfer failure n

  6. Recovery and Atomicity Durability is achieved by making 2 copies of data n What about atomicity… n • Crash may cause inconsistencies…

  7. Recovery and Atomicity Example: transfer $50 from account A to account B n • goal is either to perform all database modifications made by Ti or none at all. Requires several inputs (reads) and outputs (writes) n Failure after output to account A and before output to B…. n • DB is corrupted!

  8. Recovery Algorithms Recovery algorithms are techniques to ensure database n consistency and transaction atomicity and durability despite failures Recovery algorithms have two parts n 1. Actions taken during normal transaction processing to ensure enough information exists to recover from failures 2. Actions taken after a failure to recover the database contents to a state that ensures atomicity and durability

  9. Background: Data Access Physical blocks: blocks on disk. n Buffer blocks: blocks in main memory. n Data transfer: n • input ( B ) transfers the physical block B to main memory. • output ( B ) transfers the buffer block B to the disk, and replaces the appropriate physical block there. Each transaction T i has its private work-area in which local n copies of all data items accessed and updated by it are kept. T i 's local copy of a data item x is called x i . • Assumption: each data item fits in and is stored inside, a single block.

  10. Data Access (Cont.) Transaction transfers data items between system buffer blocks n and its private work-area using the following operations : read ( X ) assigns the value of data item X to the local variable x i . • write ( X ) assigns the value of local variable x i to data item { X } in the • buffer block. both these commands may necessitate the issue of an input (B X ) • instruction before the assignment, if the block B X in which X resides is not already in memory. Transactions n • Perform read ( X ) while accessing X for the first time; • All subsequent accesses are to the local copy. • After last access, transaction executes write ( X ). ➢ output ( BX ) need not immediately follow write ( X ). ➢ System can perform the output operation when it deems fit.

  11. buffer input(A Buffer Block A X ) A Buffer Block B Y output(B) B read(X) write(Y) disk x x 2 1 y 1 work area work area of T2 of T1 memor y

  12. Recovery and Atomicity (Cont.) To ensure atomicity, first output information about modifications n to stable storage without modifying the database itself. We study two approaches: n • log-based recovery , and • shadow-paging

  13. Log-Based Recovery Simplifying assumptions: n • Transactions run serially • logs are written directly on the stable storage Log: a sequence of log records ; maintains a record of update n activities on the database. (Write Ahead Log, W.A.L.) Log records for transaction Ti : n <T i start > • • <Ti , X, V1, V2> < T i commi t > • Two approaches using logs n • Deferred database modification • Immediate database modification

  14. Log example Log Transaction T1 <T1, start> Read(A) <T1, A, 1000, 950> A =A-50 <T1, B, 2000, 2050> Write(A) <T1, commit> Read(B) B = B+50 Write(B)

  15. Deferred Database Modification Ti starts: write a <Ti start > record to log. n Ti write ( X ) n • write <Ti, X, V> to log: V is the new value for X • The write is deferred Note: old value is not needed for this scheme ➢ Ti partially commits: n • Write < Ti commit > to the log DB updates by reading and executing the log: n • <Ti start > …… < Ti commit >

  16. Deferred Database Modification How to use the log for recovery after a crash? n Redo: if both <Ti start > and < Ti commit > are there in the log. n Crashes can occur while n • the transaction is executing the original updates, or • while recovery action is being taken example transactions T0 and T1 ( T0 executes before T1 ): n T0 : read ( A ) T1 : read ( C ) A: - A - 50 C:- C- 100 write ( A ) write ( C ) read ( B ) B:- B + 50 write ( B )

  17. Deferred Database Modification (Cont.) Below we show the log as it appears at three instances of time. n <T0, start> <T0, start> <T0, start> <T0, A, 950> <T0, A, 950> <T0, A, 950> <T0, B, 2050> <T0, B, 2050> <T0, B, 2050> <T0, commit> <T0, commit> <T1, start> <T1, start> (a) <T1, C, 600> <T1, C, 600> <T1, commit> (b) (c) What is the correct recovery action in each case?

  18. Immediate Database Modification Database updates of an uncommitted transaction are allowed n Tighter logging rules are needed to ensure transactions are n undoable • LOG records must be of the form: <Ti, X, Vold, Vnew > • Log record must be written before database item is written • Output of DB blocks can occur: Before or after commit ➢ In any order ➢

  19. Immediate Database Modification (Cont.) Recovery procedure : n • Undo : < T i, start > is in the log but <Ti commit > is not. Undo: restore the value of all data items updated by Ti to their old ➢ values, going backwards from the last log record for Ti • Redo: <Ti start > and <Ti commit > are both in the log. sets the value of all data items updated by Ti to the new values, ➢ going forward from the first log record for Ti Both operations must be idempotent: even if the operation is executed n multiple times the effect is the same as if it is executed once

  20. Immediate Database Modification Example Log Write Output < T 0 start > < T0, A, 1000, 950> <T o , B, 2000, 2050> A = 950 B = 2050 < T 0 commit > < T 1 start > < T 1, C, 700, 600> C = 600 BB , BC < T 1 commit > BA Note: BX denotes block containing X . n

  21. I M Recovery Example <T0, start> <T0, start> <T0, start> <T0, A, 1000, 950> <T0, A, 1000, 950> <T0, A, 1000, 950> <T0, B, 2000, 2050> <T0, B, 2000, 2050> <T0, B, 2000, 2050> <T0, commit> <T0, commit> <T1, start> <T1, start> <T1, C, 700, 600> <T1, C, 700, 600> <T1, commit> (c) (b) (a) Recovery actions in each case above are: (a) undo ( T 0): B is restored to 2000 and A to 1000. (b) undo ( T 1) and redo ( T 0): C is restored to 700, and then A and B are set to 950 and 2050 respectively. (c) redo ( T 0) and redo ( T 1): A and B are set to 950 and 2050 respectively. Then C is set to 600

  22. Checkpoints Problems in recovery procedure as discussed earlier : n 1. searching the entire log is time-consuming 2. we might unnecessarily redo transactions which have already output their updates to the database. How to avoid redundant redoes? n • Put marks in the log indicating that at that point DB and log are consistent . Checkpoint !

  23. Checkpoints At a checkpoint : n Quiese system operation. n Output all log records currently residing in main memory onto stable storage. n Output all modified buffer blocks to the disk. n Write a log record < checkpoint > onto stable storage.

  24. Checkpoints (Cont.) Recovering from log with checkpoints: 1. Scan backwards from end of log to find the most recent < checkpoint > record 2. Continue scanning backwards till a record <Ti start > is found. 3. Need only consider the part of log following above star t record. Why? 4. After that, recover from log with the rules that we had before.

  25. Example of Checkpoints T T c f T 1 T 2 T 3 T 4 checkpoint system checkpoint failure n T 1 can be ignored (updates already output to disk due to checkpoint) n T 2 and T 3 redone. n T 4 undone

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend