June 12, 2015 at 4:22 am
matthew.green 36969 (6/12/2015)
fyi deadlock graph attachedthe 2 conflicting statments in this instance are:
303: MarkAsCompleted 'C0239484'
192: MarkAsKO 'C0239494'
As such seems to be conflicting with another proc - im reviewing now
Thanks for the info. Next time, please post the deadlock XML and not a picture of the deadlock graph.
-- Gianluca Sartori
June 12, 2015 at 4:25 am
not sure where my deadlock post has gone with the graph attached (prehaps some sort of review)
anyway - graph showed it was conflicting with a similar proc (markascomplete) used the same code but with different variables - i have updated that proc using the same methodology as the mark KO - ffingers crossed
June 12, 2015 at 4:49 am
hmm - seems to still deadlock - normally against itself:
Deadlock graph150823671sa0X0116
2015-06-12 11:31:09.347<deadlock-list>
<deadlock victim="processa58e3048">
<process-list>
<process id="processa58e3048" taskpriority="0" logused="2204" waitresource="RID: 29:1:11558:16" waittime="2754" ownerId="2184117293" transactionname="user_transaction" lasttranstarted="2015-06-12T11:31:06.563" XDES="0xaf8403b0" lockMode="U" schedulerid="2" kpid="4832" status="suspended" spid="443" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2015-06-12T11:31:06.563" lastbatchcompleted="2015-06-12T11:31:06.563" clientapp=".Net SqlClient Data Provider" hostname="1" hostpid="2472" isolationlevel="read committed (2)" xactid="2184117293" currentdb="29" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056">
<executionStack>
<frame procname="MarkAsKO" line="12" stmtstart="928" stmtend="1554" sqlhandle="0x03001d009357ea08a9ccaf00b5a400000100000000000000">
UPDATE tbl_main
SET inprogress = 0,
caseworked = 1,
success = 0,
Exception = 1,
ExceptionReason = @reason,
DateWorked = getdate(),
LastURL = @LastURL,
@RecordID = RecordID
WHERE lockedby = @Username; </frame>
<frame procname="adhoc" line="1" sqlhandle="0x01001d006295750b804f1282010000000000000000000000">
MarkAsKO 'C0239486', 'KO - Perform IDV link didnt show expected page, most likely invalid data input error','http://sabb1.santanderuk.gs.corp/ACTRAB_ENS/BtoChannelDriver.ssobto?dse_operationName=OP_FlowAccountTransfActivationP2at&dse_parentContextName=&dse_processorState=initial&dse_nextEventName=start&taskId=lnxipe60p|SPP21ATR|ab258491|R|13031606|48490291|lnxipe60p|FULLFILM|0|22&navName=NAV1' </frame>
</executionStack>
<inputbuf>
MarkAsKO 'C0239486', 'KO - Perform IDV link didnt show expected page, most likely invalid data input error','urlt&taskId=lnxipe60p|SPP21ATR|ab258491|R|13031606|48490291|lnxipe60p|FULLFILM|0|22&navName=NAV1' </inputbuf>
</process>
<process id="processa58e2748" taskpriority="0" logused="2204" waitresource="RID: 29:1:142641:4" waittime="2710" ownerId="2184117289" transactionname="user_transaction" lasttranstarted="2015-06-12T11:31:06.560" XDES="0x191930e80" lockMode="U" schedulerid="2" kpid="3428" status="suspended" spid="452" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2015-06-12T11:31:06.560" lastbatchcompleted="2015-06-12T11:31:06.560" clientapp=".Net SqlClient Data Provider" hostname="2" hostpid="4144" loginname="" isolationlevel="read committed (2)" xactid="2184117289" currentdb="29" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056">
<executionStack>
<frame procname="MarkAsKO" line="12" stmtstart="928" stmtend="1554" sqlhandle="0x03001d009357ea08a9ccaf00b5a400000100000000000000">
UPDATE tbl_main
SET inprogress = 0,
caseworked = 1,
success = 0,
Exception = 1,
ExceptionReason = @reason,
DateWorked = getdate(),
LastURL = @LastURL,
@RecordID = RecordID
WHERE lockedby = @Username; </frame>
<frame procname="adhoc" line="1" sqlhandle="0x01001d00a363b523e008c32e010000000000000000000000">
MarkAsKO 'C0239477', 'KO - Perform IDV link didnt show expected page, most likely invalid data input error','url&taskId=lnxipe60p|SPP21ATR|ab258512|R|13122709|48490615|lnxipe60p|FULLFILM|0|22&navName=NAV1' </frame>
</executionStack>
<inputbuf>
MarkAsKO 'C0239477', 'KO - Perform IDV link didnt show expected page, most likely invalid data input error','url&taskId=lnxipe60p|SPP21ATR|ab258512|R|13122709|48490615|lnxipe60p|FULLFILM|0|22&navName=NAV1' </inputbuf>
</process>
</process-list>
<resource-list>
<ridlock fileid="1" pageid="11558" dbid="29" objectname="BBsimplifacation.dbo.Tbl_main" id="lockc34d0200" mode="X" associatedObjectId="72057594038779904">
<owner-list>
<owner id="processa58e2748" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="processa58e3048" mode="U" requestType="wait"/>
</waiter-list>
</ridlock>
<ridlock fileid="1" pageid="142641" dbid="29" objectname="BBsimplifacation.dbo.Tbl_main" id="lock133caa200" mode="X" associatedObjectId="72057594038779904">
<owner-list>
<owner id="processa58e3048" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="processa58e2748" mode="U" requestType="wait"/>
</waiter-list>
</ridlock>
</resource-list>
</deadlock>
</deadlock-list>
June 12, 2015 at 4:51 am
Table and index definitions please.
Do you have a unique index on LockedBy?
Why does the table not have a clustered index?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 12, 2015 at 4:57 am
Looks like you have no unique index on lockedby.
-- Gianluca Sartori
June 12, 2015 at 4:58 am
tbl is for a temp quick and dirty process I am running - max 90k records - default value for user id is '-'
as such no unique index, just added a clustered index (non unique) on username as will probably save a few seconds
fyi:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Tbl_main](
[RecordID] [bigint] IDENTITY(1,1) NOT NULL,
[Sortcode] [nchar](6) NOT NULL,
[AccountNumber] [nchar](8) NOT NULL,
[ProductType] [nchar](55) NOT NULL,
[DateImported] [datetime] NOT NULL,
[InProgress] [bit] NOT NULL,
[CaseWorked] [bit] NOT NULL,
[Success] [bit] NOT NULL,
[Exception] [bit] NOT NULL,
[ExceptionReason] [nvarchar](1024) NULL,
[DateWorked] [datetime] NULL,
[Locked] [bit] NOT NULL,
[LockedBy] [nvarchar](25) NOT NULL,
[LockedAt] [datetime] NULL,
[LastURL] [nvarchar](1024) NOT NULL,
[Initial_Prod] [nvarchar](255) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Tbl_main] ADD CONSTRAINT [DateImported] DEFAULT (getdate()) FOR [DateImported]
GO
ALTER TABLE [dbo].[Tbl_main] ADD CONSTRAINT [DF_Tbl_main_InProgress] DEFAULT ((0)) FOR [InProgress]
GO
ALTER TABLE [dbo].[Tbl_main] ADD CONSTRAINT [DF_Tbl_main_CaseWorked] DEFAULT ((0)) FOR [CaseWorked]
GO
ALTER TABLE [dbo].[Tbl_main] ADD CONSTRAINT [DF_Tbl_main_Success] DEFAULT ((0)) FOR [Success]
GO
ALTER TABLE [dbo].[Tbl_main] ADD CONSTRAINT [DF_Tbl_main_Exception] DEFAULT ((0)) FOR [Exception]
GO
ALTER TABLE [dbo].[Tbl_main] ADD CONSTRAINT [DF_Tbl_main_ExceptionReason] DEFAULT (N'-') FOR [ExceptionReason]
GO
ALTER TABLE [dbo].[Tbl_main] ADD CONSTRAINT [DF_Table_1_IsLocked] DEFAULT ((0)) FOR [Locked]
GO
ALTER TABLE [dbo].[Tbl_main] ADD CONSTRAINT [DF_Tbl_main_LockedBy] DEFAULT (N'-') FOR [LockedBy]
GO
ALTER TABLE [dbo].[Tbl_main] ADD DEFAULT ('-') FOR [LastURL]
GO
ALTER TABLE [dbo].[Tbl_main] ADD DEFAULT ('-') FOR [Initial_Prod]
GO
June 12, 2015 at 4:59 am
the uniqueness of that column is handled from my app - as you can see from deadlocks - it is always using different id's
June 12, 2015 at 5:07 am
Put a unique nonclustered index on the LockedBy column.
It can be a filtered index since not all rows will be locked, and the default for a row that isn't locked should be NULL, not -
Firstly to help with the deadlocks, second because 'it's enforced by the app' is followed by 'why is my data wrong' in just about every case I've seen.
LockedBy is a very poor choice for a clustered index. It's not narrow, it's not ever-increasing and it's not unchanging. Almost any other place will likely be better.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 12, 2015 at 5:11 am
GilaMonster (6/12/2015)
'it's enforced by the app' is followed by 'why is my data wrong' in just about every case I've seen.
If I had $0.01 for every time this happened to me, I would be answering SSC questions from my beach manor at the Maldives 😀
-- Gianluca Sartori
June 12, 2015 at 5:11 am
ya i got to that - going to rebuild using recordid as key as will be quicker than trying to work out what the hells happening here as am really scratching my head!!
June 12, 2015 at 5:50 am
rebuilt properly (using record id for all selects/updates/inserts) - and been running for a while with no deadlocks.... still dont understand what was causing them though as the ids were definetly unique, and had ran fine for last few days!....
thanks for the info guys, much appreciated
June 12, 2015 at 6:23 am
You knew the IDs were unique, SQL didn't so it had to take wider locks than it would have if you'd had a unique index there in the first place.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 12, 2015 at 7:57 am
ta for the update - this is still running without issue
Viewing 13 posts - 16 through 28 (of 28 total)
You must be logged in to reply to this topic. Login to reply