* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Document
Survey
Document related concepts
Entity–attribute–value model wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Commitment ordering wikipedia , lookup
Oracle Database wikipedia , lookup
Ingres (database) wikipedia , lookup
Functional Database Model wikipedia , lookup
Relational model wikipedia , lookup
Serializability wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Database model wikipedia , lookup
Clusterpoint wikipedia , lookup
Transcript
Pusan National University em Spatiotemporal Database Laboratory File Processing : Recovery 2004, Spring Pusan National University Ki-Joune Li Pusan National University em Failure Classification Transaction failure : Spatiotemporal Database Laboratory Logical errors: internal error condition System errors: system error condition (e.g., deadlock) System crash: a power failure or other hardware or software failure Fail-stop assumption: non-volatile storage contents are assumed to not be corrupted by system crash Database systems have numerous integrity checks to prevent corruption of disk data Disk failure Pusan National University em Recovery Algorithms Recovery algorithms : Ensure Spatiotemporal Database Laboratory database consistency transaction atomicity and durability despite failures Recovery algorithms have two parts 1. Preparing Information for Recovery : During normal transaction 2. Actions taken after a failure to recover the database Pusan National University em Storage Structure Volatile storage: Spatiotemporal Database Laboratory Nonvolatile storage: does not survive system crashes examples: main memory, cache memory survives system crashes examples: disk, tape, flash memory, non-volatile (battery backed up) RAM Stable storage: a mythical form of storage that survives all failures approximated by maintaining multiple copies on distinct nonvolatile media Pusan National University em Stable-Storage Implementation Maintain multiple copies of each block on separate disks. Failure during data transfer result in inconsistent copies: Block transfer can result in Spatiotemporal Database Laboratory Successful completion Partial failure: destination block has incorrect information Total failure: destination block was never updated Protecting storage media from failure during data transfer 1. Write the information onto the first physical block. 2. When the first write successfully completes, write the same information onto the second physical block. 3. The output is completed only after the second write successfully completes. Performance ? Pusan National University em Stable-Storage Implementation (Cont.) Copies of a block may differ due to failure during output operation. To recover from failure: 1. First find inconsistent blocks: Spatiotemporal Database Laboratory 1. Expensive solution: Compare the two copies of every disk block. 2. Better solution: Record in-progress disk writes on non-volatile storage (Non-volatile RAM or special area of disk). Use this information during recovery to find blocks that may be inconsistent, and only compare copies of these. Used in hardware RAID systems 2. If either copy of an inconsistent block is detected to have an error (bad checksum), overwrite it by the other copy. If both have no error, but are different, overwrite the second block by the first block. Pusan National University em Data Access Two types of Block Block movements Spatiotemporal Database Laboratory input(B) transfers the physical block B to main memory. output(B) transfers the buffer block B to the disk, Each transaction Ti Physical blocks Buffer blocks : Temporary. has its private work-area in which local copies (local variables) of all data items accessed and updated by it are kept. Ti's local copy of a data item X is called xi. We assume, for simplicity, that each data item fits in, and is stored inside, a single block. Pusan National University em Data Access (Cont.) Transaction transfers data items between system buffer blocks and its private work-area using the following operations : Spatiotemporal Database Laboratory Transactions read(X) : from buffer block X to the local variable xi. write(X) : from local variable xi to data item {X} in the buffer block. both these commands may necessitate the issue of an input(BX) instruction before the assignment, if the block BX in which X resides is not already in memory. 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. Pusan National University em Example of Data Access buffer input(A) x Buffer Block A A Y Buffer Block B output(B) B Spatiotemporal Database Laboratory read(X) write(Y) x2 x1 y1 work area of T1 memory work area of T2 disk Pusan National University em Recovery and Atomicity Modifying the database Spatiotemporal Database Laboratory Example must be committed commit Otherwise it may leave the database in an inconsistent state. Consider transaction Ti that transfers $50 from account A to account B; goal is either to perform all database modifications made by Ti or none at all. Several output operations may be required for Ti For example : output(A) and output(B). A failure may occur after one of these modifications have been made but before all of them are made. Pusan National University em Recovery and Atomicity (Cont.) To ensure atomicity despite failures, We study two approaches: Spatiotemporal Database Laboratory we first output information describing the modifications to stable storage without modifying the database itself. log-based recovery, and shadow-paging Pusan National University em Log-Based Recovery A log : must be kept on stable storage. Spatiotemporal Database Laboratory Logging Method When transaction Ti starts, <Ti start> log record When Ti finishes, <Ti commit> log record Before Ti executes write(X), <Ti, X, Vold , Vnew > log record We assume for now that log records are written directly to stable storage <Ti, Start>, and <Ti, Start> < Ti, X, V1, V2 > Two approaches using logs Deferred database modification Immediate database modification Pusan National University em Deferred Database Modification The deferred database modification scheme Log Scheme Spatiotemporal Database Laboratory records all modifications to the log, writes them after commit. Transaction starts by writing <Ti start> record to log. write(X) : <Ti, X, V> Note: old value is not needed for this scheme The write is not performed on X at this time, but is deferred. When Ti commits, <Ti commit> is written to the log Finally, executes the previously deferred writes. Pusan National University em Deferred Database Modification (Cont.) Recovering Method During recovery after a crash, Spatiotemporal Database Laboratory a transaction needs to be redone if and only if both <Ti start> and<Ti commit> are there in the log. Redoing a transaction Ti ( redoTi) sets the value of all data items updated by the transaction to the new values. Deletes Ti such that <Ti ,start> exists but <Ti commit> does not. Pusan National University Spatiotemporal Database Laboratory em Deferred Database Modification : Example T0: read (A) A: = A - 50 write (A) read (B) B:= B + 50 write (B) T1 : read (C) C:= C- 100 write (C) If log on stable storage at time of crash is as in case: (a) No redo actions need to be taken (b) redo(T0) must be performed since <T0 commit> is present (c) redo(T0) must be performed followed by redo(T1) since <T0 commit> and <Ti commit> are present Pusan National University em Immediate Database Modification Immediate database modification scheme Spatiotemporal Database Laboratory Recovery procedure has two operations Database updates of an uncommitted transaction For undoing : both old value and new value undo(Ti) : restores the value of all data items updated by Ti redo(Ti) : sets the value of all data items updated by Ti When recovering after failure: Undo if the log <Ti start>, but not <Ti commit>. Redo if the log both the record <Ti start> and <Ti commit>. Pusan National University Spatiotemporal Database Laboratory em Immediate Database Modification : Example Recovery actions in each case above are: (a) undo (T0): B is restored to 2000 and A to 1000. (b) undo (T1) and redo (T0): C is restored to 700, and then A and B are set to 950 and 2050 respectively. (c) redo (T0) and redo (T1): A and B are set to 950 and 2050 respectively. Then C is set to 600 Pusan National University em Idempotent Operation Result (Op(x)) = Result (Op(Op(x)) Example Spatiotemporal Database Laboratory Increment(x); : Not Idempotent x=a; write(x); : Idempotent Operations in Log Record Must be Idempotent, otherwise Multple Executions (for redo) may cause incorrect results Pusan National University Spatiotemporal Database Laboratory em Checkpoints Problems in recovery procedure by Log record scheme : 1. searching the entire log records : time-consuming 2. Discard unnecessary redo transactions already executed. Checkpoint Method Marking Checkpoint Recovery from Checkpoint Marking Checkpoint 1. Output all log records currently residing in main memory onto stable storage. 2. Output all modified buffer blocks to the disk. 3. Write a log record < checkpoint> onto stable storage. Pusan National University em Checkpoints (Cont.) In case of failure Tf Tc T1 Spatiotemporal Database Laboratory T2 T3 T4 checkpoint T1 can be ignored T2 and T3 redone. T4 undone system failure Pusan National University em Shadow Paging Mechanism maintain two page tables Spatiotemporal Database Laboratory shadow page table the current page table, and the shadow page table state of the database before transaction execution Shadow page table is never modified during execution To start with, both the page tables are identical. Whenever any page is about to be written for the first time A copy of this page is made onto an unused page. The current page table is then made to point to the copy The update is performed on the copy Spatiotemporal Database Laboratory Pusan National University em Shadow Page : Example Old State New State