The-Droidster
The-Droidster

Reputation: 655

Commits in concurrent transactions

Concurrent transaction execution.

 T1         T2 
================= 
           R(A)

R(A)       
A=A+100      
W(A)       
           A=A+200
           W(A)
           commit

commit

Here Initially A=100. what will be the value of A after the final commit? Note: The above schedule of transactions executes concurrently (Inter-leaved) as shown.

Upvotes: 0

Views: 273

Answers (1)

matt helliwell
matt helliwell

Reputation: 2678

There are two possibilities depending on the locking strategy:

  1. With optimistic locking, T2 will commit a value of 300 to the DB and T1 will get an optimistic locking exception

  2. With row or table level locking and assuming T2 gets the lock first then A=400. This is because T2 gets a lock first and T1 will then block until T2 has finished. T2 therefore commits A=300. T1 then reads this value and commits A=400. Obviously in this case, the operations aren't interleaved as shown.

There is a 3rd possibility where T1 could get the lock first. In this case, T1 can't commit after T2 so it isn't really possible based on your diagram.

Upvotes: 1

Related Questions