295 words

Issue #70 - Pessimistic lock timeout - blocks indefinitely

BugVersion: 2.3.1Priority: NormalStatus: FixedReplies: 3
#1
2011-09-30 13:22

I've attached a simple test which creates an object then kicks off several threads which each try to update the object. I'm using a pessimistic lock with timeout as follows:

Map<String,Object> properties = new HashMap<String,Object>();
properties.put("javax.persistence.lock.timeout", 5000);
 
MyEntity loaded = em.find(MyEntity.class, 1, LockModeType.PESSIMISTIC_WRITE, properties);

One thread manages to do its update but the others remain blocked (for longer than 5000ms at least - I killed the test after a min or so).

If I set the timeout to less than 1000ms the blocked threads get released at the correct time but thrown a LockTimeoutException implying that the first lock wasn't released on the first commit. Anything over 1000ms causes the deadlock.

felixobjectdb
felixobjectdb's picture
Joined on 2011-02-10
User Post #53
#2
2011-10-02 13:56

Thank you for this bug report and for the test.

Please try version 2.3.1 that should fix the problem.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #641
#3
2011-10-03 08:42

Thanks - looks better.

I have another issue on a similar theme though. As the timeout wasn't working last week I put the find into a loop which catches the LockTimeoutException, puts the thread to sleep, then tries the find again. I'd expect this to achieve the same result as querying with a timeout (albeit much less efficient!).

However, this is the output I get:

Starting...
updater3 starting
updater4 starting
updater0 starting
updater2 starting
updater1 starting
updater1 LockTimeoutException
updater2 LockTimeoutException
updater3 LockTimeoutException
updater4 changing name from start to updater4
updater4 commited
updater0 LockTimeoutException
updater2 changing name from start to updater2
updater3 LockTimeoutException
updater1 LockTimeoutException
updater0 LockTimeoutException
[ObjectDB 2.3.1] javax.persistence.RollbackException

As mentioned before the LockTimeoutExceptions are expected. Here "updater4" gets the object first and performs an update. "updater2" gets the object next but this appears to be getting the original copy rather than the commited update and ends up in a RollbackException (which makes sense so at least the db will stay consistent).

Code is attached. Apologies if this is something I'm doing wrong but I couldn't spot it...

 

felixobjectdb
felixobjectdb's picture
Joined on 2011-02-10
User Post #54
#4
2011-10-03 13:05

You are right again. Please try build 2.3.1_01. Thanks.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #644

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel