Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 333902

Summary: Batch Writing may result in a database/cache deadlock.
Product: z_Archived Reporter: Gordon Yorke <gordon.yorke>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: eclipselink.foundation-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed Patch
none
Final Patch
none
Updated patch to support SessionBroker none

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