Transaction Model and ACID Properties

Transaction Model and ACID Properties

Published by: Sareena Kumari Basnet

Published date: 28 Jul 2024

Transaction Model and ACID Properties

Transaction Concept 

The transaction is a set of logically related operation. It contains a group of tasks. A transaction is an action or series of actions. It is performed by a single user to perform operations for accessing the contents of the database.

States of Transaction

In a database, the transaction can be in one of the following states -

Active state

  • The active state is the first state of any transaction. The transaction is currently being processed.

  • For example, insertion, deletion, or updating a record is performed here. However, all of the records are still not saved in the database.

Partially committed

  • In the partially committed state, a transaction completes its final activity but does not save the data to the database.
  • In the total mark calculation example, the final display of the total marks step is carried out in this condition.

Committed

  • A transaction is said to be committed if it completes all of its actions successfully. In this condition, all effects are permanently stored on the database system.

Failed state

  • If any of the database recovery system's checks fail, the transaction is considered to be in the failed state.
  • In the case of total mark calculation, if the database cannot run a query to retrieve the marks, the transaction will fail.

Aborted

  • If any of the checks fail and the transaction enters a failed state, the database recovery system will restore the database to its previous consistent state. If not, it will terminate or rollback the transaction to restore the database to a consistent state.
  • If the transaction fails in the middle, all executed transactions are rolled back to their consistent state prior to the transaction being conducted.
  • After aborting the transaction, the database recovery module will choose one of two operations:
  1. Restart the transaction.
  2. Kill the transaction.

Transaction property

The transaction has the four properties. These are used to maintain consistency in a database, before and after the transaction.

ACID Properties

A transaction is a very small unit of a program that may include numerous low-level tasks. To ensure correctness, completeness, and data integrity, database transactions must adhere to the ACID characteristics (Atomicity, Consistency, Isolation, and Durability).

1. Atomicity

  • It indicates that all transaction operations must take place immediately; else, the transaction is aborted.
  • There is no midway, so the transaction cannot be completed in stages. Each transaction is handled as a single entity, which is either completed or not done.

Atomicity consists of the following two operations:

Abort: If a transaction is aborted, all modifications are lost.
Commit: If a transaction is committed, all modifications performed are visible.

Example: Let's assume that following transaction T consisting of T1 and T2. A consists of Rs 600 and B consists of Rs 300. Transfer Rs 100 from account A to account B.

After completion of the transaction, A consists of Rs 500 and B consists of Rs 400.

If the transaction T fails after the completion of transaction T1 but before completion of transaction T2, then the amount will be deducted from A but not added to B. This shows the inconsistent database state. In order to ensure correctness of database state, the transaction must be executed in entirety.

2. Consistency

  • The integrity constraints are maintained so that the database remains consistent before and after the transaction.
  • A transaction will leave a database in one of two stable states: the previous one or the new one.
  • The consistent property of a database specifies that every transaction encounters a consistent database instance.
  • The transaction transforms the database from one consistent state to another.

For example: The total amount must be maintained before or after the transaction.

Therefore, the database is consistent. In the case when T1 is completed but T2 fails, then inconsistency will occur.

3. Isolation

  • It shows that the data used during the execution of one transaction cannot be used by the second transaction until the first is done.
  • In isolation, if transaction T1 is being executed and using the data item X, no other transaction T2 can access that data item until T1 completes.
  • The DBMS's concurrency control subsystem enforced the isolation property.

4. Durability

  • The durability property is used to assess the consistency of the database's state. It states that the transaction brought about permanent changes.
  • They cannot be lost due to the incorrect execution of a defective transaction or a system breakdown. When a transaction is finished, the database enters a state known as the consistent state. Even if a system fails, the consistent state cannot be lost.
  • Durability is the responsibility of the DBMS's recovery subsystem.


 

 

FAQs About Topic
The transaction is a set of logically related operation. It contains a group of tasks. A transaction is an action or series of actions.
ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure reliable processing of database transactions.
A commit is a procedure that completes a successful transaction by making any changes made during the transaction permanent in the database. A rollback is an operation that reverses any changes made during the current transaction and returns the database to its former state.