Uploaded image for project: 'Hibernate ORM'
  1. HHH-3628

Hilo optimizer problem in case of multiple threads accessing the sequence table

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.2.6, 5.0.3
    • Fix Version/s: 5.2.10
    • Component/s: None

      Description

      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.

        Attachments

          Activity

            People

            • Votes:
              12 Vote for this issue
              Watchers:
              22 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: