У меня слишком много проблем с тупиком в моей среде.В основном тупик случается при попытке обновления.Я установил SentryOne, чтобы знать, что происходит с взаимоблокировкой. У нас очень сложная система, и мы получаем множество взаимоблокировок на одном столе.
Мой уровень транзакции повторяемый. Чтение, и я получаю циклические блокировки в одной таблице.Какие шаги я могу предпринять, чтобы избежать циклических тупиков.Как сделать так, чтобы в коде не возникало циклического тупика.
Ниже показана блокировка ключа для Reservations indexname = "IX_Reservations_ReservationId_OrganizationId. У меня 18k записей в наборе результатов, и индексация, кажется, была применена. Нопоказ сканирования индекса по индексу ReservationOrgananization. Как вы думаете, оператор запроса является причиной сканирования индекса. Я делаю много операций выбора с условием регистра внутри транзакции, в которой используется вставка, удаление обновления
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[RowVersion] AS [RowVersion],
[Extent1].[AdjustmentAmount] AS [AdjustmentAmount],
[Extent1].[Comment] AS [Comment],
[Extent1].[ReservationAdjustment_Reservation] AS [ReservationAdjustment_Reservation],
[Extent1].[ReservationAdjustment_Promotion] AS [ReservationAdjustment_Promotion],
[Extent1].[ReservationAdjustment_AdjustmentReason] AS [ReservationAdjustment_AdjustmentReason],
[Extent1].[CreatedBy] AS [CreatedBy],
[Extent1].[CreatedOn] AS [CreatedOn],
[Extent1].[ReservationProductId] AS [ReservationProductId]
FROM [dbo].[ReservationAdjustments] AS [Extent1]
INNER JOIN [dbo].[Reservations] AS [Extent2] ON [Extent1].[ReservationAdjustment_Reservation] = [Extent2].[Id]
WHERE 123 = (CASE WHEN ([Extent2].[OrganizationId] = @p__linq__0) THEN [Extent2].[Id] END)
<deadlock>
<victim-list>
<victimProcess id="process23b4b08c8" />
</victim-list>
<process-list>
<process id="process23b4b08c8" taskpriority="0" logused="0" waitresource="OBJECT: 6:30675207:0 " waittime="3311" ownerId="55794405" transactionname="user_transaction" lasttranstarted="2019-02-20T16:41:15.963" XDES="0x2a4125770" lockMode="IX" schedulerid="1" kpid="102820" status="suspended" spid="94" sbid="2" ecid="0" priority="0" trancount="2" lastbatchstarted="2019-02-20T16:41:16.403" lastbatchcompleted="2019-02-20T16:41:16.390" lastattention="1900-01-01T00:00:00.390" clientapp=".Net SqlClient Data Provider" hostname="''"" ''" loginname="''"" isolationlevel="repeatable read (3)" xactid="55794405" currentdb="6" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="234" stmtend="670" sqlhandle="0x0200000066d3ee34a3aa9027d9cf2157cf5cca17470f03dd0000000000000000000000000000000000000000">
unknown </frame>
<frame procname="unknown" line="1" sqlhandle="0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000">
unknown </frame>
</executionStack>
<inputbuf>
(@0 decimal(18,2),@1 decimal(18,2),@2 decimal(18,2),@3 bit,@4 nvarchar(255),@5 datetimeoffset(7),@6 int,@7 binary(8))update [dbo].[P]
set [TotalPrice] = @0, [PassengerTaxAndFees] = @1, [AgentCommission] = @2, [SupplierChangeExists] = @3, [ModifiedBy] = @4, [Modified] = @5
where (([Id] = @6) and ([RowVersion] = @7))
select [RowVersion]
from [dbo].[P]
where @@ROWCOUNT > 0 and [Id] = @6 </inputbuf>
</process>
<process id="process294aedc28" taskpriority="0" logused="12548" waitresource="OBJECT: 6:30675207:0 " waittime="6588" ownerId="55792892" transactionname="user_transaction" lasttranstarted="2019-02-20T16:41:12.020" XDES="0x2c5e09770" lockMode="IX" schedulerid="2" kpid="49456" status="suspended" spid="80" sbid="2" ecid="0" priority="0" trancount="2" lastbatchstarted="2019-02-20T16:41:13.127" lastbatchcompleted="2019-02-20T16:41:13.123" lastattention="1900-01-01T00:00:00.123" clientapp=".Net SqlClient Data Provider" hostname="''"" ''" loginname="''"" isolationlevel="repeatable read (3)" xactid="55792892" currentdb="6" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="1062" stmtend="5572" sqlhandle="0x02000000328db70a915f43baef23378214e51d7e0cacc8c50000000000000000000000000000000000000000">
unknown </frame>
<frame procname="unknown" line="1" sqlhandle="0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000">
unknown </frame>
</executionStack>
<inputbuf>
(@0 datetime2(7),@1 datetime2(7),@2 int,@3 decimal(18,2),@4 bit,@5 decimal(18,2),@6 bit,@7 bit,@8 nvarchar(255),@9 int,@10 decimal(18,2),@11 nvarchar(255),@12 nvarchar(25),@13 nvarchar(max) ,@14 nvarchar(255),@15 decimal(18,2),@16 nvarchar(25),@17 datetime2(7),@18 nvarchar(max) ,@19 decimal(18,2),@20 bit,@21 int,@22 int,@23 bit,@24 bit,@25 bit,@26 bit,@27 bit,@28 bit,@29 nvarchar(25),@30 bit,@31 bit,@32 nvarchar(255),@33 datetimeoffset(7),@34 nvarchar(255),@35 datetimeoffset(7),@36 int,@37 int,@38 int,@39 int,@40 int,@41 int)insert [dbo].[P]([EndDate], [StartDate], [Quantity], [PriceEach], [TotalPrice], [Comments], [NetRate], [NetRateAmountDue], [NetAmountPaid], [NetAmountPaidDate], [NetRatePaidInFull], [CommissionPaidInFull], [Owner], [Organization], [Source], [SourceConfirmationNumber], [PassengerTaxAndFees], [PassengerTaxesAndFeesDescription], [Destination], [ProductType], [Description], [RateDe </inputbuf>
</process>
</process-list>
<resource-list>
<objectlock lockPartition="0" objid="30675207" subresource="FULL" dbid="6" objectname="''.dbo.P" id="lock2ab07a480" mode="S" associatedObjectId="30675207">
<owner-list>
<owner id="process294aedc28" mode="S" />
<owner id="process294aedc28" mode="IX" requestType="convert" />
</owner-list>
<waiter-list>
<waiter id="process23b4b08c8" mode="IX" requestType="convert" />
</waiter-list>
</objectlock>
<objectlock lockPartition="0" objid="30675207" subresource="FULL" dbid="6" objectname=".dbo.''"" id="lock2ab07a480" mode="S" associatedObjectId="30675207">
<owner-list>
<owner id="process23b4b08c8" mode="S" />
<owner id="process23b4b08c8" mode="IX" requestType="convert" />
</owner-list>
<waiter-list>
<waiter id="process294aedc28" mode="IX" requestType="convert" />
</waiter-list>
</objectlock>
</resource-list>
</deadlock>