使用 Service Broker 时出现死锁问题
我有一个要求,我必须创建多个更新并插入到一组表中。
为此,将调用一个主存储过程,该过程将
根据接收到的一组数据在嵌套事务中调用多个存储过程以进行处理。一个一个地调用主过程很慢,这就是我们使用Service Broker的原因。
在主存储过程中,它将调用几个存储过程,这些过程将记录插入 3 个表并更新其他 3 个表。
所涉及的所有表都已编入索引。我为此使用 Service Broker,但面临死锁情况。每个 SP 调用将始终处理唯一的记录。
死锁图的详细信息
<Column name="TextData" id="1">
<deadlock-list>
<deadlock victim="process387bab0">
<process-list>
<process id="process387bab0" taskpriority="0" logused="50076" waitresource="KEY: 8:72057599133024256 (53975579c7be)"
waittime="3458" ownerId="1880362" transactionname="ACTIVATE_ENTITY" lasttranstarted="2012-04-16T12:56:06.713"
XDES="0x3d5cf590" lockMode="U" schedulerid="1" kpid="7036" status="background" spid="21" sbid="0" ecid="0"
priority="0" trancount="2">
<executionStack> <frame procname="unknown" sqlhandle="0x000000000000000000000000000000000000000000000000"> unknown </frame>
<frame procname="CMS.dbo.IntOnCaseCreationMessageReceive" line="102" stmtstart="6488" stmtend="6594"
sqlhandle="0x0300080076459b5a8f92150131a000000100000000000000"> EXECUTE [dbo].MasterSP @MessageBody, 1 </frame>
</executionStack> <inputbuf> </inputbuf> </process> <process id="process8588388" taskpriority="0" logused="64476"
waitresource="KEY: 8:72057599261540352 (9fea6888fb07)" waittime="1573" ownerId="1879248"
transactionname="ACTIVATE_ENTITY" lasttranstarted="2012-04-16T12:56:02.140" XDES="0xc313860"
lockMode="RangeS-S" schedulerid="1" kpid="7372" status="background" spid="20" sbid="0" ecid="0"
priority="0" trancount="2"> <executionStack> <frame procname="unknown" sqlhandle="0x000000000000000000000000000000000000000000000000"> unknown </frame>
<frame procname="CMS.dbo.IndividualSPToBeCalled" line="102" stmtstart="6488" stmtend="6594"
sqlhandle="0x0300080076459b5a8f92150131a000000100000000000000"> EXECUTE [dbo].IntCreateCases_SB @MessageBody, 1 </frame> </executionStack>
<inputbuf> </inputbuf> </process> </process-list> <resource-list> <keylock hobtid="72057599133024256" dbid="8"
objectname="CMS.dbo.TABLE1" indexname="PK_TABLE1" id="lock1e393540" mode="X" associatedObjectId="72057599133024256"> <owner-list>
<owner id="process8588388" mode="X"/> </owner-list> <waiter-list> <waiter id="process387bab0" mode="U" requestType="wait"/>
</waiter-list> </keylock> <keylock hobtid="72057599261540352" dbid="8" objectname="CMS.dbo.TABLE2" indexname="IX_TABLE2_ON_ID"
id="lock42febd80" mode="X" associatedObjectId="72057599261540352"> <owner-list> <owner id="process387bab0" mode="X"/> </owner-list>
<waiter-list> <waiter id="process8588388" mode="RangeS-S" requestType="wait"/> </waiter-list> </keylock> </resource-list> </deadlock>
</deadlock-list> </Column>