As a quick overview, if the query needs to obtain a Shared lock it only needs to acquire the shared lock on the local partition. For an exclusive lock the query acquires the lock on each partition, always progressing from partition 0 to n to avoid deadlocks. This allows the SQL Server to utilize the local partition when appropriate and improves scalability on larger systems.
Deadlock from Shared Lock on a Different Partition - What?
The problem I was presented with was the following deadlock output. (This was from trace flag 1222 and 3605 to add deadlock information to the error log. You could get similar information using the trace events.)
objectlock lockPartition=8 objid=1765581328 subresource=FULL dbid=8 objectname=Test id=lock47b821a00 mode=Sch-M associatedObjectId=1765581328 |
Notice the partition is 8 and the mode held is Sch-M. |
owner-list
owner id=process46c276188 mode=Sch-M |
The process is the task address that can be mapped to sys.dm_os_tasks, who owns the lock. |
waiter-list waiter id=process47b07dc38 mode=Sch-S requestType=wait |
This is the close of the deadlock cycle by the second process.
Note: The waiter list is usually printed in ascending order based on how the victims will be selected; usually work investment based. |
objectlock lockPartition=13 objid=1765581328 subresource=FULL dbid=8 objectname=Test id=lock47b821f80 mode=Sch-S associatedObjectId=1765581328 | Partition 13 is showing the process that already holds the same Sch-S and is attempting a new acquire on partition 8. |
owner-list owner id=process47b07dc38 mode=Sch-S |
Owner of the Sch-S lock. |
waiter-list waiter id=process46c276188 mode=Sch-M requestType=wait |
Blocked process attempting to acquire the Sch-M lock. This is expected as the Sch-M is attempting to acquire the lock on all partitions. |
Under a rare condition SQL Server may not associate the proper lock partition with the lock request, leading to additional locking overhead or possible deadlocks. This bug does not expose any locking problems that would lead to data integrity issues. This is a very small window during compile, before a user transaction is started.
The problem is that when using lock partitioning the Sch-S lock should be acquired on the transaction associated, local partition. However, the same process is attempting to acquire the Sch-S lock on 2 different partitions leading to the deadlock. Why?
Bob Dorr - Principal SQL Server Escalation Engineer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.