[
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.