Database Recovery Techniques: Closely Related To Concurrency Control Protocols
Database Recovery Techniques: Closely Related To Concurrency Control Protocols
Database Recovery Techniques: Closely Related To Concurrency Control Protocols
Goals:
• After failure (for example deadlock & abort),
restore a consistent state
• Minimize the loss of work
Means:
• Auxiliary data sets (log, backup)
Undo:
• Scan the log file backwards and apply the
before-images in this order, or
scan the log file forward and apply only the
first before-image of each updated item.
Redo:
• Scan the file forward and apply the after-
images in this order, or
scan the log file backwards and apply only the
last after-image of each updated item.
AdvDB-5 J. Teuhola 2015 139
Update alternatives: Deferred update
• NO-UNDO/REDO
• Updates first to local copies in transaction workspace,
at commit to the log and then to the database.
• Buffer space may become restrictive (transactions
should be small).
• NO UNDO: Effects become visible at commit
• REDO: Needed if the system fails after commit but
before all cache pages are written to disk.
But: Is the write phase during commit atomic?
(Is rollback needed, anyway?)
In-place updating:
• Write the updated value in the same location as
before; the log is needed for recovery;
this approach is applied by most DBMSs.
‘Shadowing’:
• Write the new (updated) entry in a different disk
location; the log can possibly be avoided
(NO-UNDO / NO-REDO), but different versions
of data must be managed.
AdvDB-5 J. Teuhola 2015 142
Recovery concepts: Steal & force
Steal approach:
• Updated page can be written to disk before
commit (opposite: no-steal approach).
Advantage of steal: smaller buffer.
Force approach (UNDO/NO-REDO):
• All updated pages are written to disk at
commit. Advantage: no redo
No-force approach (UNDO/REDO):
• Physical write possible after commit.
Advantage: More hits from the buffer.
AdvDB-5 J. Teuhola 2015 143
Transaction lists & checkpoints
Fuzzy checkpoint:
• Writing of the checkpoint is done parallel with
transactions (no interrupt in processing).
• The new checkpoint becomes valid when completed.
Data object
Logical Physical
page page Slot
number address index
Page table
Functions:
• Start of transaction: Copy the current page
table to the shadow table.
• Commit: Discard the shadow page table,
free the referenced old pages.
• Recovery: Discard the current page table,
reinstate the shadow page table, free the
new pages.
Advantages:
• Simple recovery, no log in single-user
systems (in multi-user systems, logs and
checkpoints needed for concurrency control).
Disadvantages:
• Fragmentation of storage (clustering lost).
• Writing the shadow table to disk takes time.
• Garbage collection of pages needed.
Recovery:
• Load the backup and restart the system.
• Reconstruct the effects of committed
transactions from the log.