Properties of Transaction

A transaction consists of the number of operations that are performed on the database. These operations are executed in the form of a single unit that may or may not change the data of the database, so as to ensure consistency and maintain integrity constraints. Once the transaction is submitted it should perform all the operations it consists and finally, when it is completed database should notify the success or failure and the changes it performs.

When multiple users have submitted the transaction at the same time, it will result to an inconsistent state. This state arises because of the transaction’s overlap. Therefore in order to maintain integrity in case of concurrent access and system failure, the transaction should have atomicity, consistency, isolation and durability properties. These are known as ACID properties. The acronym of ACID is atomicity, consistency, isolation and durability. So, the properties of transactions are divided into four parts mentioned below:

  • Atomicity
  • Consistency
  • Isolation
  • Durability

Let us discuss all these properties :

Atomicity

This first ACID property is defined by the phrase “all or nothing”.The atomic property is said to be achieved if the transaction runs to completion or it has made no effects at all if it is incomplete. Simply, the effects of transactions on a database should be either executing all its actions in one step or not executing any actions at all.

Features of Atomicity

  • All the transactions should be completed successfully or none are.
  • In the phase of CPU failure, database software failure and Application software failure atomicity is maintained.
  • During deadlocks, atomicity is maintained.
  • It is the responsibility of the database to maintain atomicity.

Implementing Automaticity

Let’s consider A and B are two accounts having Rs.5000 and Rs.8000 respectively. Also, consider  T1 and T2 are transactions. Now suppose after the execution of the transaction (T1) failure occur that prevent transaction T2  from completely executed.

T1 T2
Read(A)
A=A-750
Write(A)
Read(B)
B=B+750
Write(B)

As the failure occur after the completion of operation write(A) but before the execution of write( B). Consequently, the value in accounts A  and B now are Rs.4250 and 8000. respectively. It is clear that the Rs.750 amount is lost due to the failure. This results in an inconsistent state of the database because the transaction is partially completed. In order to maintain consistency and to ensure atomicity either all the transaction operations should be completed or none of them affects the data during failure situations.

The consistent state is maintained when DBMS restores the original values of A and B.  So database should track the old values of any data on which write operations are performed. In case of transaction failure, it should restore the old values to appear that nothing has happened.

Consistency

The ‘No violation of integrity constraints’ phrase is used to define the consistency property. This property is said to be fulfil if the DBMS before the start of the transaction and after the completion of the transaction is in a consistent state. Maintaining consistency is the responsibility of the programmer who writes the code.

Implementing Consistency

The database is said to be in a consistent state when before and after the completion of transactions sum in both accounts A and B are the same. Keep an eye on the data of below table :

Before the execution of transaction value in Accounts  Before the execution of transactions, Total sum is  After the completion of  transactions value in Accounts  After the completion of  transactions, Total  sum is  
A=Rs.5000, B=Rs.8000 Sum =Rs.13000 A=Rs.4250, B=Rs.8750 Sum =Rs.13000

From the above table, it is crystal clear that before the start of transactions on accounts A and B the sum of the amount is Rs.13000. And after the completion of the transactions, the sum of the total amount is also Rs.13000. So here database is in a consistent state in both the situations.

Isolation

When transactions executes in concurrent phase then there is a need to maintain isolation. The concurrent transaction here refers to the access of the database at the same time by multiple users.

The isolation property will achieve if several transactions results the same as if they will executes concurrently or serially. The data use by one transaction should not use by the other transaction until the first completes its execution successfully.

Implementing Isolation

The problem to satisfy atomicity and consistency come into existence when two transactions executes concurrently. The main reason for these problems is because of the overlapping of concurrently running transactions. Now suppose transactions T1 and T2 are executes currently. Also, consider the transaction T1 transfer the amount of Rs.750 from A to B. The transaction T2  transfers 20% of the amount from Account A to B. The initial values in A and B accounts are Rs.5000 and Rs. 8000.

Now the schedule for transactions T1 and T2 running concurrently as mentioned in schedule 1. It results in a consistent state of DBMS before and after the execution of transactions.

From the above two tables, it is crystal clear that schedule 1 results in a consistent state of the database whereas Schedule leads to an inconsistent state.

Sechdule1 Table (Consistent State)

T1 T2 Description/Status
Read (A)
A: =A-750
Write(A)
  Rs.5000
Rs.4250
Store to A
  Read (A)
temp:=A*0.2
A: =A-temp
Write(A)
Rs.4250
Rs.850
Rs.3400
Store to A
Read (B)
B: =B+750
Write(B)
  Rs.8000
Rs.8750
Store to B
  Read (B)
B: =B+temp
Write(B)
Rs.8750
Rs.9600
Store to B

