img
Question:
Published on: 3 December, 2024

With suitable examples, show how recovery in a database system can be done using Log Files with

  • Immediate updation
  • Deferred updation
Answer:

 

Deferred Update Recovery

  • Also called NO-UNDO/REDO
  • During a transaction, only record the changes to data items in the log.
  • When the transaction commits, actually update the data items on disk.

Two main rules:

  • A transaction cannot change any items in the database until it commits.
  • A transaction may not commit until all the write operations are successfully recorded in the log. This means that we must check to see that the log is actually written to disk.

Recovery:

  • we simply ignore those transactions that did not commit.

Advantages:

  • Recovery is made easier: Any transaction that reached the commit point (from the log) has its writes applied to the database (REDO). All other transactions are ignored
  • Cascading rollback does not occur because no other transaction sees the work of another until it is committed (no stale reads).

Disadvantages:

  • Concurrency is limited: Must employ Strict 2PL which limits concurrency.

 

Immediate Update Recovery

  • Immediate Update applies the write operations to the database as the transaction is executing (as opposed to at the end as with deferred update).
  • Writes are still saved in the log before being applied to the database - a write-ahead log (WAL)
  • Maintain two logs:
    1. REDO log: A record of each new data item in the database.
    2. UNDO log: A record of each updated data item (old values).

Two rules:

  • Transaction T may not update the database until all UNDO entries have been written to the UNDO log.
  • Transaction T is not allowed to commit until all REDO and UNDO log entries are written (forced-written to disk).

To Recover:

  • Begin at the end of the log and read backwards to the last checkpoint. Create two lists:
    C - transactions that have committed, NC - transactions that did not commit
  • For each transaction T in C, make a third list of transactions, RB, that have read items that were updated by NC transactions during T.
  • UNDO: Undo the effects of the transactions in NC and RB.
  • REDO: Apply the effects of all of the transactions that did commit (all T in list C)

Advantages:

  • Immediate update allows higher concurrency because transactions write continuously to the database rather than waiting until the commit point.

Disadvantages:

  • Step 2 above can lead to cascading rollbacks - time consuming and may be problematic.

 

 

 

Random questions