Recovery
T1 Read(A) A:=A-500; Write(A) Read(B) B:=B+500 Write(B) commit Example: BA 1000 ?? fail
Two approaches for modifying the database when using logs Deferred database modification Immediate database modification
Deferred database modification
Log zyx Log zyx
Immediate database modification
Log zyx
How is the process Recovery do? Rollback Recovery procedure has two operations instead of one: Undo redo
Log fail Redo : Commit listActivity list ZYX
Log fail Commit listActivity list T1T2 T3 redo( T 1 ) and redo( T 3 ) must be performed since is present Redo : ZYX
Undo / Redo : Log fail Commit listActivity list ZYX
Undo / Redo : Log fail Commit listActivity list T1T2 T3 ZYX undo ( T 2 ) and redo ( T 1 ) and redo ( T 3 ): Y is restored to 20, and then X and Z are set to 100 and 50 respectively.
We assume that the original item values, shown in the first line, are A = 10, B = 30, C = 20. Which transactions will rollback if transaction T3 has not reached its conclusion and must be rolled back? ● What is the final value for each item?
ABC [start_transction,T3] [read_item,T3,A] [write_item,T3,A,10,5] 5 [start_transction,T1] [read_item,T1,A] [start_transction,T2] [read_item,T2,B] [read_item,T1,B] [write_item,T1,B,30,22] 22 [write_item,T2,B,22,6] 6 [read_item,T1,C] [write_item,T1,C,20,100] 100 [read_item,T2,A] [write_item,T2,A, 5,2] 2 CBA T2 must be roll back because T3 has not reached
Checkpoints
Example of Checkpoints T 1 can be ignored (updates already output to disk due to checkpoint) T 2 and T 3 redone. T 4 undone TcTc TfTf T1T1 T2T2 T3T3 T4T4 checkpoint system failure
Consider a database with data items {A, B, C, D}. The system uses an undo/redo scheme and has the following logs. Note that an entry means transaction T changes the value of X from old to new. We consider recovery using this undo/redo log System failed Example:
1. List all possible values of A, B, C and D. That is, what are the possible data values on the disk at the point of failure (after action 21)? A= 20 or 21, B=11, C = 30 or 31 or 32 or 33, D = 50, 51, During recovery, what are the transactions that need to be undone? T1, T6. 3. During recovery, what are the transactions that need to be redone? T3, T4, T5 4. During recovery, what are the transactions that need to be ignored ? T2 5. What are the values of A, B, C, D after recovery? Explain why ? A = 20 B = 41 C = 31 D = 52 A= 20 because T1 is undo. B= 41 because T4 is redone. C= 31 because both T1 and T6 are undone and T3 is redone. D = 52 because T5 is redone.