473,385 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Deadlock or timeout on executeBatch()

Hi there

we are getting the following db2 error on executeBatch() method that
inserts n rows on a table (where n is between 50 and 200).

[IBM][CLI Driver][DB2/NT] SQL0911N The current transaction has been
rolled back because of a deadlock or timeout. Reason code "2".
SQLSTATE=40001
errorCode : 911

Problem raises just when two or more people try to insert , at the
same time, on the table..
with one user there is no problem and the insert batch is perfectly
done by db2.

The batch java code is very simple:

connection = ds.getConnection("bla","bla");
connection.setAutoCommit(false);
myStatement = connection .createStatement();
for(int i=0;i<inSqlCommand1.size();i++) {
myStatement.addBatch((String)inSqlCommand1.get(i)) ;
}
updateCounts = myStatement.executeBatch();
if(Ok) connection.commit();
else connection.rollback();

Any hints?

tnx
M.
Nov 12 '05 #1
8 9485
If you are working with a DB2 V8.1 system, there is
a deadlock event monitor automatically generated
when you create a database.

The event monitor is called DB2DETAILDEADLOCK and is
activated by default.

You might flush the event monitor and analyze your
deadlock situation with the db2evmon tool.

Example for Unix based systems:

- cd <INSTANCE_HOME>/<INSTANCE>/NODE0000/SQL0000#/db2event/db2detaildeadlock
- db2 'flush event monitor db2detaillock'
- db2evmon -d <dbname> db2detaildeadlock

This might give you an idea what is causing the deadlock situation.

HTH.
Best regards

Eric

Javauser wrote:
Hi there

we are getting the following db2 error on executeBatch() method that
inserts n rows on a table (where n is between 50 and 200).

[IBM][CLI Driver][DB2/NT] SQL0911N The current transaction has been
rolled back because of a deadlock or timeout. Reason code "2".
SQLSTATE=40001
errorCode : 911

Problem raises just when two or more people try to insert , at the
same time, on the table..
with one user there is no problem and the insert batch is perfectly
done by db2.

The batch java code is very simple:

connection = ds.getConnection("bla","bla");
connection.setAutoCommit(false);
myStatement = connection .createStatement();
for(int i=0;i<inSqlCommand1.size();i++) {
myStatement.addBatch((String)inSqlCommand1.get(i)) ;
}
updateCounts = myStatement.executeBatch();
if(Ok) connection.commit();
else connection.rollback();

Any hints?

tnx
M.


--
IT-Consulting Herber
Mobile: +49 177 2276895
***********************************************
Download the IFMX Database-Monitor for free at:
http://www.herber-consulting.de/BusyBee
***********************************************
Nov 12 '05 #2
Hi Eric and thanks for your help..
unluckily we are using 7.2.3 version of Db2.

Anyway i've tried to snapshot a lock monitor and i have obtained this
log's snippet..

Database Lock Snapshot

Database name = BANKTEST

Database path = D:\DB2\NODE0000\SQL00017\

Input database alias = BANKTEST

Locks held = 2036

Applications currently connected = 4

Agents currently waiting on locks = 2

Snapshot timestamp = 01-09-2004
11:20:27.745603

Application handle = 17

Application ID =
0A0A0A68.D109.040109082850

Sequence number = 0001

Application name = java.exe

Authorization ID = DB2ADMIN

Application status = Lock-wait

Status change time = Not Collected

Application code page = 1252

Locks held = 563

Total wait time (ms) = Not Collected

List Of Locks

Lock Object Name = 0

Node number lock is held at = 0

Object Type = Internal V Lock

Tablespace Name =

Table Schema =

Table Name =

Mode = S

Status = Granted

Lock Escalation = NO

Lock Object Name = 293378

Node number lock is held at = 0

Object Type = Row

Tablespace Name = USERSPACE1

Table Schema = BANKTEST

Table Name = ROAMS

Mode = W

Status = Granted

Lock Escalation = NO
Application handle = 25

Application ID =
0A0A0A68.180A.040109101223

Sequence number = 0001

Application name = java.exe

Authorization ID = DB2ADMIN

Application status = UOW Waiting

Status change time = Not Collected

Application code page = 1252

Locks held = 0

Total wait time (ms) = Not Collected

Application handle = 26

Application ID =
0A0A0A68.190A.040109101224

Sequence number = 0001

Application name = java.exe

Authorization ID = DB2ADMIN

Application status = UOW Executing

Status change time = Not Collected

Application code page = 1252

Locks held = 910

Total wait time (ms) = Not Collected

List Of Locks

Lock Object Name = 0

Node number lock is held at = 0

Object Type = Internal V Lock

Tablespace Name =

Table Schema =

Table Name =

Mode = S

Status = Granted

Lock Escalation = NO

Lock Object Name = 333057

Node number lock is held at = 0

Object Type = Row

