HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Explain SQL Server deadlock graph modes

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
graphsqldeadlockserverexplainmodes

Problem

I got such a deadlock:

I see that /process/@lockMode is equal to /owner/@mode.
But why /keylock/@mode is not equal to /owner/@mode?
What does /keylock/@mode mean?

As I understand from the entire deadlock, processVictim should neither use U lock nor X lock.

Here is the entire deadlock:


 

  
   
    
     
if exists(select 1 from DbRepl.dbo.vRule where RuleId = @nRuleId_ and CloseDate is not null)     
     
EXEC notify.pRuleActivated
    @xmlMsg = @xmlMsg     
     
exec @proc_ @xmlMsg = @msg_, @uuidConversationGroup = @cgid_, @uuidConversationHandle = @dh_, @nServiceId = @service_id_;     
    
    
    
   

   
    
     
update [dbo].[tRule] set
        [Id] = case substring(@bitmap,1,1) & 2 when 2 then @c2 else [Id] end,
        [TypeId] = case substring(@bitmap,1,1) & 4 when 4 then @c3 else [TypeId] end,
        [EventId] = case substring(@bitmap,1,1) & 8 when 8 then @c4 else [EventId] end
where [RuleId] = @pkc1     
    
    
Proc [Database Id = 10 Object Id = 1907939431]    
   
  

  
   
    
     
    
    
     
    
   

   
    
     
    
    
     
    
   
  

 


And it's visualization:

Solution

Both sessions have locks on the second key. The reader has an S and the writer has a U and wants to convert to X. Consider changing the database to use READ_COMMITTED_SNAPSHOT mode, or add an XLOCK hint to the UPDATE so it doesn't read with U locks and then convert to X.


What are these modes.

I think that is the most restrictive lock locks currently held on the resource, as opposed to the locks requested. This is often the lock that is incompatible with the blocked session's request, but not always.


Why is this mode not S.

Because the most restrictive lock currently held on the resource is the U lock held by the writer session, and which it has requested to "convert" from U to X.

Context

StackExchange Database Administrators Q#205245, answer score: 5

Revisions (0)

No revisions yet.