Database Management System 23
Database Management System 23
Chittaranjan Pradhan
Transaction Failure
Shadow-Copy Scheme
Log-Based Recovery
Deferred Database
Modification
Immediate Database
Modification
Checkpoints
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
23.1
Recovery System
Recovery System
Chittaranjan Pradhan
Recovery System
Transaction Failure
Shadow-Copy Scheme
The recovery manager of a database system is responsible for Recovery Facilities
ensuring two important properties of transactions: Log-Based Recovery
Deferred Database
• atomicity Modification
Immediate Database
Modification
• durability Checkpoints
23.2
Recovery System
Transaction Failure
Chittaranjan Pradhan
Transaction Failure
Recovery System
Database Recovery
• Logical error : The transaction can not complete due to
Shadow-Copy Scheme
some internal error conditions, such as wrong input, data
Recovery Facilities
not found, overflow or resource limit exceeded Log-Based Recovery
• System error : The transaction can not complete because of Deferred Database
Modification
the undesirable state. However, the transaction can be Immediate Database
Modification
re-executed at a later time Checkpoints
23.3
Recovery System
Database Recovery
Chittaranjan Pradhan
Transaction Failure
Database recovery is the process of restoring a database to
Database Recovery
the correct state in the event of a failure Shadow-Copy Scheme
Recovery Facilities
This service is provided by the database system to ensure that Log-Based Recovery
the database is reliable and remains in consistent state in case Deferred Database
Modification
23.4
Recovery System
Shadow-Copy Scheme
Chittaranjan Pradhan
Shadow-Copy Scheme
This scheme is based on making copies of the database called Recovery System
shadow copies and it assumes that only one transaction is Transaction Failure
Database Recovery
active at a time
Shadow-Copy Scheme
This scheme assumes that the database is simply a file on
Recovery Facilities
disk. A pointer called db-pointer is maintained on disk; it points Log-Based Recovery
to the current copy of the database Deferred Database
Modification
Immediate Database
Modification
Checkpoints
Recovery System
Transaction Failure
Recovery Facilities Database Recovery
Shadow-Copy Scheme
A database system should provide the following facilities to
Recovery Facilities
assist with the recovery: Log-Based Recovery
23.6
Recovery System
Log-Based Recovery
Chittaranjan Pradhan
Transaction Failure
Log is a sequence of log records, recording all the update Database Recovery
activities in the database. It is kept on stable storage Shadow-Copy Scheme
Recovery Facilities
There are several types of log records. An update log record Log-Based Recovery
Deferred Database
describes a single database write. It has the following fields: Modification
Immediate Database
23.7
Recovery System
Log-Based Recovery...
Chittaranjan Pradhan
Database Recovery
• <Ti start>: Transaction Ti has started Shadow-Copy Scheme
• <Ti , xj ,v1 ,v2 >: Transaction Ti has performed a write Recovery Facilities
operation on the data item xj . This data item xj had value Log-Based Recovery
Deferred Database
v1 before the write, and will have value v2 after the write Modification
Immediate Database
Modification
• <Ti commit>: Transaction Ti has committed Checkpoints
For log records to be useful for recovery from system and disk
failures, the log must reside in stable storage
23.8
Recovery System
Deferred Database Modification
Chittaranjan Pradhan
Recovery System
Deferred Database Modification Transaction Failure
This scheme ensures transaction atomicity by recording all the Database Recovery
database modifications in the log, but deferring the execution of Shadow-Copy Scheme
Recovery Facilities
all write operations of a transaction until the transaction
Log-Based Recovery
partially commits Deferred Database
Modification
Immediate Database
Modification
The execution of transaction Ti proceeds as follows: Checkpoints
23.9
Recovery System
Deferred Database Modification...
Chittaranjan Pradhan
T1 T2
Read(A); Read(C);
Recovery System
A:=A-100; C:=C-100;
Transaction Failure
Write(A); Write(C);
Database Recovery
Read(B);
Shadow-Copy Scheme
B:=B+100;
Recovery Facilities
Write(B);
Log-Based Recovery
Deferred Database
Suppose the transactions are executed serially in the order T1 Modification
Immediate Database
followed by T2 ; and the initial values of accounts A, B and C Modification
Checkpoints
before the execution took place were $1000, $2000 and $3000
respectively
Database Log
<T1 start>
<T1 ,A,900>
<T1 ,B,2100>
<T1 commit>
<T2 start>
<T2 ,C, 2900>
<T2 commit>
Recovery System
Redo(Ti ): It sets the value of all data items updated by Transaction Failure
Database Recovery
transaction Ti to the new values. The set of data items updated
Shadow-Copy Scheme
by Ti and their respective new values can be found in the log
Recovery Facilities
Log-Based Recovery
The redo operation must be idempotent, i.e. executing it Deferred Database
Modification
23.11
Recovery System
Deferred Database Modification...
Chittaranjan Pradhan
Transaction Failure
Database Log
<T1 start> Database Recovery
Log-Based Recovery
When the system recovers, no redo actions need to be taken, Deferred Database
Modification
because no commit record appears in the log. The log records Immediate Database
Modification
Database Log
<T1 start>
<T1 ,A,900>
<T1 ,B,2100>
<T1 commit>
Recovery System
Transaction Failure
Shadow-Copy Scheme
Recovery Facilities
Database Log
<T1 start> Log-Based Recovery
Deferred Database
<T1 ,A,900> Modification
<T1 ,B,2100> Immediate Database
Modification
<T1 commit> Checkpoints
<T2 start>
<T2 ,C, 2900>
23.13
Recovery System
Deferred Database Modification...
Chittaranjan Pradhan
Recovery System
Transaction Failure
Case-4: Crash occurs just after <T2 commit> Database Recovery
Shadow-Copy Scheme
23.14
Recovery System
Immediate Database Modification
Chittaranjan Pradhan
Immediate Database Modification
This scheme allows database modifications to be output to the Recovery System
database while the transaction is still in the active state. Data Transaction Failure
Recovery Facilities
Log-Based Recovery
In the event of a crash or a transaction failure, the system must Deferred Database
Modification
use the old-value field of the log records to restore the modified Immediate Database
Modification
data items to the value they had prior to the start of the Checkpoints
Database Log
<T1 start> Recovery System
<T1 ,A,1000,900> Transaction Failure
<T1 ,B,2000,2100> Database Recovery
<T1 commit>
Shadow-Copy Scheme
<T2 start>
Recovery Facilities
<T2 ,C, 3000,2900>
Log-Based Recovery
<T2 commit> Deferred Database
Modification
Immediate Database
The recovery scheme uses two recovery procedures: Modification
Checkpoints
Transaction Failure
Database Log
<T1 start> Database Recovery
<T1 ,A,1000,900>
Shadow-Copy Scheme
<T1 ,B,2000,2100>
Recovery Facilities
When the system recovers, it finds the record <T1 start> in the Log-Based Recovery
Deferred Database
Database Log
<T1 start>
<T1 ,A,1000,900>
<T1 ,B,2000,2100>
<T1 commit>
Recovery System
Database Recovery
Shadow-Copy Scheme
Database Log
<T1 start> Recovery Facilities
23.18
Recovery System
Immediate Database Modification...
Chittaranjan Pradhan
Recovery System
Transaction Failure
Shadow-Copy Scheme
<T2 start>
<T2 ,C, 3000, 2900>
<T2 commit>
23.19
Recovery System
Checkpoints
Chittaranjan Pradhan
Checkpoints
Recovery System
When a system failure occurs, we must consult the log to Transaction Failure
determine those transactions that need to be redone and those Database Recovery
that need to be undone. For this, we need to search the entire Shadow-Copy Scheme
Recovery Facilities
log to determine this information. There are two major
Log-Based Recovery
difficulties with this approach: Deferred Database
Modification
• The search process is time consuming Immediate Database
Modification
Checkpoints
• Most of the transactions that need to be redone have
already written their updates into the database. Although
redoing them will cause no harm, it will nevertheless
cause recovery to take longer time
To reduce these types of overhead, checkpoints can be used
• Output onto stable storage all log records currently
residing in main memory
• Output to the disk all modified buffer blocks
• Output onto stable storage a log record <checkpoint>
23.20
Recovery System
Checkpoints...
Chittaranjan Pradhan
While a checkpoint is in progress, transactions are not allowed
to perform any update actions such as writing to a buffer block
Recovery System
or writing a log record
Transaction Failure
After a failure has occurred, the recovery scheme examines Database Recovery
the log to determine the most recent transaction Ti that started Shadow-Copy Scheme
executing before the most recent checkpoint took place Recovery Facilities
• Scan backwards from end of log to find the most recent Log-Based Recovery
Deferred Database
<checkpoint> record Modification
Immediate Database
• Continue scanning backward till a record <Ti start> is Modification
Checkpoints
found
• Once the system has identified transaction Ti , the redo
and undo operations need to be applied to only
transaction Ti and all transactions Tj that started executing
after transaction Ti . Let these transactions are denoted by
the set T. The earlier part of the log can be ignored and
can be erased whenever desired
• For all transactions starting from Ti or later with no <Ti
commit> record in the log, execute undo(Ti )
• Scanning forward in the log, for all transactions starting
from Ti or later with a <Ti commit>, execute redo(Ti ) 23.21
Recovery System
Checkpoints...
Chittaranjan Pradhan
Recovery System
Transaction Failure
Database Recovery
Shadow-Copy Scheme
Recovery Facilities
Log-Based Recovery
Deferred Database
Modification
Immediate Database
Modification
Checkpoints