Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333902 - Batch Writing may result in a database/cache deadlock.
Summary: Batch Writing may result in a database/cache deadlock.
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-10 15:03 EST by Gordon Yorke CLA
Modified: 2022-06-09 10:23 EDT (History)
1 user (show)

See Also:


Attachments
Proposed Patch (2.38 KB, patch)
2011-01-11 21:31 EST, Gordon Yorke CLA
no flags Details | Diff
Final Patch (2.66 KB, patch)
2011-01-12 14:51 EST, Gordon Yorke CLA
no flags Details | Diff
Updated patch to support SessionBroker (2.59 KB, patch)
2011-01-13 16:35 EST, Gordon Yorke CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gordon Yorke CLA 2011-01-10 15:03:13 EST
There is a conflict between batch writing and how EclipseLink acquires internal locks on the cache.  If the batch "buffer" has pending writes the "buffer" will not be flushed until after the UOW has attempted to acquire its locks.  The UOW is unaware that there are pending updates before it attempts to acquire the needed locks.

If another thread has locked those same rows that the first thread has not yet locked because of the unflushed buffer and then attempts to acquire cache locks it will have to wait on the first thread.  The first thread with the buffered batch writes will not be able to complete it's txn and release the cache locks because it will not be able to complete the writes to the database.

There are two simple workarounds :
 1) Using a SessionCustomizer in EclipseLink change the cache transaction isolation:

        public void customize(Session session) throws Exception{
            ... // other customizations
            session.getLogin().setCacheTransactionIsolation(DatasourceLogin.SYNCRONIZED_OBJECT_LEVEL_READ_WRITE);
        }

  This will cause EclipseLink to acquire locks only after the transaction has been committed.  This may result in a slight increase in Optimistic Lock occurrences but will continue to maintain data integrity in the cache with out impacting performance.

 2) remove batch writing. However, this is likely to have a major impact on performance.
Comment 1 Gordon Yorke CLA 2011-01-10 15:03:52 EST
The fix is quite simple as well.  The UnitOfWork must ensure that it's BatchWriting buffer is flushed prior to acquiring any cache locks.
Comment 2 Gordon Yorke CLA 2011-01-11 21:31:21 EST
Created attachment 186595 [details]
Proposed Patch

This fix is very simple.  During the UOW Commit before acquiring locks the batch writing mechanism is flushed.
Comment 3 Gordon Yorke CLA 2011-01-12 14:51:41 EST
Created attachment 186663 [details]
Final Patch
Comment 4 Gordon Yorke CLA 2011-01-13 16:35:07 EST
Created attachment 186783 [details]
Updated patch to support SessionBroker
Comment 5 Gordon Yorke CLA 2011-01-13 21:09:18 EST
Patch Checked In
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:23:45 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink