Reputation: 143
Can you please check whether my answer is acceptable for these questions? Question 1 is about lost-update and Question 2 is about 2PL ( How deadlock occurs? )
QUESTION 1
My Answer for (Q1)
Lost-Update Problem
Reason:
Expected final value for A will be 280 while B will be 240. But due to lost-update problem, these two respective values couldnt be achieved.
As for the transaction T1, the value A is being read at time t1 which is 160 and value B is being read at time t2 which is 60. During time t2, Transaction T2 begins, and value B is being read as well which is known as a dirty-read. Followed by time t4, the value B has been calculated in Transaction 1 and on time t6, value B has been partially committed which is 120 meanwhile, in Transaction T2 time t5, value B has been calculated as well which now holds 120 and is being partially committed as well. Lastly, value B which is 120 has been committed in Transaction 1 on time t7 and later followed by value B which is 120, committed in Transaction 2 on time t11. This is when Lost-Update problem occurs whereby the value B on Transaction 1 is overwritten by value B on Transaction T2.
Versioning Approach --> Still unsure about this will update my answer here after i finish my studies! Apologies for this!
QUESTION 2
My Answer for (Q2) How deadlock occurs in 2PL
Upvotes: 2
Views: 331
Reputation: 143
My explanation
In Transaction T1 there are two locks being requested. During time t2, read-lock is being used on value A because value A is needed to read only and write-lock is being used on value B because value B is needed for modifying or writing data. Meanwhile, Transaction T2 begins and write-lock is being requested and notice that T1 has not yet unlock value B and this is when the write-lock in Transaction T2 Is not granted because value B is still being write-lock in Transaction T1 and this is known as mutual exclusion situation whereby operation in Transaction T2 will be waiting for Transaction T1 operation to finish, then value B will be unlocked and since only Transaction T2 is waiting on Transaction T1 and Transaction T1 isn't waiting for Transaction T2 then there is no deadlock to occur, Transaction T2 will just simply wait until Transaction T1 completes the transaction no matter how long Transaction T1 lasts. And as we can see at time t12 the write-lock on value B is being granted as soon as value A and value B is committed means the exclusive-lock on value B is usable as unlocking has been done on Transaction 1.
Upvotes: 1