Professional Documents
Culture Documents
Cannot commit transaction without first writing all changes to the disk.
Commit is slow as all changes must be updated to disk before commit.
It is often efficient to keep changes in memory for a while.
Other transactions are also updating.
Better to write update to disk after changes done by multiple transactions.
Otherwise disk I/O may need to be done multiple times.
03/20/2024
Remember a <> log record for redo logging uses the new value v instead of old value
[which is the case for undo logging]
The following order is strictly followed writing updates and log records to disk:
1. The log records <> for each X.
2. The <> log record.
3. The updated elements X.
03/20/2024
Consider the transaction and the log records for redo logging.
Note that <> records are ahead of <> log record.
Note the <> records and <> record is flushed to disk before updated As and Bs are
flushed to disk.
03/20/2024
Committed vs uncommitted:
If there is a <>, then T is committed; otherwise uncommitted.
In redo logging recovery, nothing needs to be done for uncommitted transactions.
[Why?]
Algorithm for recovery after a system crash:
Identify all committed transactions.
Scan the log forward from the beginning. For each log record <> encountered,
perform the following:
If T is a committed transaction, update X with new value v.
If T is uncommitted, do nothing.
For each incomplete transaction, write an <> record and flush the log.
03/20/2024
Recovery with redo logging
Analyze the steps performed by recovery manager if the system crashes:
After <> written to disk
After <> written to disk
After <> written to disk
03/20/2024
03/20/2024
Example:
Checkpoint started when was active but committed.
Element A must be written to disk before <>
is written to disk log.
Note the log records before <> and
<>. Active transactions were still writing to log.
03/20/2024
03/20/2024
03/20/2024
03/20/2024
Undo logging problem: Undo logging requires that data be written to disk after a
transaction committed.
This increases number of disk I/Os.
Redo logging problem: Redo logging requires that data be kept in buffers till
transactions is committed.
This increases average number of buffers required in memory.
Undo+redo logging: An efficient approach is combining both undo and redo logging
mechanism.
Requires us to store more information in log records.
03/20/2024
03/20/2024
Undo/Redo Logging Rules
Consider the transaction below undo/redo logging.
Note <COMMIT T> is not flushed while A and B are written to disk.
03/20/2024
Recovery With Undo/Redo Logging
Recover process in undo/redo logging:
Step 1: Redo all the committed transactions in the order earliest-to-latest.
Step 2: Undo all the uncommitted transactions in the order latest-to-earliest.
What happens if redo and undo involve transactions modifying same element X?
Suppose X is modified by and is uncommitted.
X is modified by and is committed.
Now, if Step 1 “redo” is done first and then Step 2 “undo” then there is a possibility that ’s
changes will not be reflected.
Now, if Step 2 “undo” is done first and then Step 1 “redo” then there is a possibility that ’s
changes may not be reflected.
03/20/2024
Recovery With Undo/Redo Logging
Analyze the recovery for the following cases:
Crash occurs after <> flushed to disk.
Crash occurs before <> flushed to disk.
03/20/2024
Checkpointing Undo/Redo Log
Algorithm for checkpointing:
Write a log record <> where are all active (uncommitted) transactions. Flush this
log.
Write to disk all DB elements X that were updated but not written to disk.
Unlike redo logging, flush all dirty buffers! [all buffers updated by both
committed and uncommitted transactions]
Write an <> log record. Flush the log.
03/20/2024
Recovery Under Checkpointing
03/20/2024
Protect From Media Failures
Archiving:
Maintain a copy of the database
Shutdown the database and copy database state to a backup storage medium such
tape or optical device
Copy all log files starting from an archived copy.
The log files can be used to store the database state using archived copy.
Once log is written to disk, it is also written to an archived medium.
To prevent from site failure, log can be written to remote site
03/20/2024
Archiving
Database archives can be two types:
Full dump: A full dump in which entire database is copied
Incremental dump: An incremental dump in which database changed since the
previous full dump are copied.
03/20/2024
Nonquiescent Archiving
It is always not possible to shutdown database for archiving.
Non-quiescent arching can be taken without shutting down the database.
Algorithm:
Write a log record <START DUMP>.
Perform a checkpoint appropriate for whichever logging method is used.
Perform a full or incremental dump of data disk, making sure the copy of the
database has reached the remote site.
Make sure enough of the log has been copied to the remote site at least of the log
up to the checkpoint above to survive a media failure of the database.
Write a log record <END DUMP>.
03/20/2024
Nonquiescent Archiving
Example scenario of dump:
Safe to ignore log records before <START CKPT(T1,T2)>. [why? ]
03/20/2024
Recovery from archived log
Step1: Restore the database from the archive.
Find the most recent full dump and reconstruct the database from it.
If there are later incremental dump, modify the database according to each, earliest
first.
Step 2: Modify the database using surviving logs.
Use the method of recovery appropriate to the log method being used.
03/20/2024