You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by "Philippe Mouawad (JIRA)" <ji...@apache.org> on 2009/04/24 18:19:30 UTC

[jira] Created: (OFBIZ-2353) SequenceUtil may generate duplicate IDs in Load Balancing mode

SequenceUtil  may generate duplicate IDs in Load Balancing mode
---------------------------------------------------------------

                 Key: OFBIZ-2353
                 URL: https://issues.apache.org/jira/browse/OFBIZ-2353
             Project: OFBiz
          Issue Type: Bug
          Components: framework
    Affects Versions: Release Branch 4.0, Release Branch 9.04, SVN trunk
            Reporter: Philippe Mouawad
            Priority: Critical


If Ofbiz is deploy on 2 servers in Load Balancing Mode
SequenceUtil will generate duplicate IDs because synchronization is done at JVM level instead of doing it in DB.

A good replacement implementation would be:
org.hibernate.id.enhanced.TableGenerator

But it would involve a dependency on Hibernate

Philippe
www.ubik-ingenierie.com


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OFBIZ-2353) SequenceUtil may generate duplicate IDs in Load Balancing mode

Posted by "Philippe Mouawad (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-2353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12777935#action_12777935 ] 

Philippe Mouawad commented on OFBIZ-2353:
-----------------------------------------

Hello M. Le Roux,
I had no time to handle this issue.
Philippe.

> SequenceUtil  may generate duplicate IDs in Load Balancing mode
> ---------------------------------------------------------------
>
>                 Key: OFBIZ-2353
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2353
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: Release Branch 4.0, Release Branch 9.04, SVN trunk
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> If Ofbiz is deploy on 2 servers in Load Balancing Mode
> SequenceUtil will generate duplicate IDs because synchronization is done at JVM level instead of doing it in DB.
> A good replacement implementation would be:
> org.hibernate.id.enhanced.TableGenerator
> But it would involve a dependency on Hibernate
> Philippe
> www.ubik-ingenierie.com

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OFBIZ-2353) SequenceUtil may generate duplicate IDs in Load Balancing mode

Posted by "Karl Eilebrecht (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-2353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12758697#action_12758697 ] 

Karl Eilebrecht commented on OFBIZ-2353:
----------------------------------------

Hi, 

if you don't like to replace the whole SequenceUtil by some other implementation, you may adapt 
the fillBank-method in SequenceUtil as follows:


if bank empty then fill bank {
suspend TX0;
    int upd = 0;
  do {
    newSequenceMaxValue = lastKnownUsedSequenceValue + bankSize
    begin TX1 {
         upd = executeUpdate("UPDATE SEQUENCE_VALUE_ITEM  SET SEQ_ID = newSequenceMaxValue WHERE SEQ_NAME = 'mySequence' 
                                                     AND SEQ_ID = lastKnownUsedSequenceValue ");
     commit TX1;
     if (upd == 0) {
         begin TX2 {
           lastKnownUsedSequenceValue  = select SEQ_ID from SEQUENCE_VALUE_ITEM where SEQ_NAME = 'mySequence'
         commit TX2;
    
     }
   while upd < 1;
resume TX0;

Now the range from lastKnownUsedSequenceValue (exclusive) to newSequenceMaxValue (inclusive) is safe to be used within the current Ofbiz instance.  It is essential to use different transactions. Otherwise the pattern will not work.

You'll have to integrate the "create sequence if missing"-feature again, but that is no problem, you may test once for existence and memorize locally that the sequence has been created. (However this "convenience feature" is a pain in the ass anyway (typos rule the world) ... ;-) )
 
Regards.
Karl

> SequenceUtil  may generate duplicate IDs in Load Balancing mode
> ---------------------------------------------------------------
>
>                 Key: OFBIZ-2353
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2353
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: Release Branch 4.0, Release Branch 9.04, SVN trunk
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> If Ofbiz is deploy on 2 servers in Load Balancing Mode
> SequenceUtil will generate duplicate IDs because synchronization is done at JVM level instead of doing it in DB.
> A good replacement implementation would be:
> org.hibernate.id.enhanced.TableGenerator
> But it would involve a dependency on Hibernate
> Philippe
> www.ubik-ingenierie.com

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OFBIZ-2353) SequenceUtil may generate duplicate IDs in Load Balancing mode

Posted by "Jacques Le Roux (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-2353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12757818#action_12757818 ] 

Jacques Le Roux commented on OFBIZ-2353:
----------------------------------------

Hi Philippe,

How did you finally manage this issue ?

Thanks

> SequenceUtil  may generate duplicate IDs in Load Balancing mode
> ---------------------------------------------------------------
>
>                 Key: OFBIZ-2353
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2353
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: Release Branch 4.0, Release Branch 9.04, SVN trunk
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> If Ofbiz is deploy on 2 servers in Load Balancing Mode
> SequenceUtil will generate duplicate IDs because synchronization is done at JVM level instead of doing it in DB.
> A good replacement implementation would be:
> org.hibernate.id.enhanced.TableGenerator
> But it would involve a dependency on Hibernate
> Philippe
> www.ubik-ingenierie.com

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OFBIZ-2353) SequenceUtil may generate duplicate IDs in Load Balancing mode

Posted by "Jacques Le Roux (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-2353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790646#action_12790646 ] 

Jacques Le Roux commented on OFBIZ-2353:
----------------------------------------

Thanks Karl, Adrian,

To be revisited...

> SequenceUtil  may generate duplicate IDs in Load Balancing mode
> ---------------------------------------------------------------
>
>                 Key: OFBIZ-2353
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2353
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: Release Branch 4.0, Release Branch 9.04, SVN trunk
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> If Ofbiz is deploy on 2 servers in Load Balancing Mode
> SequenceUtil will generate duplicate IDs because synchronization is done at JVM level instead of doing it in DB.
> A good replacement implementation would be:
> org.hibernate.id.enhanced.TableGenerator
> But it would involve a dependency on Hibernate
> Philippe
> www.ubik-ingenierie.com

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (OFBIZ-2353) SequenceUtil may generate duplicate IDs in Load Balancing mode

Posted by "Adam Heath (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-2353?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Adam Heath reassigned OFBIZ-2353:
---------------------------------

    Assignee: Adam Heath

> SequenceUtil  may generate duplicate IDs in Load Balancing mode
> ---------------------------------------------------------------
>
>                 Key: OFBIZ-2353
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2353
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: Release Branch 4.0, Release Branch 9.04, SVN trunk
>            Reporter: Philippe Mouawad
>            Assignee: Adam Heath
>            Priority: Critical
>
> If Ofbiz is deploy on 2 servers in Load Balancing Mode
> SequenceUtil will generate duplicate IDs because synchronization is done at JVM level instead of doing it in DB.
> A good replacement implementation would be:
> org.hibernate.id.enhanced.TableGenerator
> But it would involve a dependency on Hibernate
> Philippe
> www.ubik-ingenierie.com

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OFBIZ-2353) SequenceUtil may generate duplicate IDs in Load Balancing mode

Posted by "Karl Eilebrecht (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-2353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790187#action_12790187 ] 

Karl Eilebrecht commented on OFBIZ-2353:
----------------------------------------

Hi Jaques,

sorry, we have "developed away" from standard ofbiz long time ago. Means, I'm using a too old version of ofbiz to create patches.

However, the described solution follows the standard pattern "sequence block" and WILL work, I used similar code successfully in different environments.

Regards.
Karl

> SequenceUtil  may generate duplicate IDs in Load Balancing mode
> ---------------------------------------------------------------
>
>                 Key: OFBIZ-2353
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2353
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: Release Branch 4.0, Release Branch 9.04, SVN trunk
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> If Ofbiz is deploy on 2 servers in Load Balancing Mode
> SequenceUtil will generate duplicate IDs because synchronization is done at JVM level instead of doing it in DB.
> A good replacement implementation would be:
> org.hibernate.id.enhanced.TableGenerator
> But it would involve a dependency on Hibernate
> Philippe
> www.ubik-ingenierie.com

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OFBIZ-2353) SequenceUtil may generate duplicate IDs in Load Balancing mode

Posted by "Jacques Le Roux (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-2353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12777941#action_12777941 ] 

Jacques Le Roux commented on OFBIZ-2353:
----------------------------------------

Thanks Philippe,

Karl, have you used this solution in production ? In case it has been well tested could you create a patch ? 

> SequenceUtil  may generate duplicate IDs in Load Balancing mode
> ---------------------------------------------------------------
>
>                 Key: OFBIZ-2353
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2353
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: Release Branch 4.0, Release Branch 9.04, SVN trunk
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> If Ofbiz is deploy on 2 servers in Load Balancing Mode
> SequenceUtil will generate duplicate IDs because synchronization is done at JVM level instead of doing it in DB.
> A good replacement implementation would be:
> org.hibernate.id.enhanced.TableGenerator
> But it would involve a dependency on Hibernate
> Philippe
> www.ubik-ingenierie.com

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OFBIZ-2353) SequenceUtil may generate duplicate IDs in Load Balancing mode

Posted by "Adrian Crum (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-2353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790219#action_12790219 ] 

Adrian Crum commented on OFBIZ-2353:
------------------------------------

In addition to the issue reported here, SequenceUtil will return duplicate IDs in a heavily multi-threaded single instance. I confirmed this while testing my multi-threaded demo data loading code. The synchronization used in the class is not well thought out.


> SequenceUtil  may generate duplicate IDs in Load Balancing mode
> ---------------------------------------------------------------
>
>                 Key: OFBIZ-2353
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2353
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: Release Branch 4.0, Release Branch 9.04, SVN trunk
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> If Ofbiz is deploy on 2 servers in Load Balancing Mode
> SequenceUtil will generate duplicate IDs because synchronization is done at JVM level instead of doing it in DB.
> A good replacement implementation would be:
> org.hibernate.id.enhanced.TableGenerator
> But it would involve a dependency on Hibernate
> Philippe
> www.ubik-ingenierie.com

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.