Monday, 18 April 2016

Concurrency Anomalies - Uncommitted Read Problem



Need for concurrency control, Concurrency Anomalies, Concurrent Execution Problems

Reading Uncommitted Data / Temporary Update / Dirty Read Problem


This problem is caused when one transaction is permitted to read a data item that is modified by an uncommitted transaction. It will cause us trouble if the uncommitted transaction decided to rollback.

For example, if a transaction T1 has modified a data item Q and if a transaction T2 is allowed to read the value of Q as modified by T1 before T1 commits, then it causes dirty read problem. Here, the read operation performed by T2 is called dirty read.

Example:

To explain this concept, let us use the schedule s1 given below;
Here, transaction T1 transfers 50 from account A to B, and transaction T2 calculates the 10 % interest on the balance of A and credits A with the interest.
Transaction T1
Transaction T2
A = 1000, B = 1000
read(A);
A := A – 50;
write(A);





read(B);
B := B + 50;
write(B);
commit;



read(A);
temp := A * 0.1;
A := A + temp;
write(A);
commit;
T1 read: A = 1000

T1 write: A = 950
T2 read: A = 950 (read uncommitted data)


T2 write: A = 1045

T1 decided to rollback.
Table: Schedule S1
Let us suppose the initial value of A and B are 1000;

  • The transaction T1, at first, read the value of A (ie., 1000).

  • Then T1 is writing account A with 950 after calculation.

  • Now transaction T2 reads the value of A that is written by T1 and consecutively calculated the interest value. Also, T2 has committed by writing 1045 into A.

  • In the mean time T1 is decided to roll back for some reason.

At this point, if T1 is rolled back, that makes the value 950 to be rolled back to 1000. But the interleaved transaction T2 has used that uncommitted value (950) which does not exist now. This read by T2 is called dirty read. And, this lead the database to an inconsistent state.

Discussion:

  • The process of allowing another transaction to view the intermediate results (not yet committed) of a transaction before it commits causes this problem. This is violating the Isolation property of transactions.

  • It is caused due to Write-Read conflict between transactions.



***********************

Go to Transaction Management in DBMS home page

Go to Need for Concurrency Control in DBMS page





No comments:

Post a Comment

SQL exercises for beginners one

SQL Exercises for Beginners / Simple SQL Exercises with Answers / Solved SQL exercises / SQL solved exercises with simple conditions / So...