Ch6-Recovery Systems
Ch6-Recovery Systems
Failure Classification
Storage Structure
Recovery and Atomicity
Recovery Algorithms
Buffer Management
Failure with loss of non-volatile storage
Failure Classification
Transaction failure :
Logical errors: transaction cannot complete due to some internal
error condition such as bad input, data not found, overflow, etc.
System errors: The system has entered an undesirable state (for
example, deadlock), as a result of which a transaction cannot
continue with its normal execution.
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 failure during data transfer destroys all or
part of disk storage
Destruction is assumed to be detectable: disk drives use checksums
to detect failures
Storage Structure
Volatile storage:
does not survive power failure, system crashes
examples: main memory, cache memory
Nonvolatile storage:
survives power failure, system crashes
examples: disk, tape, flash memory,
non-volatile (battery backed up) RAM
but may still fail, losing data
Stable storage:
a mythical form of storage that survives all failures
approximated by maintaining multiple copies on distinct
nonvolatile media
Stable-Storage Implementation
To implement stable storage, we need to replicate the needed
information in several non volatile storage media (usually disk) and to
update the information in a controlled manner to ensure that failure
during data transfer does not damage the needed information.
More secure systems keep a copy of each block of stable storage at a
remote site, writing it out over a computer network, in addition to
storing the block on a local disk system.
Since the blocks are output to a remote system as and when they are
output to local storage, once an output operation is complete, the data
is not lost, even in the event of a disaster such as a fire or flood.
Maintain multiple copies of each block on separate disks
copies can be at remote sites to protect against disasters such as
fire or flooding.
Stable-Storage Implementation
Failure during data transfer at remote site can still result in
inconsistent copies: Block transfer can result in
Successful completion. The transferred information arrived safely at its
destination.
Partial failure. A failure occurred in the midst of transfer, and the
destination block has incorrect information.
Total failure. The failure occurred sufficiently early during the transfer that
the destination block remains intact.
❑ Protecting storage media from failure during data transfer (one
solution): The system maintain two physical blocks for each logical
database block.
❑ Execute output operation as follows (assuming two copies of each
block):
1. Write the information onto the first physical block.
2. When the first write successfully completes, write the same
information onto the second physical block.
3. The output is completed only after the second write
successfully completes.
Stable-Storage Implementation (Cont.)
If the system fails while blocks are being written, it is possible that the
two copies of a block are inconsistent with each other.
During recovery, for each block, the system would need to examine two
copies of the blocks. If both are the same and no detectable error
exists, then no further actions are necessary.
If the system detects an error in one block, then it replaces its content
with the content of the other block.
If both blocks contain no detectable error, but they differ in content,
then the system replaces the content of the first block with the value of
the second.
This recovery procedure ensures that a write to stable storage either
succeeds completely (that is, updates all copies) or results in no
change.
Data Access
the database system resides permanently on nonvolatile storage (usually
disks) and only parts of the database are in memory at any time.
Database is partitioned into fixed-length storage units called blocks.
Physical blocks are those blocks residing on the disk.
Buffer blocks are the blocks residing temporarily in main memory.
Disk buffer area of main memory where blocks resides temporarily.
Block movements between disk and main memory are initiated through the
following two operations:
input(A) transfers the physical block A from disk to main memory.
output(B) transfers the buffer
block B from main memory to
the disk, and replaces the
appropriate physical block there.
Data Access (Cont.)
Each transaction Ti has its private work-area in which local copies of
all data items accessed and updated by it are kept.
The system creates this work area when the transaction is initiated;
the system removes it when the transaction either commits or aborts.
Ti's local copy of a data item X is called xi.
Transferring data items between system buffer blocks and its private
work-area done by:
read(X) assigns the value of data item X to the local variable xi.
write(X) assigns the value of local variable xi to data item {X} in
the buffer block.
Transactions
Must perform read(X) before accessing X for the first time
(subsequent reads can be from local copy)
write(X) can be executed at any time before the transaction
commits
Example of Data Access
buffer
Buffer Block A input(A)
X A
Buffer Block B Y B
output(B)
read(X)
write(Y)
x2
x1
y1
memory disk
Recovery and Atomicity
Modifying the database without ensuring that the transaction will
commit may leave the database in an inconsistent state.
Consider transaction Ti that transfers $50 from account A to
account B;.
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
Goal is either to perform all database modifications made by Ti or
none at all
Several output operations may be required for Ti (to output A
and B). A failure may occur after one of these modifications have
been made but before all of them are made.
Recovery and Atomicity
To ensure atomicity despite failures, we first output
information describing the modifications (logs) to stable
storage without modifying the database itself.
log-based recovery mechanisms:
Deferred Database Modification
Immediate Database Modification
Less used alternative: shadow-paging
Log-Based Recovery
Log is the most widely used structure for recording database
modifications.
The log is a sequence of log records, and maintains a record of
update activities on the database.
A log is kept on stable storage.
It has these fields:
Transaction Identifier
Data-item Identifier
Old Value
New Value
Log-Based Recovery
When transaction Ti starts, it registers itself by writing a
<Ti start>log record
Before Ti executes write(X), a log record
<Ti, X, V1, V2>
is written, where V1 is the value of X before the write (the old
value), and V2 is the value to be written to X (the new value).
When Ti finishes it last statement, the log record <Ti commit>
is written.
We assume for now that log records are written directly to
stable storage.
Deferred Database Modification
The deferred database modification scheme ensures atomicity
by recording all modifications to the log, but defers all the write
operations of a transaction until transaction partial commit.
Assume that transactions execute serially.
Transaction starts by writing <Ti start> record to log.
A write(X) operation results in a log record <Ti, X, V> being
written, where V is the new value for X
Note: old value is not needed for this scheme
The write is not performed on X at this time, but is deferred.
When Ti partially commits, <Ti commit> is written to the log
Finally, the log records are read and used to actually execute the
previously deferred writes.
Deferred Database Modification (Cont.)
During recovery after a crash, a transaction needs to be redone if
and only if both <Ti start> and<Ti commit> are there in the log.
Redoing a transaction Ti ( redoTi) sets the value of all data items
updated by the transaction to the new values.
Crashes can occur while
the transaction is executing the original updates, or
while recovery action is being taken
example transactions T0 and T1 (T0 executes before T1):
T0: read (A) T1 : read (C)
A: - A - 50 C:- C- 100
Write (A) write (C)
read (B)
B:- B + 50
write (B)
State of the Log and Database Corresponding
to T0 and T1
Deferred Database Modification (Cont.)
Below we show the log as it appears at three instances of time.
Tc Tf
T1
T2
T3
T4
……
<checkpoint L>
…..
<checkpoint L>
last_checkpoint
…..
Log
Failure with Loss of Nonvolatile Storage
So far we assumed no loss of non-volatile storage.
Technique similar to checkpointing used to deal with loss of non-
volatile storage
Periodically dump the entire content of the database to stable
storage
If a failure occurs that result in the loss of physical database blocks,
the most recent dump is used in restoring the database to a
previous consistent state.
No transaction may be active during the dump procedure; a
procedure similar to checkpointing must take place
Output all log records currently residing in main memory onto
stable storage.
Output all buffer blocks onto the disk.
Copy the contents of the database to stable storage.
Output a record <dump> to log on stable storage.
Recovering from Failure of Non-Volatile Storage
To recover from disk failure
restore database from most recent dump.
Consult the log and redo all transactions that committed after
the dump
Can be extended to allow transactions to be active during dump;
known as fuzzy dump or online dump
Similar to fuzzy checkpointing
End of Chapter