Chapter 4
Chapter 4
Chapter 4
Introduction
• A crash is the sudden failure of a software application or operating system or of a
hardware device such as a hard disk.
• An important feature of conventional database systems is the ability to recover from
system crashes.
• Recovery means storing data into previous state before incident.
• Database recovery is the process of restoring the database to a correct (consistent) state in
the event of a failure.
• Crash recovery is the process by which database is moved back to consistent state.
Failure Classification
Failure refers to the state when system can no longer continue with its normal execution and that
results in loss of information.
• Transaction failure :
⮚ Logical errors: transaction cannot complete due to some internal error condition.
E.g. Data not found, bad input
⮚ System errors: the database system must terminate an active transaction due to an
error condition (e.g., deadlock)
• System crash: a power failure or other hardware or software failure causes the system to
crash.
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: a head crash or similar disk failure destroys all or part of disk storage
Destruction is assumed to be detectable: disk drives use checksums to detect failures.
Recovery Concept
• Consider transaction Ti that transfers $50 from account A to account B
⮚ Two updates: subtract $50 from A and add $50 to B
• Transaction Ti requires updates to A and B to be output to the database.
⮚ A failure may occur after one of these modifications have been made but before
both of them are made.
⮚ Modifying the database without ensuring that the transaction will commit may
leave the database in an inconsistent state
⮚ Not modifying the database may result in lost updates if failure occurs just after
transaction commits
• Recovery algorithms have two parts
⮚ Actions taken during normal transaction processing to ensure enough information
exists to recover from failures
⮚ Actions taken after a failure to recover the database contents to a state that ensures
atomicity, consistency and durability
Concept of log:
• Log means recording of database modifications.
• To denote various types of log records:
1. Start of transaction:
<Ti, start>
2. Update log:
<Ti,Xj,V1,V2>
Ti - Transaction identifier
Xj – Data item identifier
V1 – Old value of Xj
V2 – New value Xj after the write operation
3. Transaction Commit:
<Ti, commit>
4. Transaction abort:
<Ti, abort>
• Log is stored in stable storage.
• Whenever a transaction performs a write, it is essential that the log record for that
write be created before the database is modified.
Log based recovery techniques:
• The log based recovery technique maintain transaction logs to keep track of all update
operations of the transaction.
• It assumes that transactions are executed serially ie only one transaction is active at a
time.
• It uses structure called log to store modification.
Recovery Procedure:
Two operations applied to recover from a failure:
1. Undo: This operation recovers (roll backs) the changes made to database by
uncommitted transaction and restores the database to the consistent state that existed
before the start of the transaction.
2. Redo: This operation reapplied the changes of a committed transaction and restores the
database to the consistent state it would be at the end of the transaction. This operation is
required when the changes of a committed transaction are not partially reflected to the
database on disk. The redo modifies the new values for the committed transaction.
Two recovery algorithms are:
1. Deferred update (or NO UNDO/REDO) algorithm
2. Immediate update (or UNDO/REDO) algorithm
Example 2:
In case of crash,
If transaction commits then do REDO action.
If no commit action is for transaction then perform NO UNDO
Immediate update (UNDO/REDO):
• It allows the database modifications to be output to the database while transaction is still
active state. This is called as uncommitted modifications.
• It allows database to modify by any transaction after write operation.
• If transaction fails after recording some changes in database but before reaching its
commit point, the effect of its operation on database must be undone ie transaction must
be roll backed.
• For committed transaction REDO action is taken.
• Hence deferred update is also known as UNDO/REDO algorithm
Example 1:
In log T1 contains commit so changes are updated to database. This is REDO action.
Example 2:
When T1 starts and performs write operation then immediately changes are made into the
database.
Same for T2 also.
But in case of system crash changes for Transaction T1 are Redone ie REDO because commit is
log.
For T2 changes are undone as no commit is in log.
i.e. For T1 action is REDO
For T2 action is UNDO
In case of crash,
If transaction commits then do REDO action.
If no commit action is for transaction then perform UNDO
Immediate update examples:
Recovery actions in each case above are:
(a) undo (T0): B is restored to 2000 and A to 1000, and log records
<T0, B, 2000>, <T0, A, 1000>, <T0, abort> are written out
(b) redo (T0) and undo (T1): A and B are set to 950 and 2050 and C is restored to 700. Log
records <T1, C, 700>, <T1, abort> are written out.
(c) redo (T0) and redo (T1): A and B are set to 950 and 2050
respectively. Then C is set to 600
2. If deferred update a technique with checkpoint is used, what will be the recovery
procedure?
[start – transaction, T1]
[write – T1, B, 100]
[commit T1]
[checkpoint]
[start – transaction, T2]
[write – T2, B, 15]
[commit T2]
[start – transaction, T3]
[write – T3, D, 200]
[write – T3, B, 200] <- System crash
T1 is before checkpoint and committed also – Don’t take any action for T1(Don’t apply
srecovery algorithm)
T2 It has committed after checkpoint – Redo
T3 has started after checkpoint and not committed before system crash – NO UNDO
T1 is before checkpoint and committed also – Don’t take any action for T1(Don’t apply
recovery algorithm)
T4 It has committed after checkpoint – Redo
T2, T3 has started after checkpoint and not committed before system crash – UNDO