In schedule 1 ,when transaction T1 complete its operations on one account only then the T2 transaction used the data of that account. In the table, it is clear that initially read operation is perform on account A . This shows the amount in A is Rs.5000. Now Rs.750 deducted from account A. The transaction then updated the value of account A to Rs.4250 by using the write operation.

Now T2 starts with the read(A) operation which indicates that A has Rs.4250. Now a 20% amount of account A is calculated and Rs.850 amount stored in temp variable. Now Rs. 850 amount deducted from account A and then with the help of Write (A) amount update to Rs.3400 in A account.

After that Read(B) operation perform by the T1 transaction. Then Rs.750 amount add to account B and the value is then update as Rs.8750.

Hereafter ,T2 reads the value of account B  which is Rs.8750. Then temp variable value(Rs.850) store to B . The amount is updated as Rs.9600 in account B.

Table of Contents

Sechdule2 Table (Consistent State)

T1 T2 Description/Status
Read (A)
A: =A-750
  Rs.5000
Rs.4250
  Read (A)
temp:=A*0.2
A: =A-temp
Write(A)
Read(B)
Rs.5000
Rs.1000
Rs.4000
Store to A=4000
Rs.8000
Write(A)
Read (B)
B: =B+750
Write(B)
  Store to A=4250
Rs.8000
Rs.8750
Store to B=8750
  B: =B+temp
Write(B)
Rs.9000
Store to B=9000

In schedule1 the sum of amounts of A and B is Rs.13000 whereas schedule 2 results to the sum Rs.13250. Therefore, schedule1 results in a consistent state and schedule2  to an inconsistent state.

Durability

Durability is the capability of the system to recover the committed transaction updates during system or storage failure. Maintaining durability is the onus of DBMS.

Implementing Durability

The durability property requires that once the transaction completes its execution successfully all the updates log should be maintain . Even if the system failure occurs after a transaction completes its execution. The durability can be ensures by either.

  • All the updates made by the transaction have been written over disk before the transaction is completed.
  • Details about the updates carried out by the transaction and mentioned on the disk are sufficient to enable the database to recover the updates when the database is recommenced after the failure.

Durability is handle by the recovery management component which is the component of the database.

T1 T2 Description/Status
Read (A)
A: =A-750
Write(A)
  Rs.5000
Rs.4250
Store to A
  Read (A)
temp:=A*0.2
A: =A-temp
Write(A)
Rs.4250
Rs.850
Rs.3400
Store to A
Read (B)
B: =B+750
Write(B)
  Rs.8000
Rs.8750
Store to B
  Read (B)
B: =B+temp
Write(B)
Rs.8750
Rs.9600
Store to B

In schedule 1 ,when transaction T1 complete its operations on one account only then the T2 transaction used the data of that account. In the table, it is clear that initially read operation is perform on account A . This shows the amount in A is Rs.5000. Now Rs.750 deducted from account A. The transaction then updated the value of account A to Rs.4250 by using the write operation.

Now T2 starts with the read(A) operation which indicates that A has Rs.4250. Now a 20% amount of account A is calculated and Rs.850 amount stored in temp variable. Now Rs. 850 amount deducted from account A and then with the help of Write (A) amount update to Rs.3400 in A account.

After that Read(B) operation perform by the T1 transaction. Then Rs.750 amount add to account B and the value is then update as Rs.8750.

Hereafter ,T2 reads the value of account B  which is Rs.8750. Then temp variable value(Rs.850) store to B . The amount is updated as Rs.9600 in account B.

Sechdule2 Table (Consistent State)

T1 T2 Description/Status
Read (A)
A: =A-750
  Rs.5000
Rs.4250
  Read (A)
temp:=A*0.2
A: =A-temp
Write(A)
Read(B)
Rs.5000
Rs.1000
Rs.4000
Store to A=4000
Rs.8000
Write(A)
Read (B)
B: =B+750
Write(B)
  Store to A=4250
Rs.8000
Rs.8750
Store to B=8750
  B: =B+temp
Write(B)
Rs.9000
Store to B=9000

In schedule1 the sum of amounts of A and B is Rs.13000 whereas schedule 2 results to the sum Rs.13250. Therefore, schedule1 results in a consistent state and schedule2  to an inconsistent state.

Durability

Durability is the capability of the system to recover the committed transaction updates during system or storage failure. Maintaining durability is the onus of DBMS.

Implementing Durability

The durability property requires that once the transaction completes its execution successfully all the updates log should be maintain . Even if the system failure occurs after a transaction completes its execution. The durability can be ensures by either.

Durability is handle by the recovery management component which is the component of the database.

T1 T2 Description/Status
Read (A)
A: =A-750
Write(A)
  Rs.5000
Rs.4250
Store to A
  Read (A)