Tablespace Name = USERSPACE1

Table Schema = BANKTEST

Table Name = WEARS

Mode = W

Status = Granted

Lock Escalation = NO


i have noticed that problem is related to autocommit..if i turn the
autocommit to true everything works fine.

Any hints would be appreciated.

M.
Nov 12 '05 #3
"Javauser" <ke******@mailinator.com> wrote in message
news:68**************************@posting.google.c om...
Hi Eric and thanks for your help..
unluckily we are using 7.2.3 version of Db2.

Anyway i've tried to snapshot a lock monitor and i have obtained this
log's snippet..

If autocommit is turned off, you should do explicit commits in the
application to release the locks. You might also check to see that your are
using CS isolation level.
Nov 12 '05 #4
> If autocommit is turned off, you should do explicit commits in the
application to release the locks. You might also check to see that your are
using CS isolation level.


Hi and thanks for reply..
if u watch the snippet above , at the bottom i do commits on
connection.

anyway i created an event monitor for deadlock and i found that is
caused by an update..sorry..i believed transaction was formed just by
inserts.

So..i do n inserts and 1 update on table (where id is primary key)

Application 1 does:
PREPARE
EXECUTE insert into table (id,id_pres,something) values (1,30,'test')
EXECUTE insert into table (id,id_pres,something) values (2,30,'test')
EXECUTE insert into table (id,id_pres,something) values (3,30,'test')
EXECUTE insert into table (id,id_pres,something) values (4,30,'test')
update table set something='testupdate' where id_pres=30 -->causes
deadlock

Application 2 at the same time does:
PREPARE
EXECUTE insert into table (id,id_pres,something) values (5,40,'test')
EXECUTE insert into table (id,id_pres,something) values (6,40,'test')
EXECUTE insert into table (id,id_pres,something) values (7,40,'test')
EXECUTE insert into table (id,id_pres,something) values (8,40,'test')
update table set something='testupdate' where id_pres=40 -->causes
deadlock

then a deadlock agent raises an exception (SQLSTATE=40001,errorCode :
911)
on one of two application and the other one can complete the
transaction.

Can u explain me why there's a deadlock on update?

many thanks..

M.
Nov 12 '05 #5
In article <68**************************@posting.google.com >,
Javauser (ke******@mailinator.com) says...
If autocommit is turned off, you should do explicit commits in the
application to release the locks. You might also check to see that your are
using CS isolation level.


Hi and thanks for reply..
if u watch the snippet above , at the bottom i do commits on
connection.

anyway i created an event monitor for deadlock and i found that is
caused by an update..sorry..i believed transaction was formed just by
inserts.

So..i do n inserts and 1 update on table (where id is primary key)

Application 1 does:
PREPARE
EXECUTE insert into table (id,id_pres,something) values (1,30,'test')
EXECUTE insert into table (id,id_pres,something) values (2,30,'test')
EXECUTE insert into table (id,id_pres,something) values (3,30,'test')
EXECUTE insert into table (id,id_pres,something) values (4,30,'test')
update table set something='testupdate' where id_pres=30 -->causes
deadlock

Application 2 at the same time does:
PREPARE
EXECUTE insert into table (id,id_pres,something) values (5,40,'test')
EXECUTE insert into table (id,id_pres,something) values (6,40,'test')
EXECUTE insert into table (id,id_pres,something) values (7,40,'test')
EXECUTE insert into table (id,id_pres,something) values (8,40,'test')
update table set something='testupdate' where id_pres=40 -->causes
deadlock

then a deadlock agent raises an exception (SQLSTATE=40001,errorCode :
911)
on one of two application and the other one can complete the
transaction.

Can u explain me why there's a deadlock on update?

many thanks..

M.


After the inserts Application 1 is holding exclusive locks on id 1 -
4 and application 2 is holding exclusive locks on id 5 - 8.
A1 needs to scan the full table to update rows with id_pres = 30 and
is waiting on A2. Then A2 needs to scan the full table and is waiting
on A1 et voila !

One way to prevent this could be to create a type2 index on id_pres.
This is default if the table is created on DB2 V8. You might need to
recreate your indexes if you migrated from V7. If you're not on V8
you need to commit before updating, no type2 index is available prior
to V8.

Hope this helps.

Kind regards, Gert
Nov 12 '05 #6
> After the inserts Application 1 is holding exclusive locks on id 1 -
4 and application 2 is holding exclusive locks on id 5 - 8.
A1 needs to scan the full table to update rows with id_pres = 30 and
is waiting on A2. Then A2 needs to scan the full table and is waiting
on A1 et voila !

One way to prevent this could be to create a type2 index on id_pres.
This is default if the table is created on DB2 V8. You might need to
recreate your indexes if you migrated from V7. If you're not on V8
you need to commit before updating, no type2 index is available prior
to V8.

Hope this helps.

