Professional Documents
Culture Documents
TECHNIQUES
Content
Types of Failures
What is Recovery?
Recovery Techniques
Deferred Update
Immediate Update
Shadow Paging
Disk failure: Some disk blocks may lose their data because of a read or write
malfunction or because of a disk read/write head crash.
Recovery from transaction failures usually means that the database is restored to
some state from the past so that a correct state - close to the time of failure - can be
reconstructed from that past state.
redoing committed transaction operations from the log up to the time of failure.
When the database is not physically damaged but has become inconsistent due to
noncatastrophic failures of types 1 through 4 , the strategy is to reverse the changes that
caused the inconsistency by undoing some operations.
The recovery process is often closely interwined with operating system functions.
Typically, one or more disk pages that include the data item to be updated are
cached into a main memory buffer and then updated in memory before being written back
to disk,
A directory for the cache is used to keep track of which database items are in the
buffers.
Associated with each item in the cache is a dirty bit to indicate whether or not the
item has been modified. When an item is flushed, it is written back to disk only if its dirty
bit is 1.
Flushing Techniques
Two main strategies are employed when flushing a modified data item back to
disk:
Shadowing,
Shadowing, writes a new item at a different disk location, so multiple copies of
a data item can be maintained. The old value of the data item before updating is called
before image (BFIM),
(BFIM), and the new value after updating is called the after image
(AFIM).
In-place updating,
updating, writes the data item in the same disk location. Hence, a
single copy of each data item is maintained on disk.
Recovery Techniques
(from non-catastrophic failures, i.e., failures that do not affect
secondary storage or involve destruction of the DBMS)
There are two major techniques for recovery from non-catastrophic transaction
failures:
Deferred updates
Immediate updates
Deferred Updates
The idea behind deferred update techniques is to defer or postpone any actual
updates to the database itself until the transaction completes its execution successfully
and reaches its commit point. During transaction execution, the updates are recorded only
in the log and in the transaction workspace (buffer). After the transaction reaches its
commit point and the log is force-written to disk, the updates are recorded in the database
itself.
If a transaction fails before reaching its commit point, there is no need to undo
any operations, because the transaction has not affected the database in any way.
Deferred Updates Protocol
A transaction cannot change the database until it reaches its commit point.
A transaction does not reach its commit point until all its operations are recorded
in the log and the log is force-written to disk.
Because the database is never updated until after the transaction commits, there is
never a need to UNDO any operations. Hence, this technique is known as NOUNDO/REDO algorithm. The REDO is needed in case the system fails after the
transaction commits but before all its changes are recorded in the database. In this case,
the transaction operations are redone from the log entries.
No
Start_transaction(T)
N/A
N/A
No
Read_item(T,X)
N/A
N/A
No
Write_item(T,X,Old_value,New_value)
No
No
Yes
Commit(T)
Yes
Yes
Create a
Check
point
Yes
(althoug
h writing
back to
disk may
occur not
immediat
ely)
Checkpoint
Yes (of
committed
transactions
When immediate update is allowed, provisions must be made for undoing the
effect of update operations on the database, because a transaction can fail after it has
applied some updates to the database itself. Hence, recovery schemes based on immediate
updates must include the capability to roll back a transaction by undoing the effect of its
write_item operations.
Immediate Updates Rules
1. When a transaction starts, write an entry, start_transaction(T) to the log.
2. When any operation is performed that will change values in the database, write a
log entry write_item(T, X, old_value, new_value).
3. Write the log to disk.
4. Once the log record is written, write the update to the database buffers.
5. When convenient, write the database buffers to the disk.
6. When a transaction is about to commit, write a log record of the form
Commit(T).
7. Write the log to disk.
Activity
Log
Typical Entry to the System Log
Changes Changes
W
writt
written
ri
en to
to
t
the
Databas
e
Data
e Disk
t
base
o
Buffe
D
r
i
s
k
Start
transa
ction T
Read Item
X
Write Item
X
No
Start_transaction(T)
N/A
N/A
No
Read_item(T,X)
N/A
N/A
Yes
Write_item(T,X,Old_value,New_value)
Yes
Yes
(althoug
h writing
back to
disk may
occur not
immediat
ely)
Commit
transa
ction T
Create a
Check
point
Yes
Commit(T)
Yes
Checkpoint
Yes (of
committe
d
transacti
ons
In the Shadow Page scheme, the database is not directly modified but a copy,
stored on permanent storage (e.g. disk), is made of the portion of the database to be
modified and all modifications are made to this copy. Once a transaction commits, the
modified copy replaces the original in an atomic manner, i.e., the replacement is carried
out in its entirety or not at all. If the system crashes at this point, the old version is still
available for recovery.
Page Management:
Virtual memory is divided into pages that are all of a certain size (commonly 2K
or 4K bytes). The virtual or logical pages are mapped onto physical disk blocks of the
same size as the pages. The mapping is achieved by consulting a page table (or directory).
The page table lists each logical page identifier and the address of the physical blocks
that are actually stores the logical page.
A page table (or directory) with n entries is constructed, where the ith page table
entry points to the ith database page (block) on disk.
The page table is kept in main memory if it is not too large, and all references reads or writes - to database pages on disk go through the page table.
When a transaction begins executing, the current page table - whose entries point
to the most recent or current database pages on disk - is copied into a shadow page table.
The shadow page table is then saved on disk while the current page table is used by the
transaction.
The current page table entry is modified to point to the new disk block.
For pages updated by the transaction, two versions are kept. The old version is
referenced by the shadow page table, and the new version by the current page table.
The state of the database before transaction execution is available through the
shadow page table, and that state is recovered by reinstating the shadow page table so that
it becomes the current page table once more.
Shadow Paging
The advantage of shadow paging is that it makes undoing the effect of the
executing transaction very simple.
One disadvantage of shadow paging is that the updated database pages changes
location on disk, this makes it difficult to keep related database pages close together on
disk without complex storage management strategies.
The main technique used to handle such crashes is that of database backup.
backup.
The whole database and the log are periodically copied onto a cheap storage
medium such as magnetic tapes.
tapes.
In case of a catastrophic system failure, the latest backup copy can be reloaded
from the tape to the disk, and the system can be restarted.