使用级联约束的可重现死锁

时间:2009-12-14 20:33:26

标签: sql sql-server foreign-keys constraints deadlock

我正在寻找代码来生成使用级联约束产生的可重现的死锁。我可以在网上找到针对特定问题的参考资料,我已经回答了几十个关于使用级联约束的死锁的问题,但是没有一个问题具有可重现的死锁版本。

我不是在寻找有关如何解决死锁,捕获或读取死锁图的信息,或者我应该使用跟踪标记来获取死锁图。我得到了所有这些,我想看到导致这种特定类型的死锁的锁定的细节。如果你能提供允许我写这个死锁复制品的细节,那就足够了。

我有许多脚本可以重现涉及书签查找的其他类型的死锁,使用显式事务在存储过程中进行不一致的表访问,以及在可序列化隔离下进行存在检查。我只是无法弄清楚级联约束死锁的再现。

1 个答案:

答案 0 :(得分:0)

我意识到这篇文章相当陈旧,但我有这样的情况。请查看下面的死锁信息以及相关表格的链接:http://pastebin.com/cxqtGMghhttp://pastebin.com/5E8kw6Kw

您将需要关闭我未包含的所有表的外键引用,并可能创建一些测试数据。页面引用PAGE: 16:8:5031979将根据以下代码解析为profmaster表。请注意我已使用Metadata ObjectId代替输出中的m_objId,因为后者无法解析。

DBCC TRACEON(3604)
DBCC PAGE(16,8,5031979,1)
DBCC TRACEOFF(3604)

select name from sys.tables where object_id = 1889441805

这是页面分辨率报告的输出:http://pastebin.com/HfrVp2nP - 请注意我正在运行SQL Server 2008 R2(SP1)X64

如果有关如何解决问题的任何指导,我将不胜感激。

- e

<deadlock-list>
 <deadlock victim="process53f9f2bc8">
  <process-list>
   <process id="process53f9f2bc8" taskpriority="0" logused="4712" waitresource="KEY: 16:72057678434598912 (a60c363e20e5)" waittime="571706" ownerId="93354998" transactionname="user_transaction" lasttranstarted="2013-11-19T15:39:31.203" XDES="0x80011730" lockMode="U" schedulerid="2" kpid="2064" status="suspended" spid="61" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2013-11-19T15:39:31.263" lastbatchcompleted="2013-11-19T15:39:31.260" clientapp="3E WebUI" hostname="LA-BAT-26-WAPI" hostpid="2728" loginname="sa" isolationlevel="read committed (2)" xactid="93354998" currentdb="16" lockTimeout="4294967295" clientoption1="671096864" clientoption2="128056">
    <executionStack>
     <frame procname="adhoc" line="1" stmtstart="140" sqlhandle="0x02000000d1e0f407f28e46e45feec1ce34fc8f3e09dcb3c5">
update n0t0 set ProfMaster = @0 , MatrixTaxCode = null , PrevProfMaster = @1 , LastProcItemID = @2 , TimeStamp = GETDATE ( ) from Timecard as n0t0 where ( ( ( ( n0t0 . WorkDate ) &lt; = ( @3 ) ) and ( ( ( n0t0 . IsActive ) = ( @4 ) ) and ( ( n0t0 . IsNB ) = ( @5 ) ) ) ) and ( ( ( ( ( n0t0 . ProfMaster ) is null ) and ( ( n0t0 . InvMaster ) is null ) ) and ( ( n0t0 . WIPRemoveDate ) is null ) ) and ( ( n0t0 . CurrProcItemID ) is null ) ) ) and ( ( n0t0 . Matter ) in ( select n1t1 . Matter from ProfMatter as n1t1 where ( n1t1 . ProfMaster ) = ( @6 ) ) )     </frame>
     <frame procname="adhoc" line="1" sqlhandle="0x0200000095131921232b4d814cc188595c176663442618b6">
UPDATE n0t0 SET ProfMaster = 252516,MatrixTaxCode = NULL,PrevProfMaster = 252516,LastProcItemID = &apos;939f3291-10a7-4704-885e-9021b2a39f15&apos;,TimeStamp = GETDATE() FROM Timecard AS n0t0 WHERE ( ( ( ( n0t0.WorkDate ) &lt;= ( &apos;11/04/2013 00:00:00&apos;) ) AND ( ( ( n0t0.IsActive ) = ( 1 ) ) AND ( ( n0t0.IsNB ) = ( 0 ) ) ) ) AND ( ( ( ( ( n0t0.ProfMaster ) IS NULL ) AND ( ( n0t0.InvMaster ) IS NULL ) ) AND ( ( n0t0.WIPRemoveDate ) IS NULL ) ) AND ( ( n0t0.CurrProcItemID ) IS NULL ) ) ) AND ( ( n0t0.Matter ) IN ( SELECT n1t1.Matter FROM ProfMatter AS n1t1 WHERE ( n1t1.ProfMaster ) = ( 252516 ) ) )/**0x2C621659**/     </frame>
    </executionStack>
    <inputbuf>
UPDATE n0t0 SET ProfMaster = 252516,MatrixTaxCode = NULL,PrevProfMaster = 252516,LastProcItemID = &apos;939f3291-10a7-4704-885e-9021b2a39f15&apos;,TimeStamp = GETDATE() FROM Timecard AS n0t0 WHERE ( ( ( ( n0t0.WorkDate ) &lt;= ( &apos;11/04/2013 00:00:00&apos;) ) AND ( ( ( n0t0.IsActive ) = ( 1 ) ) AND ( ( n0t0.IsNB ) = ( 0 ) ) ) ) AND ( ( ( ( ( n0t0.ProfMaster ) IS NULL ) AND ( ( n0t0.InvMaster ) IS NULL ) ) AND ( ( n0t0.WIPRemoveDate ) IS NULL ) ) AND ( ( n0t0.CurrProcItemID ) IS NULL ) ) ) AND ( ( n0t0.Matter ) IN ( SELECT n1t1.Matter FROM ProfMatter AS n1t1 WHERE ( n1t1.ProfMaster ) = ( 252516 ) ) )/**0x2C621659**/    </inputbuf>
   </process>
   <process id="process50b54c8" taskpriority="0" logused="43622588" waitresource="PAGE: 16:8:5031979" waittime="1575" ownerId="87921480" transactionname="user_transaction" lasttranstarted="2013-11-19T14:26:29.400" XDES="0x569d39950" lockMode="U" schedulerid="9" kpid="1304" status="suspended" spid="60" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2013-11-19T15:49:01.277" lastbatchcompleted="2013-11-19T15:49:01.277" clientapp="3E WebUI" hostname="LA-BAT-27-WAPI" hostpid="2628" loginname="sa" isolationlevel="read committed (2)" xactid="87921480" currentdb="16" lockTimeout="4294967295" clientoption1="671096864" clientoption2="128056">
    <executionStack>
     <frame procname="adhoc" line="1" stmtstart="86" sqlhandle="0x020000006014e71626ea61a3e74df841cee6a59043438dc8">
update n0t0 set ProfStatus = @0 , LastProcItemID = @1 , TimeStamp = GETDATE ( ) from ProfMaster as n0t0 join #TempMatterProforma as z0 on ( ( n0t0 . ProfIndex ) = ( z0 . ProfIndex ) ) and ( ( z0 . IsNewProforma ) = ( @2 ) )     </frame>
     <frame procname="adhoc" line="1" sqlhandle="0x020000004d41a316b62a8171bbf8979051631fdc480c754b">
UPDATE n0t0 SET ProfStatus = N&apos;P&apos; ,LastProcItemID = &apos;d7eff077-6f52-435f-906a-6fc8f2ee929a&apos;,TimeStamp = GETDATE() FROM ProfMaster AS n0t0 JOIN #TempMatterProforma AS z0 ON ( ( n0t0.ProfIndex ) = ( z0.ProfIndex ) ) AND ( ( z0.IsNewProforma ) = ( 0 ) )/**0xA8DF8735**/     </frame>
    </executionStack>
    <inputbuf>
UPDATE n0t0 SET ProfStatus = N&apos;P&apos; ,LastProcItemID = &apos;d7eff077-6f52-435f-906a-6fc8f2ee929a&apos;,TimeStamp = GETDATE() FROM ProfMaster AS n0t0 JOIN #TempMatterProforma AS z0 ON ( ( n0t0.ProfIndex ) = ( z0.ProfIndex ) ) AND ( ( z0.IsNewProforma ) = ( 0 ) )/**0xA8DF8735**/    </inputbuf>
   </process>
  </process-list>
  <resource-list>
   <keylock hobtid="72057678434598912" dbid="16" objectname="TE_3E_BAT27B.dbo.Timecard" indexname="IDX__TimeIndex__2F97CBE5" id="lock1ffcaf600" mode="X" associatedObjectId="72057678434598912">
    <owner-list>
     <owner id="process50b54c8" mode="X"/>
    </owner-list>
    <waiter-list>
     <waiter id="process53f9f2bc8" mode="U" requestType="wait"/>
    </waiter-list>
   </keylock>
   <pagelock fileid="8" pageid="5031979" dbid="16" objectname="TE_3E_BAT27B.dbo.ProfMaster" id="lock3bf068600" mode="IX" associatedObjectId="72057678315388928">
    <owner-list>
     <owner id="process53f9f2bc8" mode="IX"/>
    </owner-list>
    <waiter-list>
     <waiter id="process50b54c8" mode="U" requestType="wait"/>
    </waiter-list>
   </pagelock>
  </resource-list>
 </deadlock>
</deadlock-list>