Recovery and Atomicity

Recovery and Atomicity

  • When a system crashes, it may have several transactions being executed and various files open for them to modify the data items. 
  • Transactions are made of various operations, which are atomic in nature. According to ACID properties of DBMS, the atomicity of transactions as a whole must be maintained, that is, either all the operations are executed or none.
  • When a DBMS recovers from a crash, it should maintain the following −
    • It should check the states of all the transactions, which were being executed.
    • A transaction may be in the middle of some operation; the DBMS must ensure the atomicity of the transaction in this case.
    • It should check whether the transaction can be completed now or it needs to be rolled back.
    • No transactions would be allowed to leave the DBMS in an inconsistent state.
    • There are two types of techniques, which can help a DBMS in recovering as well as maintaining the atomicity of a transaction −
      • Maintaining the logs of each transaction, and writing them onto some stable storage before actually modifying the database.
      • Maintaining shadow paging, where the changes are done on a volatile memory, and later, the actual database is updated.

Log-based Recovery
  • Log is a sequence of records, which maintains the records of actions performed by a transaction. 
  • It is important that the logs are written prior to the actual modification and stored on a stable storage media, which is failsafe.
  • Log-based recovery works as follows −
    • The log file is kept on a stable storage media.
  • When a transaction enters the system and starts execution, it writes a log about it.
  • When the transaction modifies an item X, it write logs as follows −
  • It reads Tn has changed the value of X, from V1 to V2.
  • When the transaction finishes, it logs −
  • The database can be modified using two approaches −
    • Deferred database modification − All logs are written on to the stable storage and the database is updated when a transaction commits.
    • Immediate database modification − Each log follows an actual database modification. That is, the database is modified immediately after every operation.

Thanks a lot for query or your valuable suggestions related to the topic.

Previous Post Next Post

Contact Form