Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Problems explaining deadlock chain Expand / Collapse
Author
Message
Posted Tuesday, August 13, 2013 8:37 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Yesterday @ 6:43 AM
Points: 61, Visits: 699
Hi,

We are currently in a spot of bother, attempting to explain a deadlock chain and would really really appreciate any guidance/help in explaining what exactly happening and possible ways to mitigate please.

Here's a brief overview of the scenario.

There is one SP 'sp_Select_ActionsForProcessing' that is invoked at the same time by multiple threads. The SP selects a range of qualified records and selects the top 1 qualifying record. When the second thread runs, it will select the qualifying range excluding the one selected by the first one and so forth. We implemented the same with UPDATELOCK HOLDLOCK table hint, However, we do suspect the same to be the cause of contention, but could not pinpoint.

Will appreciate any help please.

Attached is the .xdl file, .xml and proc text.


  Post Attachments 
Deadlock Chain.zip (6 views, 6.19 KB)
Post #1483772
Posted Tuesday, August 13, 2013 4:07 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, December 12, 2014 1:02 AM
Points: 823, Visits: 753
I think you shold take out the HOLDLOCK. HOLDLOCK is the same as SERIALIZABLE, that is protection against "phantom reads", that is rows that were inserted since you read the range. Since your procedure is not inserting any rows, I don't see you need it.

The serializable isolation level is quite prone to deadlocks, so avoid it if possible.


Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1484021
Posted Tuesday, August 13, 2013 11:17 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Yesterday @ 6:43 AM
Points: 61, Visits: 699
Thanks a lot for your insight. We also believed in the same way, specifically, the victim's request on the resource was for an update lock.

We were and still are a bit baffled with interpreting the deadlock chain. If you did manage to have a look at the .xdl file, in one chain, it is shown, one process has been granted exclusive lock, however, in the chain involving deadlock, another process has been granted Update lock on the same keyid.

Thanks and regards.
Post #1484068
Posted Wednesday, August 14, 2013 1:15 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, December 12, 2014 1:02 AM
Points: 823, Visits: 753
I will have to admit that I did not look at the deadlock chain. My experience of serializable was enough.



Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1484096
Posted Friday, August 16, 2013 7:03 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Yesterday @ 6:43 AM
Points: 61, Visits: 699
Apology for being late in getting back. You were quite correct. Getting rid of the HOLDLOCK solve the issue, however, teh DEADLOCK took other SPs as preferred partner. :)

I did suggest to try with READ_COMMITTED_SNAPSHOT isolation level as the default isolation behavior, but the technical architects are a bit jittery as it will make the tempdb to take the toll. We have implemented the TRY..CATCH method for troubleshooting. Please advise if this is a correct approach.


Regards.
Post #1485178
Posted Friday, August 16, 2013 8:03 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, December 12, 2014 1:02 AM
Points: 823, Visits: 753
READ_COMMITTED_SNAPSHOT is an excellent idea, but it will not apply in this case, as UPDLOCK implies REPEATABLE READ.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1485225
Posted Monday, August 19, 2013 2:27 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 5:46 AM
Points: 316, Visits: 910
In these cases with complicated code that takes different kinds of locks and you have problems with deadlocks it might be a good idea to explicitly take an application lock at the beginning of each stored procedure that manipulates these tables.

Like this:

BEGIN TRAN
exec sp_getapplock 'MyRersourceName', 'Exclusive'

-- Application code
..
COMMIT

Of course this might lower the concurrency so it could lower the performance but at least you will not have to worry about deadlocks.

The lock taken by sp_getapplock when called in this way is always held until the end of the transaction.
Post #1485683
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse