db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bogdan Calmac" <bc4...@gmail.com>
Subject Concurrent select and insert deadlock on index
Date Thu, 02 Aug 2007 04:40:02 GMT
The attached test is an attempt to simulate a typical data processing
application, it consists of:
 - an insert thread that inserts records in batch
 - a select thread that 'processes' the records inserted by the other
thread: 'select * from table where id > ?'

The test deadlocks, the trace can be found in 'derby.log' and the java
stacktraces just before the deadlock in
'stacktraces_during_deadlock.txt'.

After examining them, I think that:
 - the select thread holds an S lock on the root of the PK index: (1,1)
 - the select thread waits for an S lock on one of the uncommitted inserts

 - the insert thread holds X locks on the inserted records
 - the insert thread tries to split the btree root of the PK index:
(1,1) by acquiring an X lock, so it's a deadlock

Before jumping to conclusions, can somebody confirm if this looks like
an expected behaviour or is it a bug?

I hope it is a bug, otherwise the workaround is to use table locks and
concurrency is gone.

To execute the test you can do:

javac InsertSelectDeadlock.java
ij derby.sql
java -cp .;derby-10.2.2.0.jar InsertSelectDeadlock

Thanks,

Bogdan Calmac.

Mime
View raw message