Transaction is a common word where everyone in this technology uses at least one time in a day. let us see complete information of Transaction , Properties of Transaction(ACID), States of Transaction, and Database Architecture in Transaction in this article.
A transaction is an execution of a user program and is seen by DBMS as a series or list of different from an ordinary program and is the result from the execution of a program written in a high-level data manipulation language or programming language. The statements ‘begin transaction’ and ‘end transaction’ indicates the beginning and ending of a transaction.
In a transaction, access to the database is accomplished by two operations,
The first one performs the reading operation of data item x from the database, whereas the second one performs the writing operation of data item x to the database. Consider a transaction T, which transfers $100 from ‘A’ account to ‘B’ account. This transaction will be as follows,
Ti : = read(A);
A := A-100;
B:=B + 100;
The Properties of Transaction (ACID- Atomicity, Consistency, Isolation, Durability)
These are the properties that a transaction should posses in order to avoid failures during concurrent access to a database. ACID is nothing but Atomicity, Consistency, Isolation and Durability.
Atomicity ensures that the transaction should either be executed completely or not at all. This is because incomplete execution of the transactions results in negative consequences. Consider an example of which contains a transaction of crediting and debiting an amount from the account. Suppose Pavani had ₹ 500/- in her account and Vasavi has ₹ 200/- in her account. Now Pavani transfers an amount of ₹ 50/- to Vasavi. Now the transaction from Pavani’s account will get debited first and could be credited to Vasavi’s account, In case a failure of the transaction would result in a loss of ₹ 50/-. Because, the amount is deducted from Pavani’s account but it is not added to Vasavi’s account. This makes the data to be in an inconsistent state. If there is a failure during transaction execution, then measures should be taken by transaction management component to get the data in a form which it was prior to the transaction failure.
The data which is in the database should be in a consistent form. A transaction that is carried on a consistent data should bring the data to another consistent state after execution. However, transaction need not maintain consistency at intermediate stages. Example: If amount is debited from account ‘A’ and credited to account ‘B’, after the transaction the sum A + B should be same as it was before transaction. However at an intermediate stage, where the amount is deducted from A but not yet credited to B, the sum A + B would not be same this may result in inconsistency. And therefore, it is the responsibility of application program to ensure consistency.
All transactions should run in isolation. That is every transaction should be kept unaware of other transactions and execute independently. The intermediate results generated by the transactions should not be available to other transactions.
This property ensures that data remains in a consistent state even after the failure. This is ensured by loading modified data into disk. It ensures that either the complete modified data is loaded into disk or the information that would be sufficient to get the modified data is loaded in disk, which makes to recover the system after a system-crash.
Different States of Transactions
The different states of transactions are as follows,
1. Active state 2. Partially committed state 3. Fail state 4. Abort state
5. Full committed state.
A transaction is said to be in active state if it is in execution. It is therefore considered as the initial state.
Partially Committed State
A transaction is in partially committed state if its last statement is been executed. Though the transaction had finished its execution in this state, there is a possibility that it might get aborted either due to hardware or software failure. In order to avoid the data loss, the data is stored temporarily in the main memory, This helps in recreating the updates done by the aborted transactions in case of system failure.
A transaction is in failed state, if the execution of the transaction cannot be processed, and the system performs the roll back operation.
The roll back transaction enters the abort state when the system performs any one of the following operation, Restart: If the transaction was aborted due to hardware or software failure, then the transaction can be restarted, such transaction is considered as a new transaction. Kill: If there is an internal-logical error due to bad input then the transaction is aborted and killed by the system.
Full Committed State
If every statement of the transaction is successfully completed, then it is said to be in full committed state. If every statement of the transaction is successfully completed, then it is said to be in full committed state.
Typical database architecture with modules that manage transactions, concurrency control and recovery is shown in the figure below,
It manages the transactions so as to ensure that data remain in consistent state even after the system failures. It also enables the execution of concurrent transactions without any conflicts.
The task of scheduler is to apply appropriate concurrency control mechanism while interacting with the transaction manager. In case if the adopted mechanism is based on the concept of locking it acts as a lock manager. Use of scheduler increases the rate of concurrent transactions while eliminating the risk of interfering each other.
3. Recovery Manager
Recovery manager is responsible for restoring the failed database to a consistent state. It typically roll back the failed transaction.
4. Buffer Manager
It handles the transfer of data from disk onto main memory and decides what data must be kept in main memory
5. File Manager
It manages the process of allocating disk and data structures that are used for representing the information saved on disk.
6. Authorization Manager
It checks the authority of users and allows only authorized users to access the data.
7. System Manager
System manager acts as a query processor which retrieves the data from database.
If you are interested to read more articles on (Database Management Systems)DBMS you can check here: Database Management