문제

I have to implement an sql transaction as my assignment and show that i've chosen correct isolation level. The problem is im not sure what should happen when two transactions collide when isolation level is optimal. What i mean is that i dont know whether one of them should get cancelled due to the deadlock or complete successfully but have no effect (get rollbacked?). Im using MS SQL Server if it matters.

도움이 되었습니까?

해결책

When transactions are in a deadlock situation, SQL Server chooses one as the victim of the deadlock. That means that the victim transaction will be canceled and rollback whereas the other will keep on going as if nothing happened. SQL Server chooses the victim based on the difficulty (CPU cost) of rolling-back the victim's changes. The victim transaction will then error out with the error code 1205, which is quite explicit.

You can set the transactions' deadlock priorities yourself, as explained in the second link.

More details here : http://technet.microsoft.com/en-us/library/ms178104(v=sql.105).aspx

And here : http://technet.microsoft.com/en-us/library/ms186736.aspx

Btw, the fact that you use SQL Server matters a lot ! Some other DBMS would just keep the transactions in a lock forever, and others would just choose to error both transactions out. I never heard of one that would consider the transactions complete and roll them back, though...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top