dbTalk Databases Forums  

Manual Creation of Deadlock Scenario with Stored Procedures?

comp.databases.sybase comp.databases.sybase


Discuss Manual Creation of Deadlock Scenario with Stored Procedures? in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Evan Smith
 
Posts: n/a

Default Manual Creation of Deadlock Scenario with Stored Procedures? - 12-16-2003 , 01:54 PM






We're currently experiencing deadlocks with a production application.
With the volume of transactions that we get, this behavior is not
completely unexpected. What we would like to do is trap the deadlock,
wait, and re-submit. We are having difficulty trapping the deadlock
from within the application, so what I'm looking for is a way to
create a deadlock using stored procedures to be able to simulate what
happens in our production code.

I'm somewhat of a newbie to ASE (it's been 9 years since I last worked
with Sybase). I need two procs where I can create a window large
enough to create the right sequence of events in order to trigger the
deadlock.

Currently I have the following sequence of events:

1. Proc A requests select-lock on page
2. Proc B requests exclusive-lock on same page for insert
3. Proc A requests exclusive-lock on page for update of previously
selected row.

Is there a way to "pause" a stored proc long enough to start my second
process to create the deadlock scenario? Is there a function that I
can invoke which effectively makes a procedure "sleep" for a while? I
know that usually code is written to be fast and efficient, but maybe
there's a way to induce this behavior through what otherwise might be
considered bad/sloppy coding practices.

Your help is greatly appreciated!

Evan

Reply With Quote
  #2  
Old   
Joe Weinstein
 
Posts: n/a

Default Re: Manual Creation of Deadlock Scenario with Stored Procedures? - 12-16-2003 , 02:26 PM








Evan Smith wrote:

Quote:
We're currently experiencing deadlocks with a production application.
With the volume of transactions that we get, this behavior is not
completely unexpected. What we would like to do is trap the deadlock,
wait, and re-submit. We are having difficulty trapping the deadlock
from within the application, so what I'm looking for is a way to
create a deadlock using stored procedures to be able to simulate what
happens in our production code.

I'm somewhat of a newbie to ASE (it's been 9 years since I last worked
with Sybase). I need two procs where I can create a window large
enough to create the right sequence of events in order to trigger the
deadlock.

Currently I have the following sequence of events:

1. Proc A requests select-lock on page
2. Proc B requests exclusive-lock on same page for insert
3. Proc A requests exclusive-lock on page for update of previously
selected row.

Is there a way to "pause" a stored proc long enough to start my second
process to create the deadlock scenario? Is there a function that I
can invoke which effectively makes a procedure "sleep" for a while? I
know that usually code is written to be fast and efficient, but maybe
there's a way to induce this behavior through what otherwise might be
considered bad/sloppy coding practices.

Your help is greatly appreciated!

Evan
Sure. Look up 'waitfor' in the T-SQL docs.

Joe Weinstein at BEA



Reply With Quote
  #3  
Old   
Larry Coon
 
Posts: n/a

Default Re: Manual Creation of Deadlock Scenario with Stored Procedures? - 12-16-2003 , 04:22 PM



Evan Smith wrote:

Quote:
[. . .] so what I'm looking for is a way to
create a deadlock using stored procedures to be able to simulate what
happens in our production code.
Something like this...

create table deadlock_test_1 (a int)
go
create table deadlock_test_2 (a int)
go

create procedure sp_deadlock_1 as
begin transaction
lock table deadlock_test_1 in exclusive mode
waitfor delay '00:00:10'
lock table deadlock_test_2 in exclusive mode
commit transaction
return
go

create procedure sp_deadlock_2 as
begin transaction
lock table deadlock_test_2 in exclusive mode
lock table deadlock_test_1 in exclusive mode
commit transaction
return
go

Then in one session, run sp_deadlock_1. In another
session, run sp_deadlock_2.


Larry Coon
University of California


Reply With Quote
  #4  
Old   
Bret Halford
 
Posts: n/a

Default Re: Manual Creation of Deadlock Scenario with Stored Procedures? - 12-16-2003 , 06:51 PM



Hi Evan,

You can use the WAITFOR command to put a delay between the two updates.

-bret

Reply With Quote
  #5  
Old   
Evan Smith
 
Posts: n/a

Default Re: Manual Creation of Deadlock Scenario with Stored Procedures? - 12-17-2003 , 08:10 AM



Thanks, all! I searched the online docs for both "wait" and "sleep"
and didn't find any relevant matches. This should do the trick.

Cheers!

Evan

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.