Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transactions and Recovery Checkpointing Souhad Daraghma.

Similar presentations


Presentation on theme: "Transactions and Recovery Checkpointing Souhad Daraghma."— Presentation transcript:

1 Transactions and Recovery Checkpointing Souhad Daraghma

2 Transactions and Recovery

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18  Time to time (randomly or under some criteria) the database flushes its buffer to database disk to minimize the task of recovery. The following steps defines a checkpoint operation: 1. Suspend execution of transactions temporarily. 2. Force write modified buffer data to disk. 3. Write a [checkpoint] record to the log, save the log to disk. 4. Resume normal transaction execution. During recovery redo or undo is required to transactions appearing after [checkpoint] record. Checkpointing

19 Database Recovery This environment requires some concurrency control mechanism to guarantee isolation property of transactions. In a system recovery transactions which were recorded in the log after the last checkpoint were redone. Recovery in a concurrent users environment.

20 Deferred Update with concurrent users  Two tables are required for implementing this protocol:  Active table: All active transactions are entered in this table.  Commit table: Transactions to be committed are entered in this table.  During recovery, all transactions of the commit table are redone and all transactions of active tables are ignored since none of their modifications reached the database.  It is possible that a commit table transaction may be redone twice but this does not create any inconsistency because of a redone is “idempotent”, that is, one redone for a modification is equivalent to multiple redone for the same modification.

21 Transactions and Recovery Types of Transactions Last CheckpointSystem Failure T1T1 T2T2 T3T3 T4T4 T5T5

22 Transactions and Recovery System Recovery Any transaction that was running at the time of failure needs to be undone and restarted Any transactions that committed since the last checkpoint need to be redone Transactions of type T 1 need no recovery Transactions of type T 3 or T 5 need to be undone and restarted Transactions of type T 2 or T 4 need to be redone

23 Transactions and Recovery Transaction Recovery UNDO and REDO: lists of transactions UNDO = all transactions running at the last checkpoint REDO = empty For each entry in the log, starting at the last checkpoint If a START TRANSACTION entry is found for T Add T to UNDO If a COMMIT entry is found for T Move T from UNDO to REDO

24 Transactions and Recovery Transaction Recovery T1T1 T2T2 T3T3 T4T4 T5T5 CheckpointFailure UNDO: T 2, T 3 REDO: Last Checkpoint Active transactions: T 2, T 3

25 Transactions and Recovery Transaction Recovery T1T1 T2T2 T3T3 T4T4 T5T5 CheckpointFailure UNDO: T 2, T 3, T 4 REDO: T4 Begins Add T 4 to UNDO

26 Transactions and Recovery Transaction Recovery T1T1 T2T2 T3T3 T4T4 T5T5 CheckpointFailure UNDO: T 2, T 3, T 4, T 5 REDO: T 5 begins Add T 5 to UNDO

27 Transactions and Recovery Transaction Recovery T1T1 T2T2 T3T3 T4T4 T5T5 CheckpointFailure UNDO: T 3, T 4, T 5 REDO: T 2 T 2 Commits Move T 2 to REDO

28 Transactions and Recovery Transaction Recovery T1T1 T2T2 T3T3 T4T4 T5T5 CheckpointFailure UNDO: T 3, T 5 REDO: T 2, T 4 T 4 Commits Move T 4 to REDO

29 Transactions and Recovery Forwards and Backwards Backwards recovery We need to undo some transactions Working backwards through the log we undo any operation by a transaction on the UNDO list This returns the database to a consistent state Forwards recovery Some transactions need to be redone Working forwards through the log we redo any operation by a transaction on the REDO list This brings the database up to date

30 Examples Transactions and Recovery

31 FIGURE 19.4 An example of recovery using deferred update with concurrent transactions. (a) The READ and WRITE operations of four transactions. (b) System log at the point of crash. Recovery Techniques Based on Deferred Update

32 [start_transaction, T1] [write_item, T1,D, 20, 25] [commit,T1] [checkpoint] [start_transaction, T2 ] [write_item, T2,B, 12,18] [start_transaction, T4 ] [write_item, T4,D, 25,15] [start_transaction, T3] [write_item, T3,C, 30,40] [write_item, T4,A, 30, 20] [commit,T4] [write_item, T2,D, 15, 25] <-----system crash Recovery Techniques Based on Immediate Update

33 Transactions and Recovery Media Failures System failures are not too severe Only information since the last checkpoint is affected This can be recovered from the transaction log Media failures (disk crashes etc) are more serious The data stored to disk is damaged The transaction log itself may be damaged

34 Transactions and Recovery Backups Backups are needed to recover from media failure The transaction log and entire contents of the database is written to secondary storage (often tape) Time consuming, and often requires down time Backups frequency Frequent enough that little information is lost Not so frequent as to cause problems Every day (night) is common Backup storage

35 Transactions and Recovery Recovery from Media Failure Restore the database from the last backup Use the transaction log to redo any changes made since the last backup If the transaction log is damaged you can’t do step 2 Store the log on a separate physical device to the database The risk of losing both is then reduced


Download ppt "Transactions and Recovery Checkpointing Souhad Daraghma."

Similar presentations


Ads by Google