[ 
https://issues.apache.org/jira/browse/OFBIZ-2353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14117609#comment-14117609
 ] 

Jacopo Cappellato commented on OFBIZ-2353:
------------------------------------------

[~adri...@hlmksw.com] this new patch works, thank you.
However the safeGetNextSeqId method that you shared previously didn't work and 
had issues and my comments were referred to it only, not at the algorithm that 
you proposed that is ok.
Your algorithm is good and easy to read: it requires 2 statements + 2 times the 
number of collisions (that can be zero); so the minimum (no collisions) is 2 
statements.
The algorithm that I have committed requires always 3 statements (and there is 
not much between them that can go wrong).

Your algorithm may be slightly more efficient with lower loads but with higher 
load the existing one seems much faster; for what is worth I just tried to 
increase the loop in testSequenceValueItemWithConcurrentThreads to 100000 and 
yours runs in approx 50sec and mine in 6sec.



> 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 09.04, Trunk
>            Reporter: Philippe Mouawad
>            Assignee: Jacopo Cappellato
>            Priority: Critical
>             Fix For: Release Branch 10.04, Upcoming Branch
>
>         Attachments: OFBIZ-2353 SELECT FOR UPDATE solution.patch, OFBIZ-2353 
> SELECT FOR UPDATE solution.patch, OFBIZ-2353-AC.patch
>
>
> 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 was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to