temp:=A*0.2
A: =A-temp
Write(A)
Rs.4250
Rs.850
Rs.3400
Store to A
Read (B)
B: =B+750
Write(B)
  Rs.8000
Rs.8750
Store to B
  Read (B)
B: =B+temp
Write(B)
Rs.8750
Rs.9600
Store to B

In schedule 1 ,when transaction T1 complete its operations on one account only then the T2 transaction used the data of that account. In the table, it is clear that initially read operation is perform on account A . This shows the amount in A is Rs.5000. Now Rs.750 deducted from account A. The transaction then updated the value of account A to Rs.4250 by using the write operation.

Now T2 starts with the read(A) operation which indicates that A has Rs.4250. Now a 20% amount of account A is calculated and Rs.850 amount stored in temp variable. Now Rs. 850 amount deducted from account A and then with the help of Write (A) amount update to Rs.3400 in A account.

After that Read(B) operation perform by the T1 transaction. Then Rs.750 amount add to account B and the value is then update as Rs.8750.

Hereafter ,T2 reads the value of account B  which is Rs.8750. Then temp variable value(Rs.850) store to B . The amount is updated as Rs.9600 in account B.

Sechdule2 Table (Consistent State)

T1 T2 Description/Status
Read (A)
A: =A-750
  Rs.5000
Rs.4250
  Read (A)
temp:=A*0.2
A: =A-temp
Write(A)
Read(B)
Rs.5000
Rs.1000
Rs.4000
Store to A=4000
Rs.8000
Write(A)
Read (B)
B: =B+750
Write(B)
  Store to A=4250
Rs.8000
Rs.8750
Store to B=8750
  B: =B+temp
Write(B)
Rs.9000
Store to B=9000

In schedule1 the sum of amounts of A and B is Rs.13000 whereas schedule 2 results to the sum Rs.13250. Therefore, schedule1 results in a consistent state and schedule2  to an inconsistent state.

Durability

Durability is the capability of the system to recover the committed transaction updates during system or storage failure. Maintaining durability is the onus of DBMS.

Implementing Durability

The durability property requires that once the transaction completes its execution successfully all the updates log should be maintain . Even if the system failure occurs after a transaction completes its execution. The durability can be ensures by either.

Durability is handle by the recovery management component which is the component of the database.

T1 T2 Description/Status
Read (A)
A: =A-750
Write(A)
  Rs.5000
Rs.4250
Store to A
  Read (A)
temp:=A*0.2
A: =A-temp
Write(A)
Rs.4250
Rs.850
Rs.3400
Store to A
Read (B)
B: =B+750
Write(B)
  Rs.8000
Rs.8750
Store to B
  Read (B)
B: =B+temp
Write(B)
Rs.8750
Rs.9600
Store to B

In schedule 1 ,when transaction T1 complete its operations on one account only then the T2 transaction used the data of that account. In the table, it is clear that initially read operation is perform on account A . This shows the amount in A is Rs.5000. Now Rs.750 deducted from account A. The transaction then updated the value of account A to Rs.4250 by using the write operation.

Now T2 starts with the read(A) operation which indicates that A has Rs.4250. Now a 20% amount of account A is calculated and Rs.850 amount stored in temp variable. Now Rs. 850 amount deducted from account A and then with the help of Write (A) amount update to Rs.3400 in A account.

After that Read(B) operation perform by the T1 transaction. Then Rs.750 amount add to account B and the value is then update as Rs.8750.

Hereafter ,T2 reads the value of account B  which is Rs.8750. Then temp variable value(Rs.850) store to B . The amount is updated as Rs.9600 in account B.

Sechdule2 Table (Consistent State)

T1 T2 Description/Status
Read (A)
A: =A-750
  Rs.5000
Rs.4250
  Read (A)
temp:=A*0.2
A: =A-temp
Write(A)
Read(B)
Rs.5000
Rs.1000
Rs.4000
Store to A=4000
Rs.8000
Write(A)
Read (B)
B: =B+750
Write(B)
  Store to A=4250
Rs.8000
Rs.8750
Store to B=8750
  B: =B+temp
Write(B)
Rs.9000
Store to B=9000

In schedule1 the sum of amounts of A and B is Rs.13000 whereas schedule 2 results to the sum Rs.13250. Therefore, schedule1 results in a consistent state and schedule2  to an inconsistent state.

Durability

Durability is the capability of the system to recover the committed transaction updates during system or storage failure. Maintaining durability is the onus of DBMS.

Implementing Durability

The durability property requires that once the transaction completes its execution successfully all the updates log should be maintain . Even if the system failure occurs after a transaction completes its execution. The durability can be ensures by either.

Durability is handle by the recovery management component which is the component of the database.

Sharing Is Caring: