0

我有 2 个进程之间的死锁,processd38f8748(第一个)和process5b2988(第二个)。

第一个进程是SELECT在单独的连接中运行的。没有在代码中为其打开显式事务。SELECT在同一连接中之前或之后没有可能运行过的 sql 请求。此选择需要获取第 356615 页上的共享锁。

第二个进程是一个UPDATE,它已经在页面 356615 上持有 IX 锁(很难确定系统中的确切位置,但我可以相信),同时它想要另一个页面 356614。这里一切正常。

现在,奇怪的是第二个进程无法获得第 356614 页上的锁,因为它已经被第一个进程持有。

这对我来说很奇怪,原因有两个:

  • 我很确定这个选择是 sql-connection 中的唯一请求
  • IL 被重新提交。我认为对于这个 IL,一旦语句完成,所有 S 锁都会被释放。

这是死锁xml。

<deadlock-list>
 <deadlock victim="processd38f8748">
  <process-list>
   <process id="processd38f8748" taskpriority="0" logused="0" waitresource="PAGE: 7:1:356615" waittime="2369" ownerId="24096354927" transactionname="SELECT" lasttranstarted="2013-03-06T11:26:10.810" XDES="0x368701960" lockMode="S" schedulerid="4" kpid="5756" status="suspended" spid="60" sbid="0" ecid="11" priority="0" trancount="0" lastbatchstarted="2013-03-06T11:26:10.810" lastbatchcompleted="2013-03-06T11:26:10.810" clientapp=".Net SqlClient Data Provider" hostname="CWCEINAW" hostpid="2604" isolationlevel="read committed (2)" xactid="24096354927" currentdb="7" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
    <executionStack>
     <frame procname="adhoc" line="1" sqlhandle="0x02000000dffc7a241f9433fddb83b7f97a7c0369dbf6d467">
SELECT TOP 1 1
                FROM [WP_CashCenter_StockTransaction] AS [ST]
                    LEFT JOIN [WP_CashCenter_StockTransactionLine] AS [STL] ON ( [STL].[StockTransaction_id] = [ST].[id] )
                WHERE
                    [ST].[Status] IN (0, 1) AND
                    [ST].[Type] = 0 AND
                    ([ST].[StockContainerID] = 300000120244 OR [STL].[StockContainer_id] = 300000120244)     </frame>
    </executionStack>
    <inputbuf>
    </inputbuf>
   </process>
   <process id="process5b2988" taskpriority="0" logused="17268" waitresource="PAGE: 7:1:356614" waittime="2264" ownerId="24096354521" transactionname="user_transaction" lasttranstarted="2013-03-06T11:26:10.690" XDES="0x80021040" lockMode="IX" schedulerid="2" kpid="5832" status="suspended" spid="55" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2013-03-06T11:26:10.920" lastbatchcompleted="2013-03-06T11:26:10.920" lastattention="2013-02-28T11:26:25.940" clientapp=".Net SqlClient Data Provider" hostname="CWCEINAW" hostpid="2604" loginname="cwcuser" isolationlevel="read committed (2)" xactid="24096354521" currentdb="7" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
    <executionStack>
     <frame procname="adhoc" line="1" stmtstart="702" sqlhandle="0x02000000f0a38d32edae20f54b42cd640b8022448db200b7">
UPDATE [WP_CashCenter_StockTransaction] SET [type] = @type, [status] = @status, [startdate] = @startdate, [enddate] = @enddate, [totalquantity] = @totalquantity, [totalvalue] = @totalvalue, [totalweight] = @totalweight, [datecreated] = @datecreated, [dateupdated] = @dateupdated, [stockorder_id] = @stockorder_id, [site_id] = @site_id, [stockowner_id] = @stockowner_id, [stocklocation_id] = @stocklocation_id, [stockcontainerid] = @stockcontainerid, [uid] = @uid, [machinenumber] = @machinenumber, [editor_id] = @editor_id WHERE [id] = @id     </frame>
     <frame procname="unknown" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
unknown     </frame>
    </executionStack>
    <inputbuf>
(@type int,@status int,@startdate datetime,@enddate datetime,@totalquantity int,@totalvalue decimal(6,2),@totalweight decimal(5,5),@datecreated datetime,@dateupdated datetime,@stockorder_id bigint,@site_id int,@stockowner_id int,@stocklocation_id int,@stockcontainerid bigint,@uid uniqueidentifier,@machinenumber nvarchar(1),@editor_id int,@id bigint)UPDATE [WP_CashCenter_StockTransaction] SET [type] = @type, [status] = @status, [startdate] = @startdate, [enddate] = @enddate, [totalquantity] = @totalquantity, [totalvalue] = @totalvalue, [totalweight] = @totalweight, [datecreated] = @datecreated, [dateupdated] = @dateupdated, [stockorder_id] = @stockorder_id, [site_id] = @site_id, [stockowner_id] = @stockowner_id, [stocklocation_id] = @stocklocation_id, [stockcontainerid] = @stockcontainerid, [uid] = @uid, [machinenumber] = @machinenumber, [editor_id] = @editor_id WHERE [id] = @id    </inputbuf>
   </process>
  </process-list>
  <resource-list>
   <pagelock fileid="1" pageid="356615" dbid="7" objectname="Eindhoven_CWC.dbo.WP_CashCenter_StockTransaction" id="lock10f24cb00" mode="IX" associatedObjectId="72057594093830144">
    <owner-list>
     <owner id="process5b2988" mode="IX"/>
    </owner-list>
    <waiter-list>
     <waiter id="processd38f8748" mode="S" requestType="wait"/>
    </waiter-list>
   </pagelock>
   <pagelock fileid="1" pageid="356614" dbid="7" objectname="Eindhoven_CWC.dbo.WP_CashCenter_StockTransaction" id="lock17e539e00" mode="SIU" associatedObjectId="72057594093830144">
    <owner-list>
     <owner id="processd38f8748" mode="S"/>
    </owner-list>
    <waiter-list>
     <waiter id="process5b2988" mode="IX" requestType="convert"/>
    </waiter-list>
   </pagelock>
  </resource-list>
 </deadlock>
</deadlock-list>
4

1 回答 1

1

看起来读者和作者之间的访问顺序不同。我希望更新只搜索一次,[Id] = @id但它有一个页面并且想要另一个页面这一事实表明了一次扫描。你有索引[Id]吗?

于 2013-03-25T10:01:42.870 回答