[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3628) Hilo optimizer problem in case of multiple threads accessing the sequence table

Tara Simpson (JIRA) noreply at atlassian.com
Wed Dec 3 14:40:15 EST 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3628?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=31867#action_31867 ] 

Tara Simpson commented on HHH-3628:
-----------------------------------

This is not a major issue, it is absolutely critical.

Steve Ebersole has 'highly recommended' (in italics) that one should use the enhanced sequence generators - see http://blog.hibernate.org/Bloggers/Steve.    However, both this and the pooled optimizer strategies do not work in a clustered / multi-jvm'ed environment - and what good is a sequence generator if it cannot be used in more than one JVM. 

Btw,  this bug results in a ConstraintViolationException on the primary key when inserting.  It is easily reproducible on even moderately busy systems. 

> Hilo optimizer problem in case of multiple threads accessing the sequence table
> -------------------------------------------------------------------------------
>
>                 Key: HHH-3628
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3628
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.2.6
>         Environment: Sybase
>            Reporter: Montagnon Cyril
>
> If 2 (or more) threads access the table storing the ids, this optimizer won't work and will try to insert entities with twice the same idea.
> The problem is the way the HiLoOptimizer class generates the id : 
>             public synchronized Serializable generate(AccessCallback callback) {
> 			if ( lastSourceValue < 0 ) {
> 				lastSourceValue = callback.getNextValue();
> 				while ( lastSourceValue <= 0 ) {
> 					lastSourceValue = callback.getNextValue();
> 				}
> 				hiValue = ( lastSourceValue * incrementSize ) + 1;
> 				value = hiValue - incrementSize;
> 			}
> 			else if ( value >= hiValue ) {
> 				lastSourceValue = callback.getNextValue();
> 				hiValue = ( lastSourceValue * incrementSize ) + 1;
> 			}
> 			return make( value++ );
> 		}
> In the 'else if' part, the 'value' variable isn't reaffected, which means the current thread will try to insert entities with an id that has already been used by another thread. The value should be reset with hiValue - incrementSize.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list