Recovery and Atomicity

Recovery and Atomicity

Published by: Sareena Kumari Basnet

Published date: 30 Jul 2024

Recovery and Atomicity

Recovery

  • Purpose: Recovery procedures ensure that the database can be restored to its previous state following a failure, whether it is a transaction, system, or media failure.
  • Components:
    • Transaction logs: Record all changes to the database so that recovery processes can rebuild its state.
    • Checkpointing: Periodically saves the database's state, decreasing the amount of labor required for recovery.
  • Recovery algorithms: Techniques for restoring the database include:
    • Deferred Update: Changes are logged in logs and applied to the database only after a transaction is committed. If a transaction fails, there are no modifications to undo.
    • Immediate Update: Changes are applied immediately, and logs can be used to undo (rollback) or redo (rollforward) operations as needed.
    • Shadow Paging: Uses a copy-on-write approach to keep a shadow page and only switches to the new page when the transaction is committed.

Recovery Techniques

1. Rollback (undo)

  • Used to undo changes caused by a failed or incomplete transaction.
  • Ensures that the database returns to the state it was in before the transaction began.

2. Rollforward (Redo)

  • Used after a system crash to reapply modifications from committed transactions that were not written to the database.
  • Checks that all committed transactions are reflected in the database.

Atomicity

  • Definition: Atomicity is one of the ACID properties of database transactions. It ensures that a sequence of activities within a transaction is handled as a single entity.
  • Principle: All operations in a transaction must be completed; if any operation fails, the entire transaction must be reversed, restoring the database to its original state.
  • Example: In a bank transfer, if debiting one account works but crediting the receiving account fails, the operation is reversed, affecting neither account.

Ensuring Atomicity and Recovery

  • Write Ahead Logging (WAL): Ensures that all modifications are logged before they are applied to the database. This enables the system to reapply modifications in the event of a failure.
  • Checkpointing: Periodically saves a consistent database state, minimizing recovery time and resources.
  • Backup and restore: Backups of the database and transaction logs are performed on a regular basis to provide for restoration in the event of a catastrophic failure.

Atomicity ensures that a transaction is an indivisible unit, either fully completed or not at all, whereas recovery techniques ensure that the database may be restored to a consistent state following a failure. These concepts are essential for ensuring data integrity, consistency, and reliability in a database management system.
 

FAQs About Topic
Atomicity is one of the ACID properties of database transactions. It ensures that a sequence of activities within a transaction is handled as a single entity.
The purpose of recovery is to return the database to a consistent state after a failure, preserving all committed transactions while rolling back incomplete transactions.
Shadow paging maintains a copy of the database pages. Changes are made to a shadow page, and when committed, the shadow page becomes the actual page, assuring atomicity without the need for undo log files.