Recovery Techniques
Recovery Techniques
Recovery Techniques
Recovery Concepts
I. The Purpose of Database Recovery:
To bring the database into the last consistent state, which existed prior
to the failure.
To protect transaction properties (Atomicity & Durability).
The recovery manager of a DBMS is responsible to ensure
Atomicity by undoing the action of transaction that do not
commit
Durability by making sure that all actions of committed
transaction survive system crash.
– DBMS starts at time t0, but fails at time tf and tc is the last check point.
– T1 and T6 have to be undone.
– T2 and T3, no need of redo or undone
4
–
Recovery Concepts …
III. Data Caching
Data items to be modified are first stored into database cache
by the Cache Manager (CM) and after modification they are
flushed (written) to the disk
When DBMS request for read/write operation on some item
It checks the requested data item is in the cache or not
If it is not, the appropriate disk block are copied to the
cache.
If the cache is already full, some buffer replacement policy
can be used. Like
Least recent used (LRU)
FIFO
While replacing buffers, first of all the updated value on that
buffer should be saved on the appropriate block in the
database 5
Recovery Concepts …
Two main strategies can be employed when flushing a
modified buffer back to disk.
i. Shadowing update:
The modified version of a data item does not overwrite its
disk copy but is written at a separate disk location.
Thus the old value ( before image BFIM) and the new value
(AFIM) are kept in the disk
ii. In-place updating: The disk version of the data item is
overwritten by the cache version.
6
Recovery Concepts …
Standard Recovery Terminology
Possible ways for flushing database cache to database disk:
i. No-Steal: Cache cannot be flushed before transaction commit.
ii. Steal: Cache can be flushed before transaction commits
iii. Force: if all Cache updates are immediately flushed (forced) to
disk when a transaction commits----- force writing
iv. No-Force: if Cached are flushed to a disk when the need arise
after a committed transaction
7
Recovery Concepts …
VI. Check pointing
Log file or record file is used to recover failed DB but we may not know how
far back in the log to search.
Thus, Checkpoint is a Point of synchronization between database and log
file.
Time to time (randomly or under some criteria) the database flushes its buffer
to database disk to minimize the task of recovery.
When failure occurs, redo all transactions that committed since the
checkpoint and undo all transactions active at time of crash.
In previous example , with checkpoint at time tc, changes made by T2 and
T3 have been written to secondary storage. Thus: only redo T4 and T5, undo
transactions T1 and T6.
The following steps defines a checkpoint operation:
i. Suspend execution of transactions temporarily.
ii. Force write modified buffer data to disk.
iii. Write a [checkpoint] record to the log, save the log to disk.
iv. Resume normal transaction execution.
8
Recovery Concepts …
VII. Transaction Roll-Back(Undo) and Roll-Forward(Redo)
If a transaction fails for whatever reason after updating the database, it may
be necessary to roll back the transaction.
To maintain such cases, a transaction’s operations are redone or undone.
Undo: Restore all BFIMs on to disk (Remove all AFIMs).
Redo: Restore all AFIMs on to disk.
Database recovery is achieved either by performing only Undos or only
Redos or by a combination of the two. These operations are recorded in the
log as they happen.
If a transaction T is rolled back, any transaction S that has, in the interim,
read the value of some data item X written by T must also be rolled back.
Similarly, once S is rolled back, any transaction R that has read the value of
some data item Y written by S must also be rolled back, and so on.
This phenomenon is called cascading rollback
9
Thank You
Any Question???
10