Topic2 Transaction Processing Part 2
Topic2 Transaction Processing Part 2
1
The following 3 problems frequently
plague transactions when there are
concurrency controls:
2
This problem occurs when two transactions
are accessing the same data, and
simultaneously alters that data.
3
Time User 1 User 2 balx
t1 Start transaction 100
t2 Start transaction READ (balx) 100
t3 READ (balx) balx = balx + 100 100
t4 balx= balx – 10 WRITE(balx) 200
t5 WRITE(balx) COMMIT 90
t6 COMMIT 90
4
The WRITE process to balx for User 2 is not
recorded and ‘missing’.
5
The problem can be avoided by preventing
User 1 from reading balx until the update
transaction by User 2 is complete.
6
The problem occurs when there are
transactions that access data that has not
been committed, and the data reverts/rolls-
back to its original value.
7
Time User 1 User 2 balx
t1 Start transaction 100
t2 READ (balx) 100
t3 balx = balx+ 100 100
t4 Start transaction WRITE(balx) 200
t5 READ (balx) … 200
t6 balx=balx– 10 ROLLBACK 100
t7 WRITE(balx) 190
t8 COMMIT 190
8
The value balx = 200 which is retrieved by
User 1’s transaction is incorrect.
9
The problem can be avoided by preventing
User 1 from reading balx until a decision is
made on whether or COMMIT or ROLLBACK
User 2’s transactions.
10
Problems can also occur during the process
of reading data from the database.
11
Example
◦ User 1 wants to transfer 10 from balx
to balz.
12
Time User 1 User 2 balx baly balz Total
t1 Start transaction 100 50 25
t2 Start transaction Total = 0 100 50 25 0
t3 READ (balx) READ (balx) 100 50 25 0
t4 balx=balx– 10 Total =Total + balx 100 50 25 100
t5 WRITE(balx) READ (baly) 90 50 25 100
t6 READ (balz) Total =Total + baly 90 50 25 150
t7 balz=balz+10 90 50 25 150
t8 WRITE(balz) 90 50 35 150
t9 COMMIT READ (balz) 90 50 35 150
t10 Total =Total + balz 90 50 35 185
t11 COMMIT 90 50 35 185
13
The TOTAL value is incorrect because it does
not account for the reduction of 10 in balx in
the transfer to balz.
14
The problem can be avoided if User 2 is
prevented from reading balx and balz until
User 1’s transaction has completed.
15