In this tutorial you are going to learn about Transactions and Concurrency Control in Distributed System.
Transaction
Transaction is a collection of related read and write operations used to perform some related task.
The read or write operation performs a specific unit of work. A transaction will depend on only two outcomes - success or failure.
When a transaction starts execution, it could be terminated by two possibilities which are abort or commit.
A transaction is said to be aborted when it does not continue to a successful end or its not successfully completed whereas a transaction is committed when execution is successfully done and the changes will be stored. A database transaction can be atomic, consistent, isolated and durable. This is often referred to as the ACID.
Example: R(A) A=A+500 W(A) R(B) B=B-500 W(B) Commit |
Where R(A) is a read operation to read a data item A, W(A) is a write operation to write a data item A and commit is a commit operation to commit the transaction.
Properties of a Transaction
The main purpose of the transaction is to ensure data integrity in a concurrent environment. The ACID properties help to maintain the integrity of a database in terms of transactions. These properties describe the major guarantees of a database transaction.
Acid properties of transactions
There are four properties of a transaction. These properties are represented by ACID, which means Atomicity, Consistency, Isolation and Durability.
The acronym ACID stands for: Atomicity, consistency, Isolation and Durability.
Atomicity (All or nothing principle) : Either execute all the operations of the transaction or none of them.
Components of Database Responsible for it:
- Recovery Management component.
- It takes care that either the atomicity is applied, else rollback is done if any error arises before the commit.
How does it do it?
- Maintains log files till the commit statement is encountered.
- After a commit statement, the log file is deleted.
Consistency: No violation of integrity constraints
Rule for Consistency: “If the Database was consistent before a particular transaction, then it should also be consistent after the execution of the transaction”.
Whose responsibility is it?
- It is the user's or programmer’s responsibility.
How does he do it?
- By setting various Integrity constraints.
Isolation: (Concurrent Changes invisible)
Rule or Principle of Isolation: “Concurrent execution of two or more transactions should not cause any inconsistency”. It should be as if the transaction executed independently of the other transactions.
Concurrency Control
The task that is to manage the concurrent access to the database in a distributed system is called Distributed Concurrency control.
The challenges with concurrency control in a distributed system are:
- Data may be accessed by multiple users at a number of distant sites. It might cause inconsistent retrieval problems and also update problems.
- The database is fragmented and/or replicated across multiple sites.
- Concurrency control techniques implemented at one location must ensure the consistency of the database at all other sites.
The benefits of concurrency control in distributed transactions are as follows:
- Faster execution and response.
- Improved performance.
- It helps ensure serializability.
- It is reliable/dependable.
This article on Transactions and Concurrency Control in Distributed System is contributed by Hemalatha P. If you like TheCode11 and would like to contribute, you can also write your article and mail to thecode11info@gmail.com