Kind regards, Gert


Hi Gert..
thank u very much for your clear answer!
unluckily we have to stay with the V7 ..
is there any fixpack out there that can fix the problem for our db version?
In case there's not any i will commit before update like u said..

thanks again
M.

Nov 12 '05 #7
>Application 1 does:
EXECUTE insert into table (id,id_pres,something) values (1,30,'test')
EXECUTE insert into table (id,id_pres,something) values (2,30,'test')
EXECUTE insert into table (id,id_pres,something) values (3,30,'test')
EXECUTE insert into table (id,id_pres,something) values (4,30,'test')
update table set something='testupdate' where id_pres=30 -->causes
deadlock
Application 2 at the same time does:
EXECUTE insert into table (id,id_pres,something) values (5,40,'test')
EXECUTE insert into table (id,id_pres,something) values (6,40,'test')
EXECUTE insert into table (id,id_pres,something) values (7,40,'test')
EXECUTE insert into table (id,id_pres,something) values (8,40,'test')
update table set something='testupdate' where id_pres=40 -->causes
deadlock
This is default if the table is created on DB2 V8. You might need to
recreate your indexes if you migrated from V7. If you're not on V8
you need to commit before updating, no type2 index is available prior


I'm committing before updating like u said but it still does not work!
autocommit is set to true of course and i removed the executeBatch()
method....
now i just run with executeUpdate() n 'inserts' and than executeUpdate() m
'updates' on the same connection..
but damn..deadlock raises in one of the updates.

i'm talking about n=800 and m=10 for 4 concurrent applications on the same
table.
with a lower number of inserts (about 400) and less concurrent applications
it works..

now the isolation level is by default set to READ_COMMITTED..
i've tried to change it to READ_UNCOMMITTED but it still does not work..

i can't believe it..

any suggestion would be appreciated..

Tnx
M.


Nov 12 '05 #8
"Javauser" <ke******@mailinator.com> wrote in message
now the isolation level is by default set to READ_COMMITTED..
i've tried to change it to READ_UNCOMMITTED but it still does not work..

i can't believe it..

any suggestion would be appreciated..

Tnx
M.


I do not have your DDL for the table and indexes, nor the
exact SQL, but it sounds simple to discover what's really
happening.
If you really want to see what's happening
then do a manual test. Use GET SNAPSHOT FOR LOCKS along with
the CLP and do not commit. By that I mean
to use at least two shell windows (or command-prompts
depending on your platform), and execute (for a test)
the update commands manually WITHOUT A COMMIT purely
to see for yourself what are the locks!

Use commands like these in separate windows at the same time,
on a database in which nothing much else is happening:

db2 connect to ....
db2 +c "update table set something='testupdate' where id_pres=40"
db2 get snapshot for locks on...

After the end of the test: db2 rollback.

Now compare the locks from both connections, in the different
shells/prompts. You may find that the ROW locks from the update are not
what you expect. You may find that in addition to a "U"
row locks (for the update), there might other "next key" locks.
If you find these, consider reading about DB2_RR_TO_RS=YES
registry variable , only on DB2 v7.x. This may help.
However the basic idea is to prove what's happening with the
locking by taking a real example and proving things.
Good luck.
Nov 12 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Anita | last post by:
Hi All, Can multiple updates on one table using single query generate deadlock ? For example, at the same time, there are 2 users run 2 queries as follows : User1 runs : update tab1 set...
11
by: EoRaptor | last post by:
I`m exporting data from many Lotus Notes databases to a DB2 database using LotusScript. The LotusScript agents commit after EACH update/insert. Nevertheless, I keep getting transaction rollbacks on...
8
by: mk | last post by:
You probably suspect the answer, typically its 'yes' deadlock can occur in any multithreaded application. Even ones that employ static members. Commonly it occurs when more than one thread tries...
3
by: J.Marsch | last post by:
Issue: I have 3 threads, syncing with a ReaderWriterLock (in "real life", there will be more). Thread 1 (there could be any number of these) Gets a read lock with infinite timeout. It runs in...
2
by: Sumanth | last post by:
Hi , I am trying to acquire a lock on a table A in exclusive mode, and this statement gives an error indicating a deadlock or timeout has been detected. The lock timeout value is set to 0 which...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
2
by: | last post by:
I have a db2 V. 8.1 Fix Pack 13 installed, and i have too much problem with deadlock, maibe depends becouse i have a direct remote connection with a 56k modem. Someone know if depends to a...
0
by: db2user | last post by:
Hi all, I need to alter a table to add a column into the table.I tried altering the table with the help of the control center and also using the query ALTER TABLE SIEBEL.S_USER ADD COLUMN...
1
by: kalpacx | last post by:
Hi All, I am a newbie to db2 database. Currently i am facing an issue which i know for sure that many would have faced and resolved. I am running 6 sql scripts concurrently against the db ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.