t***@momentum.co.za
2007-09-26 11:56:49 UTC
Hi
I'm experiencing conversion deadlocks in a highly concurrent java application which uses Hibernate with Cursor Stability isolation level.
One thread issues a "select * from myTable where pkey=? for update with cs" to acquire an update lock, followed by and "update myTable, set blah blah where pkey=?". The select for update is required both to acquire a lock and refresh the data since optimistic locking is used and multiple threads could both have read the same data.
Another thread uses exactly the same statements and occasionly I get a conversion deadlock (Thread 1 gets an NS->Update conversion lock and thread 2 an Update->Exclusive conversion lock).
All the reading I've done suggests that select for update issues an NS lock prior to the Update lock, so thread 2 can acquire an NS lock while thread 1 has an Update lock. If the X lock is now attempted by thread 1, the deadlock occurs.
How can I avoid this situation?
Is there any other way to get an update(or exclusive) lock without using "select for update" or changing my isolation level?
Regards
Terry
I'm experiencing conversion deadlocks in a highly concurrent java application which uses Hibernate with Cursor Stability isolation level.
One thread issues a "select * from myTable where pkey=? for update with cs" to acquire an update lock, followed by and "update myTable, set blah blah where pkey=?". The select for update is required both to acquire a lock and refresh the data since optimistic locking is used and multiple threads could both have read the same data.
Another thread uses exactly the same statements and occasionly I get a conversion deadlock (Thread 1 gets an NS->Update conversion lock and thread 2 an Update->Exclusive conversion lock).
All the reading I've done suggests that select for update issues an NS lock prior to the Update lock, so thread 2 can acquire an NS lock while thread 1 has an Update lock. If the X lock is now attempted by thread 1, the deadlock occurs.
How can I avoid this situation?
Is there any other way to get an update(or exclusive) lock without using "select for update" or changing my isolation level?
Regards
Terry