Database Recovery Techniques

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

DATABASE RECOVERY TECHNIQUE

SONA V
2021239022
MSc INTEGRATED COMPUTER SCIENCE
RECOVERY AND ATOMICITY
⮚ Consider transaction Ti that transfers $50 from account A to account B with initial values of A
and B being $1000 and $2000 respectively.

⮚ Suppose the system crash has occurred and when the system restarts, the value of A would be
$950, while B would be $2000 which is inconsistent.

⮚ The goal is to perform either all or no database modifications made by Ti.

⮚ To ensure atomicity despite failures, we first output information describing the modifications
without modifying the database.
RECOVERY TECHNIQUES
i. Log Based Recovery

a. Deferred Recovery
b. Immediate Recovery

ii. Shadow Paging

iii. Checkpoints

iv. Forward Recovery and Backward Recovery


LOG RECORDS
⮚ The most widely used structure for recording database modifications.

⮚ Log is a sequence of log records, recording all update activities in the database.

⮚ The update log record describes a single database write.

⮚ It has 4 parts

• Transaction identifier

• Data-item identifier

• Old value

• New value
UPDATE LOG RECORD

1. Transaction identifier (Ti) :

⮚ Unique identifier of the transaction that performed the write operation.

2. Data item identifier (Xi) :

⮚ It is the unique identifier of the data item written.

⮚ It is the location of the disk of the data item, consisting of the block identifier of the

block on which data item resides.


UPDATE LOG RECORD
3.Old value (Vi) :

⮚ It is the value of the data item prior to the write.

4.New value (Vj) :

⮚ It is the value that the data item will have after write.
UPDATE LOG RECORD

⮚ We represent an update log record as <Ti,Xi,Vi,Vj> indicating the transaction Ti has performed a
write on data item Xj.

⮚ Xj had value V1 before the write and has value V2 after write.
⮚ Other special log records exist
▪ <Ti start> Transaction Ti has started.
▪ <Ti commit> Transaction Ti has committed.
▪ <Ti abort> Transaction Ti has aborted.
DATABASE MODIFICATION
⮚ We know that, a transaction creates a log record prior to modifying the database.

⮚ The log records allow the system to undo changes made by a transaction in the event that the

transaction must be aborted.

⮚ It allows the system to redo changes made by a transaction if the transaction has committed.
DEFERRED DATABASE MODIFICATION

⮚ The deferred modification technique occurs if the transaction does not modify the database until

it has committed.

⮚ All the logs are created and stored in the stable storage, and the database

is updated when a transaction commits.


IMMEDIATE DATABASE MODIFICATION

⮚ The Immediate modification technique occurs if database modification occurs while the

transaction is still active.

⮚ In this technique, the database is modified immediately after every operation. It follows an actual

database modification.
USING LOG TO REDO AND UNDO TRANSACTION
⮚ Consider a banking system. Let T0 be the transaction that transfers $50 from account A to
account B and T1 be the transaction that transfers $100 from account C.

T0 T1
read(A); read(C);
A:=A-50; C:=C-100;
write(A); write(C).
read(B);
B:=B+50;
write(B).
Log Database
<T0 start>
<T0 , A , 1000 , 950>
<T0 , B , 2000 , 2050>

A=950
B=2050
<T0 commit>
<T1 start>
<T1 , C , 700 , 600>

C=600
<T1 commit>

State of system log and database corresponding to T0 and T1


UNDO AND REDO
⮚ All database modifications must be preceded by the creation of log record, the system
has available both the old value prior to the modification of the data item and the new
value is written for the data item.
⮚ This allows the system to perform undo and redo operations.
UNDO :
⮚ Undo using a log record sets the data item specified in the log record to the old value.
⮚ Transaction Ti needs to be undone if the log contains record <Ti start> but does not contain either
the record <Ti commit> or the record <Ti abort>
⮚ It not only restores the data item to their old values but also writes log records to record the
updates.
⮚ When the undo operation for Transaction Ti completes it writes a
<Ti abort> log record indicating the undo has completed.
REDO :
⮚ Redo using a log record sets the data item specified in the log record to the new value.
⮚ Transaction Ti needs to be redone if the log contains record <Ti start> and either the record <Ti
commit>
⮚ The updates carried out by redo is important when recovering from a system crash.
⮚ Most recovery algorithms do not perform redo separately, instead they perform a single scan of
log during which redo actions are performed for each log record is encountered.
<T0 start> <T0 start> <T0 start>

<T0 , A , 1000 , 950> <T0 , A , 1000 , 950> <T0 , A , 1000 , 950>

<T0 , B , 2000 , 2050> <T0 , B , 2000 , 2050> <T0 , B , 2000 , 2050>

<T0 commit> <T0 commit>

<T1 start> <T1 start>

<T1 , C , 700 , 600> <T1 , C , 700 , 600>


<T1 commit>

(a) (b)
(c)
(a)

⮚ Assume that the system crash has occurred after the log record for the step

write(B)
of transaction T0 has been written to the stable storage.
⮚ When the system comes back up, it finds the record <T0 start> in the log but no <T0 commit>
or <T0 abort> record.
⮚ Therefore, the Transaction T0 has to be undone (ie) undo(T0).
⮚ As a result, the values of A and B in the disk buffer are restored to $1000 and $2000
respectively.
(b)

⮚ Assume that the system crash has occurred after the log record for the step

write(C)
of transaction T1 has been written to the stable storage.
⮚ When the system comes back up, it finds the record <T0 start> in the log and the record <T0
commit>.
⮚ Therefore the transaction T0 has to perform the operation redo(T0) and the transaction T1 has to be
undone (ie) undo(T1).
⮚ As a result, the values of accounts A , B and C are $950, $2050, $700 respectively.
(c)

⮚ Assume that the system crash has occurred after the log record for the step

<T1 commit>
of transaction T1 has been written to the stable storage.
⮚ When the system comes back up, it finds the record <T0 start> and <T0 commit>
as do the records, <T1 start> and <T1 commit>.
⮚ Therefore the transaction T0 and T1 has to perform the operation redo(T0) and redo(T1).
⮚ As a result, the values of accounts A , B and C are $950, $2050, $600 respectively.
THANK YOU

You might also like