Chapter 16
Chapter 16
Failure Classification
Storage Structure
Recovery and Atomicity
Log-Based Recovery
Recovery Algorithm
Chapter 16: Recovery System
Database System Concepts - 6th Edition 16.2 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 6th Edition 16.3 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.4 ©Silberschatz, Korth and Sudarshan
Storage Structure Data Access
Volatile storage: Physical blocks are those blocks residing on the disk.
does not survive system crashes System buffer blocks are the blocks residing temporarily in main
memory.
examples: main memory, cache memory
Block movements between disk and main memory are initiated
Nonvolatile storage: through the following two operations:
survives system crashes input(B) transfers the physical block B to main memory.
examples: disk, tape, flash memory, output(B) transfers the buffer block B to the disk, and replaces
non-volatile (battery backed up) RAM the appropriate physical block there.
but may still fail, losing data We assume, for simplicity, that each data item fits in, and is stored
Stable storage: inside, a single block.
a mythical form of storage that survives all failures
approximated by maintaining multiple copies on distinct
nonvolatile media
Database System Concepts - 6th Edition 16.5 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.8 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 6th Edition 16.9 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.10 ©Silberschatz, Korth and Sudarshan
Recovery and Atomicity Log-Based Recovery
To ensure atomicity despite failures, we first output A log is kept on stable storage.
information describing the modifications to stable storage The log is a sequence of log records, which maintains
without modifying the database itself. information about update activities on the database.
We study log-based recovery mechanisms in detail When transaction Ti starts, it registers itself by writing a record
<Ti start>
We first present key concepts
to the log
And then (module 17) present the actual recovery
algorithm Before Ti executes write(X), a log record
<Ti, X, V1, V2>
Less used alternative: shadow-paging (brief details is written, where V1 is the value of X before the write (the old value),
presented in the book). and V2 is the value to be written to X (the new value).
In this Module we assume serial execution of transactions. When Ti finishes it last statement, the log record <Ti commit> is
In Module 17, we consider the case of concurrent written.
transaction execution. Two approaches using logs:
Immediate database modification
Deferred database modification
Database System Concepts - 6th Edition 16.11 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.12 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 6th Edition 16.13 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.14 ©Silberschatz, Korth and Sudarshan
Immediate Database Modification Example Undo and Redo Operations
Log Write Output Undo of a log record <Ti, X, V1, V2> writes the old value V1 to X
Redo of a log record <Ti, X, V1, V2> writes the new value V2 to X
<T0 start>
Undo and Redo of Transactions
<T0, A, 1000, 950>
undo(Ti) restores the value of all data items updated by Ti to
<To, B, 2000, 2050>
their old values, going backwards from the last log record for Ti
A = 950
B = 2050 4 Each time a data item X is restored to its old value V, a
special log record (called redo-only) <Ti , X, V> is written out
<T0 commit>
4 When undo of a transaction is complete, a log record
<T1 start>
<T1, C, 700, 600> <Ti abort> is written out (to indicate that the undo was
BC output before T1 completed)
C = 600 commits
BB , BC redo(Ti) sets the value of all data items updated by Ti to the new
<T1 commit> values, going forward from the first log record for Ti
BA 4 No logging is done in this case
BA output after T0
Note: BX denotes block containing X. commits
Database System Concepts - 6th Edition 16.15 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.16 ©Silberschatz, Korth and Sudarshan
Undo and Redo Operations (Cont.) Undo and Redo on Recovering from Failure
The undo and redo operations are used in several When recovering after failure:
different circumstances: Transaction Ti needs to be undone if the log
The undo is used for transaction rollback during 4 contains the record <Ti start>,
normal operation (in case a transaction cannot 4 but does not contain either the record <Ti commit>
complete its execution due to some logical error).
Transaction Ti needs to be redone if the log
The undo and redo operations are used during
recovery from failure. 4 contains the records <Ti start>
We need to deal with the case where during recovery 4 and contains the record <Ti commit>
from failure another failure occurs prior to the system
having fully recovered.
Database System Concepts - 6th Edition 16.17 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.19 ©Silberschatz, Korth and Sudarshan
Immediate Modification Recovery Example Checkpoints
Redoing/undoing all transactions recorded in the log can be very slow
Below we show the log as it appears at three instances of time.
Processing the entire log is time-consuming if the system has run for
a long time
We might unnecessarily redo transactions which have already output
their updates to the database.
Streamline recovery procedure by periodically performing checkpointing
All updates are stopped while doing checkpointing
1. Output all log records currently residing in main memory onto stable
storage.
Recovery actions in each case above are: 2. Output all modified buffer blocks to the disk.
(a) undo (T0): B is restored to 2000 and A to 1000, and log records
3. Write a log record < checkpoint L> onto stable storage where L is a
<T0, B, 2000>, <T0, A, 1000>, <T0, abort> are written out
list of all transactions active at the time of checkpoint.
(b) redo (T0) and undo (T1): A and B are set to 950 and 2050 and C is
restored to 700. Log records <T1, C, 700>, <T1, abort> are written out.
(c) redo (T0) and redo (T1): A and B are set to 950 and 2050
respectively. Then C is set to 600
Database System Concepts - 6th Edition 16.20 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.21 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 6th Edition 16.22 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.23 ©Silberschatz, Korth and Sudarshan
Recovery Schemes Concurrency Control and Recovery
With concurrent transactions, all transactions share a single disk
So far: buffer and a single log
We covered key concepts A buffer block can have data items updated by one or more
We assumed serial execution of transactions transactions
Database System Concepts - 6th Edition 16.25 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.26 ©Silberschatz, Korth and Sudarshan
work area work area – such log records are called compensation log records
of T1 of T2 Once the record <Ti start> is found stop the scan and write the log
record <Ti abort>
memory disk
Database System Concepts - 6th Edition 16.27 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.28 ©Silberschatz, Korth and Sudarshan
Recovery Algorithm Recovery Algorithm
Create undi-list and redo-list: Recovery:
1. Initial undo-list = Æ and redo-list = Æ 1. Scan log backwards from end until <Ti, start> has been found for
2. Scan log file backward from the end to the last <checkpoint L> every transaction in undo-list: undo(Ti)
1. Whenever a <Ti, commit> is found: 2. Find last <checkpoint L> record: scan forward the log file and
⇒ add Ti into the redo-list preform undo(Ti) for every Ti in redo-list
Database System Concepts - 6th Edition 16.31 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.32 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 6th Edition 16.33 ©Silberschatz, Korth and Sudarshan Database System Concepts - 6th Edition 16.34 ©Silberschatz, Korth and Sudarshan
End of Chapter 16
Database System Concepts - 6th Edition 16.82 ©Silberschatz, Korth and Sudarshan