У моего друга возникла проблема с приложением Java (Spring + Hibernate), которое случайным образом прерывается из-за исключения:
Транзакция (ID процесса 57) была заблокирована для ресурсов блокировки с другим процесс и был выбран в качестве жертвы тупика
Я считаю, что это из-за злоупотребления аннотацией @Transactional
. Фактически, каждый отдельный запрос в его приложении представляет собой явную транзакцию с уровнем изоляции «прочитано зафиксировано». Я попросил его предоставить мне график взаимоблокировок (см. Ниже), однако я не могу его понять.
Если я прав: процесс process1bc993e8108 (выбрать) удерживает общую блокировку таблицы TABLEA. Процесс process1bc9a25bc28 (вставка) ожидает установки намеренной монопольной блокировки на таблицу TABLEA. Но в то же время этот же процесс удерживает уже намеренную монопольную блокировку таблицы TABLEA ??? и процесс1bc9a10bc28 (выберите) был выбран жертвой, потому что он ожидает установки общей блокировки на TABLEA ??? Я потерян здесь ... для меня это простая блокировка, и я не могу найти здесь какую-либо блокировку по циклу (она же тупик)
Итак, вот мои вопросы:
- Я верно, что это связано с явными транзакциями и переход к неявным транзакциям для отдельных запросов решит проблему?
- Может ли активация опции «снимок» для «чтения зафиксировано» быть потенциальным решением? или они должны уменьшить уровень изоляции транзакции по умолчанию и сохранить «чтение зафиксировано» только для транзакций с несколькими командами?
- Как воспроизвести график взаимоблокировок в редакторе SQL? Должен ли я запустить
select + insert + select
в одно и то же время, чтобы воспроизвести его?
Я был бы очень признателен за любую помощь.
<deadlock>
<victim-list>
<victimProcess id="process1bc9a10bc28" />
</victim-list>
<process-list>
<process id="process1bc9a10bc28" taskpriority="0" logused="0" waitresource="PAGE: 6:1:2283030 " waittime="1948" ownerId="125034381" transactionname="implicit_transaction" lasttranstarted="2020-02-26T15:09:44.357" XDES="0x1be848c6040" lockMode="S" schedulerid="5" kpid="7160" status="suspended" spid="72" sbid="0" ecid="7" priority="0" trancount="0" lastbatchstarted="2020-02-26T15:09:44.367" lastbatchcompleted="2020-02-26T15:09:44.363" lastattention="1900-01-01T00:00:00.363" clientapp="jTDS" hostname="LP097MID8513" hostpid="123" isolationlevel="read committed (2)" xactid="125034381" currentdb="6" currentdbname="server1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="18" stmtend="164" sqlhandle="0x02000000baccf036bb7c864a41cd9425eebee165c997e0b00000000000000000000000000000000000000000">unknown </frame>
</executionStack>
<inputbuf>(@P0 int)select sum(AMOUNT) from TABLEA where IND_REJECT='Y' and ID_BILL= @P0 </inputbuf>
</process>
<process id="process1bc994bf848" taskpriority="0" logused="10000" waittime="1496" schedulerid="1" kpid="7436" status="suspended" spid="72" sbid="0" ecid="4" priority="0" trancount="0" lastbatchstarted="2020-02-26T15:09:44.367" lastbatchcompleted="2020-02-26T15:09:44.363" lastattention="1900-01-01T00:00:00.363" clientapp="jTDS" hostname="LP097MID8513" hostpid="123" isolationlevel="read committed (2)" xactid="125034381" currentdb="6" currentdbname="server1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="18" stmtend="164" sqlhandle="0x02000000baccf036bb7c864a41cd9425eebee165c997e0b00000000000000000000000000000000000000000">unknown </frame>
</executionStack>
<inputbuf>(@P0 int)select sum(AMOUNT) from TABLEA where IND_REJECT='Y' and ID_BILL= @P0 </inputbuf>
</process>
<process id="process1bc9a158108" taskpriority="0" logused="10000" waittime="1499" schedulerid="2" kpid="4624" status="suspended" spid="72" sbid="0" ecid="5" priority="0" trancount="0" lastbatchstarted="2020-02-26T15:09:44.367" lastbatchcompleted="2020-02-26T15:09:44.363" lastattention="1900-01-01T00:00:00.363" clientapp="jTDS" hostname="LP097MID8513" hostpid="123" isolationlevel="read committed (2)" xactid="125034381" currentdb="6" currentdbname="server1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="18" stmtend="164" sqlhandle="0x02000000baccf036bb7c864a41cd9425eebee165c997e0b00000000000000000000000000000000000000000">unknown </frame>
</executionStack>
<inputbuf>(@P0 int)select sum(AMOUNT) from TABLEA where IND_REJECT='Y' and ID_BILL= @P0 </inputbuf>
</process>
<process id="process1bc993e84e8" taskpriority="0" logused="10000" waittime="1498" schedulerid="4" kpid="13552" status="suspended" spid="72" sbid="0" ecid="2" priority="0" trancount="0" lastbatchstarted="2020-02-26T15:09:44.367" lastbatchcompleted="2020-02-26T15:09:44.363" lastattention="1900-01-01T00:00:00.363" clientapp="jTDS" hostname="LP097MID8513" hostpid="123" isolationlevel="read committed (2)" xactid="125034381" currentdb="6" currentdbname="server1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="18" stmtend="164" sqlhandle="0x02000000baccf036bb7c864a41cd9425eebee165c997e0b00000000000000000000000000000000000000000">unknown </frame>
</executionStack>
<inputbuf>(@P0 int)select sum(AMOUNT) from TABLEA where IND_REJECT='Y' and ID_BILL= @P0 </inputbuf>
</process>
<process id="process1bc9a2c48c8" taskpriority="0" logused="10000" waittime="1499" schedulerid="3" kpid="9660" status="suspended" spid="72" sbid="0" ecid="6" priority="0" trancount="0" lastbatchstarted="2020-02-26T15:09:44.367" lastbatchcompleted="2020-02-26T15:09:44.363" lastattention="1900-01-01T00:00:00.363" clientapp="jTDS" hostname="LP097MID8513" hostpid="123" isolationlevel="read committed (2)" xactid="125034381" currentdb="6" currentdbname="server1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="18" stmtend="164" sqlhandle="0x02000000baccf036bb7c864a41cd9425eebee165c997e0b00000000000000000000000000000000000000000">unknown </frame>
</executionStack>
<inputbuf>(@P0 int)select sum(AMOUNT) from TABLEA where IND_REJECT='Y' and ID_BILL= @P0 </inputbuf>
</process>
<process id="process1bc993e8108" taskpriority="0" logused="10000" waittime="2502" schedulerid="4" kpid="15204" status="suspended" spid="72" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2020-02-26T15:09:44.367" lastbatchcompleted="2020-02-26T15:09:44.363" lastattention="1900-01-01T00:00:00.363" clientapp="jTDS" hostname="LP097MID8513" hostpid="123" loginname="xcaf" isolationlevel="read committed (2)" xactid="125034381" currentdb="6" currentdbname="server1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="18" stmtend="164" sqlhandle="0x02000000baccf036bb7c864a41cd9425eebee165c997e0b00000000000000000000000000000000000000000">unknown </frame>
</executionStack>
<inputbuf>(@P0 int)select sum(AMOUNT) from TABLEA where IND_REJECT='Y' and ID_BILL= @P0 </inputbuf>
</process>
<process id="process1bc993b1c28" taskpriority="0" logused="10000" waittime="1497" schedulerid="6" kpid="8708" status="suspended" spid="72" sbid="0" ecid="1" priority="0" trancount="0" lastbatchstarted="2020-02-26T15:09:44.367" lastbatchcompleted="2020-02-26T15:09:44.363" lastattention="1900-01-01T00:00:00.363" clientapp="jTDS" hostname="LP097MID8513" hostpid="123" isolationlevel="read committed (2)" xactid="125034381" currentdb="6" currentdbname="server1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="18" stmtend="164" sqlhandle="0x02000000baccf036bb7c864a41cd9425eebee165c997e0b00000000000000000000000000000000000000000">unknown </frame>
</executionStack>
<inputbuf>(@P0 int)select sum(AMOUNT) from TABLEA where IND_REJECT='Y' and ID_BILL= @P0 </inputbuf>
</process>
<process id="process1bc993ceca8" taskpriority="0" logused="10000" waittime="1498" schedulerid="5" kpid="11632" status="suspended" spid="72" sbid="0" ecid="3" priority="0" trancount="0" lastbatchstarted="2020-02-26T15:09:44.367" lastbatchcompleted="2020-02-26T15:09:44.363" lastattention="1900-01-01T00:00:00.363" clientapp="jTDS" hostname="LP097MID8513" hostpid="123" isolationlevel="read committed (2)" xactid="125034381" currentdb="6" currentdbname="server1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="18" stmtend="164" sqlhandle="0x02000000baccf036bb7c864a41cd9425eebee165c997e0b00000000000000000000000000000000000000000">unknown </frame>
</executionStack>
<inputbuf>(@P0 int)select sum(AMOUNT) from TABLEA where IND_REJECT='Y' and ID_BILL= @P0 </inputbuf>
</process>
<process id="process1bc9a25bc28" taskpriority="0" logused="35648" waitresource="PAGE: 6:1:5073184 " waittime="2077" ownerId="125033657" transactionname="implicit_transaction" lasttranstarted="2020-02-26T15:09:39.767" XDES="0x1c19a7b0ba0" lockMode="IX" schedulerid="6" kpid="13120" status="suspended" spid="69" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2020-02-26T15:09:44.803" lastbatchcompleted="2020-02-26T15:09:44.793" lastattention="1900-01-01T00:00:00.793" clientapp="jTDS" hostname="LP097MID8513" hostpid="123" loginname="xcaf" isolationlevel="read committed (2)" xactid="125033657" currentdb="6" currentdbname="server1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="1126" stmtend="2768" sqlhandle="0x0200000025025e075b272ac2bce1ec6cdcbc590a955eb7d30000000000000000000000000000000000000000">unknown </frame>
</executionStack>
<inputbuf>(@P0 int,@P1 int,@P2 nvarchar(4000),@P3 int,@P4 nvarchar(4000),@P5 int,@P6 int,@P7 nvarchar(4000),@P8 datetime,@P9 datetime,@P10 decimal(38,2),@P11 nvarchar(4000),@P12 nvarchar(4000),@P13 nvarchar(4000),@P14 nvarchar(4000),@P15 nvarchar(4000),@P16 nvarchar(4000),@P17 nvarchar(4000),@P18 nvarchar(4000),@P19 nvarchar(4000),@P20 nvarchar(4000),@P21 nvarchar(4000),@P22 nvarchar(4000),@P23 nvarchar(4000),@P24 nvarchar(4000),@P25 nvarchar(4000),@P26 datetime,@P27 nvarchar(4000),@P28 datetime,@P29 nvarchar(4000),@P30 int,@P31 nvarchar(4000),@P32 datetime,@P33 int)insert into dbo.TABLEA ( </inputbuf>
</process>
</process-list>
<resource-list>
<pagelock fileid="1" pageid="2283030" dbid="6" subresource="FULL" objectname="server1.dbo.TABLEA" id="lock1be67e3cd00" mode="IX" associatedObjectId="72057594048610304">
<owner-list>
<owner id="process1bc9a25bc28" mode="IX" />
</owner-list>
<waiter-list>
<waiter id="process1bc9a10bc28" mode="S" requestType="wait" />
</waiter-list>
</pagelock>
<exchangeEvent id="Pipe1bedeed8a80" WaitType="e_waitPipeGetRow" waiterType="Consumer" nodeId="5" tid="4" ownerActivity="sentData" waiterActivity="needMoreData" merging="false" spilling="false" waitingToClose="false">
<owner-list>
<owner id="process1bc9a10bc28" />
</owner-list>
<waiter-list>
<waiter id="process1bc994bf848" />
</waiter-list>
</exchangeEvent>
<exchangeEvent id="Pipe1bedeed8b80" WaitType="e_waitPipeGetRow" waiterType="Consumer" nodeId="5" tid="5" ownerActivity="sentData" waiterActivity="needMoreData" merging="false" spilling="false" waitingToClose="false">
<owner-list>
<owner id="process1bc9a10bc28" />
</owner-list>
<waiter-list>
<waiter id="process1bc9a158108" />
</waiter-list>
</exchangeEvent>
<exchangeEvent id="Pipe1bedeed8880" WaitType="e_waitPipeGetRow" waiterType="Consumer" nodeId="5" tid="2" ownerActivity="sentData" waiterActivity="needMoreData" merging="false" spilling="false" waitingToClose="false">
<owner-list>
<owner id="process1bc9a10bc28" />
</owner-list>
<waiter-list>
<waiter id="process1bc993e84e8" />
</waiter-list>
</exchangeEvent>
<exchangeEvent id="Pipe1bedeed8c80" WaitType="e_waitPipeGetRow" waiterType="Consumer" nodeId="5" tid="6" ownerActivity="sentData" waiterActivity="needMoreData" merging="false" spilling="false" waitingToClose="false">
<owner-list>
<owner id="process1bc9a10bc28" />
</owner-list>
<waiter-list>
<waiter id="process1bc9a2c48c8" />
</waiter-list>
</exchangeEvent>
<exchangeEvent id="Pipe1bedeed8380" WaitType="e_waitPipeGetRow" waiterType="Coordinator" nodeId="2" tid="0" ownerActivity="sentData" waiterActivity="needMoreData" merging="false" spilling="false" waitingToClose="false">
<owner-list>
<owner id="process1bc993b1c28" />
<owner id="process1bc993e84e8" />
<owner id="process1bc993ceca8" />
<owner id="process1bc994bf848" />
<owner id="process1bc9a158108" />
<owner id="process1bc9a2c48c8" />
</owner-list>
<waiter-list>
<waiter id="process1bc993e8108" />
</waiter-list>
</exchangeEvent>
<exchangeEvent id="Pipe1bedeed8780" WaitType="e_waitPipeGetRow" waiterType="Consumer" nodeId="5" tid="1" ownerActivity="sentData" waiterActivity="needMoreData" merging="false" spilling="false" waitingToClose="false">
<owner-list>
<owner id="process1bc9a10bc28" />
</owner-list>
<waiter-list>
<waiter id="process1bc993b1c28" />
</waiter-list>
</exchangeEvent>
<exchangeEvent id="Pipe1bedeed8980" WaitType="e_waitPipeGetRow" waiterType="Consumer" nodeId="5" tid="3" ownerActivity="sentData" waiterActivity="needMoreData" merging="false" spilling="false" waitingToClose="false">
<owner-list>
<owner id="process1bc9a10bc28" />
</owner-list>
<waiter-list>
<waiter id="process1bc993ceca8" />
</waiter-list>
</exchangeEvent>
<pagelock fileid="1" pageid="5073184" dbid="6" subresource="FULL" objectname="server1.dbo.TABLEA" id="lock1bf59410980" mode="S" associatedObjectId="72057594048610304">
<owner-list>
<owner id="process1bc993e8108" mode="S" />
</owner-list>
<waiter-list>
<waiter id="process1bc9a25bc28" mode="IX" requestType="wait" />
</waiter-list>
</pagelock>
</resource-list>
</deadlock>
CREATE TABLE TABLEA (
ID_TABLEA numeric(10,0) IDENTITY(1,1) NOT NULL,
ID_BILL numeric(10,0) NOT NULL,
AMOUNT numeric(16,2) NULL,
IND_REJECT char(1) COLLATE French_CI_AS NULL,
CONSTRAINT PK__TABLEA__0F1F9EE614270015 PRIMARY KEY (ID_TABLEA),
)