If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Table Partitioning - MERGE RANGE deadlocking

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-23-12, 17:49
Gagnon Gagnon is offline
Registered User
 
Join Date: Jun 2005
Posts: 319
Table Partitioning - MERGE RANGE deadlocking

On a system with a high number of inserts I have a job that implements a sliding window in order to purge data that is 30 days old (table is partitioned on a Date_ID column).

The problem is the job fails a lot due to deadlock.

I have tried setting DEADLOCK_PRIORITY to HIGH and then to 10 and it is still chosen as the deadlock victim.

I ran a trace and added the deadlock graph event and found it is deadlocking with an insert statement to the same table where the Date_ID is today's date.

So it would be inserting into the right most partition, I am trying to MERGE RANGE on the left most partition. I am confused as to why this should be deadlocking.

I have asked the client if they can halt inserts by stopping the windows service that controls the inserts and then start the service up after this daily purge maintenance but they said that was not an acceptable solution.

Any ideas?
Reply With Quote
  #2 (permalink)  
Old 01-30-12, 12:32
Gagnon Gagnon is offline
Registered User
 
Join Date: Jun 2005
Posts: 319
bump, they're still having issues - I really think they should change their application to halt inserts during this very brief maintenance window (less than a minute), but their company is so large and disorganized they claim it would take at least 6 months to push out a feature such as this.

Any other solutions from the db side? Originally there was data being inserted into the first partition and we assumed the extra time it took to merge these rows (compared to when it was empty) was causing the deadlock, but now we see it when the partition we are merging is empty.

The only solution I have come up with is to repeatedly attempt the merge with a 30 second delay between attempts until it is successful, it seems like a hack but I feel it is the best solution until they can change their application to pause the stream of inserts while this purge operation takes place.
Reply With Quote
  #3 (permalink)  
Old 01-30-12, 17:03
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
This is brute force and uglier than the south end of a north-bound mule, but it should work if the other process ever releases its locks long enough for this code to start running:
Code:
BEGIN TRANSACTION

SELECT COUNT(*)
   FROM DemoData (HOLDLOCK)
   WHERE DemoDate = '2012-01-20'

DELETE FROM DemoData
   WHERE DemoDate = '2012-01-20'

COMMIT TRANSACTION
-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #4 (permalink)  
Old 01-31-12, 09:52
Gagnon Gagnon is offline
Registered User
 
Join Date: Jun 2005
Posts: 319
Quote:
Originally Posted by Pat Phelan View Post
This is brute force and uglier than the south end of a north-bound mule, but it should work if the other process ever releases its locks long enough for this code to start running:
Code:
BEGIN TRANSACTION

SELECT COUNT(*)
   FROM DemoData (HOLDLOCK)
   WHERE DemoDate = '2012-01-20'

DELETE FROM DemoData
   WHERE DemoDate = '2012-01-20'

COMMIT TRANSACTION
-PatP
Thanks Pat - good stuff.
Reply With Quote
  #5 (permalink)  
Old 01-31-12, 12:12
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
The real test will be to see if this does what you need. Assuming that your server settings and the behavior of the other code is even a tiny bit forgiving, I think this will work but the proof is in the pudding.

Let me know if this works or if you need a bigger hammer.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On