Discussion:
how to produce deadlock or timeout
(too old to reply)
j***@yahoo.com
2007-10-10 04:12:38 UTC
Permalink
Hi All,
I want to simulate the deadlock or timeout environment to test on my retry program to handle the below exception.
SQL0911N The current transaction has been rolled back because of a deadlock or timeout. Reason code "2". SQLSTATE=40001

Anyone know how to produce the exception?

Thanks in advance.
Mark A
2007-10-10 04:56:54 UTC
Permalink
This post might be inappropriate. Click to display it.
j***@yahoo.com
2007-10-12 02:40:58 UTC
Permalink
Hi All,
Here is part of the program. I just want to simulate the deadlock environment in order to test out the deadlock handling part.

do {
errorCode = 0;

try {
GenUserProfileDAO.resetLogin(userId);
} catch (SQLException sqle) {
errorCode = sqle.getErrorCode();
retry++;
try {
Thread.sleep(getRandom()*1000);
} catch (InterruptedException ie) {
log.error("Thread sleeps failed", ie);
}
}
}while (errorCode == -911 && retry < SystemConfig.LOGOUT_RETRY);

I use the method u suggest.
1) set locktimeout = 30
2) db2 +c lock table genuserprofile in exclusive mode

I didn't get the deadlock exception but instead this is the error I got...
ThreadMonitor W WSVR0605W: Thread "WebContainer : 0" (0000001c) has been active for 608062 milliseconds and may be hung. There is/are 1 thread(s) in total in the server that may be hung.
Mark A
2007-10-12 03:55:10 UTC
Permalink
Post by j***@yahoo.com
Hi All,
Here is part of the program. I just want to simulate the deadlock
environment in order to test out the deadlock handling part.
do {
errorCode = 0;
try {
GenUserProfileDAO.resetLogin(userId);
} catch (SQLException sqle) {
errorCode = sqle.getErrorCode();
retry++;
try {
Thread.sleep(getRandom()*1000);
} catch (InterruptedException ie) {
log.error("Thread sleeps failed", ie);
}
}
}while (errorCode == -911 && retry < SystemConfig.LOGOUT_RETRY);
I use the method u suggest.
1) set locktimeout = 30
2) db2 +c lock table genuserprofile in exclusive mode
I didn't get the deadlock exception but instead this is the error I got...
ThreadMonitor W WSVR0605W: Thread "WebContainer : 0" (0000001c) has been
active for 608062 milliseconds and may be hung. There is/are 1 thread(s)
in total in the server that may be hung.
First, the method I suggested above will not yield a deadlock, but it will
yield a locktimeout. Both are -911, but a deadlock is reason code 2 and
locktimeout is reason code 68.

It looks like you are getting a warning error from Websphere, which is your
connection pooling software.

Keep in mind that until you release the table lock in step 2 above, your
java program will keep doing the retry logic after the 30 second locktimeout
period is over and your program receives its first -911 (basically in a
loop), but nothing will change since it is still locked and eventually
Websphere will issue the WSVR0605W above. So my guess is that your retry
logic is working, if that is really what you want to do. You probably need
some kind of "give up" logic if the locking problem is not resolved within a
reasonable time before you get whacked by Websphere.

Also keep in mind that DB2 automatically checks for true deadlocks (not
locktimeouts) every 10 seconds (by default) and solves the problem by
cancelling one the applications (the victim) to let the other one through.
Jan M. Nelken
2007-10-10 06:32:47 UTC
Permalink
Post by j***@yahoo.com
Hi All,
I want to simulate the deadlock or timeout environment to test on my retry program to handle the below exception.
SQL0911N The current transaction has been rolled back because of a deadlock or timeout. Reason code "2". SQLSTATE=40001
Anyone know how to produce the exception?
Thanks in advance.
It is relatively very simple to create a deadlock situation. Using DB2
UDB SAMPLE database - specifically tables ORG and PRODUCT, follow thoese
easy steps.


1. Open 2 DB2 command windows;
2. In session 1:

db2 connect to SAMPLE
db2 -c- delete from ORG


3. In session 2:

db2 connect to SAMPLE
db2 -c- delete from PRODUCT


Next two command you have to issue relatively quickly - deadlock
detector by default scans for deadlock every 10 sec.


4. In session 1:

db2 -c- select * from PRODUCT


5. In session 2:

db2 -c- select * from ORG


Presto - one of the session will receive -911 RC=2 SQLCODE. It is
difficult to predict which session will get it though.


Jan M. Nelken
Mark A
2007-10-10 07:03:57 UTC
Permalink
It is relatively very simple to create a deadlock situation. Using DB2 UDB
SAMPLE database - specifically tables ORG and PRODUCT, follow thoese easy
steps.
1. Open 2 DB2 command windows;
db2 connect to SAMPLE
db2 -c- delete from ORG
db2 connect to SAMPLE
db2 -c- delete from PRODUCT
Next two command you have to issue relatively quickly - deadlock detector
by default scans for deadlock every 10 sec.
db2 -c- select * from PRODUCT
db2 -c- select * from ORG
Presto - one of the session will receive -911 RC=2 SQLCODE. It is
difficult to predict which session will get it though.
Jan M. Nelken
That is not what the OP asked. The OP has an application program written
that is designed to handle a -911 and the program will do a retry.

If you can use one command line session and one application program to
deadlock with each other, that would be fine, but the retry code is in the
application program, not in the a command line session.
Jan M. Nelken
2007-10-10 18:52:17 UTC
Permalink
Post by Mark A
That is not what the OP asked. The OP has an application program written
that is designed to handle a -911 and the program will do a retry.
If you can use one command line session and one application program to
deadlock with each other, that would be fine, but the retry code is in the
application program, not in the a command line session.
Well - since it is not predictable which participant - or "victim" -
will receive -911 RC=2 and rollback - best approach would be to have
multiple threads:

one (main) driver;
one thread per connection;

implementing idea outlined in my previous post.


With command session and application program it is uncertain who will be
chosen as victim.


Jan M. Nelken
Mark A
2007-10-11 00:23:28 UTC
Permalink
"Jan M. Nelken" <***@Invalid.Domain> wrote in message news:fej716>
Well - since it is not predictable which participant - or "victim" -
Post by Jan M. Nelken
will receive -911 RC=2 and rollback - best approach would be to have
one (main) driver;
one thread per connection;
implementing idea outlined in my previous post.
With command session and application program it is uncertain who will be
chosen as victim.
Jan M. Nelken
I am guessing that the OP wants to test it with the programs as they are
written, and not programs that are poorly written to enhance the chance of a
deadlock. The locktimeout is easy, but inducing a deadlock in a well written
application is not so easy.
Knut Stolze
2007-10-11 12:21:06 UTC
Permalink
Post by Mark A
I am guessing that the OP wants to test it with the programs as they are
written, and not programs that are poorly written to enhance the chance of
a deadlock. The locktimeout is easy, but inducing a deadlock in a well
written application is not so easy.
That's the main question here: what exactly does the OP want to do?

I would have a small C program that specifically triggers a deadlock.
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Mark A
2007-10-11 12:26:39 UTC
Permalink
Post by Knut Stolze
That's the main question here: what exactly does the OP want to do?
I would have a small C program that specifically triggers a deadlock.
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
The OP has added logic to their program that intercepts a -911 and does a
retry. They want to test it.
Loading...