Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 57051 invoked from network); 5 Sep 2003 22:07:11 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 5 Sep 2003 22:07:11 -0000 Received: (qmail 55552 invoked by uid 500); 5 Sep 2003 22:06:52 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 55528 invoked by uid 500); 5 Sep 2003 22:06:52 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 55516 invoked by uid 500); 5 Sep 2003 22:06:52 -0000 Received: (qmail 55504 invoked from network); 5 Sep 2003 22:06:51 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 5 Sep 2003 22:06:51 -0000 Received: (qmail 57020 invoked by uid 1510); 5 Sep 2003 22:06:59 -0000 Date: 5 Sep 2003 22:06:59 -0000 Message-ID: <20030905220659.57019.qmail@minotaur.apache.org> From: arminw@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/sequence SequenceManagerHighLowImpl.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N arminw 2003/09/05 15:06:59 Modified: . release-notes.txt xdocs sequencemanager.xml src/java/org/apache/ojb/broker/util/sequence SequenceManagerHighLowImpl.java Log: rollback to previous version, I can't get a grip on new version (deadlock problem) Revision Changes Path 1.22 +0 -6 db-ojb/release-notes.txt Index: release-notes.txt =================================================================== RCS file: /home/cvs/db-ojb/release-notes.txt,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- release-notes.txt 3 Sep 2003 18:52:59 -0000 1.21 +++ release-notes.txt 5 Sep 2003 22:06:59 -0000 1.22 @@ -31,13 +31,7 @@ to make additional proprietary methods available for user by casting org.odmg.Transaction to TransactionExt -- SequenceManagerHighLowImpl now can be used in managed environments -too - BUG FIXES: - -- Fixed. Under heavy multithreaded load SequenceManagerHighLowImpl -blocked application and induce PB-pool throw an timeout exception. Please refer to our Bug tracking site under http://scarab.werken.com/scarab/issues/id/OJBxxx to see details for a bug 1.15 +5 -1 db-ojb/xdocs/sequencemanager.xml Index: sequencemanager.xml =================================================================== RCS file: /home/cvs/db-ojb/xdocs/sequencemanager.xml,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- sequencemanager.xml 3 Sep 2003 18:51:35 -0000 1.14 +++ sequencemanager.xml 5 Sep 2003 22:06:59 -0000 1.15 @@ -234,7 +234,11 @@

Limitations: -
- superfluously to mention, do not use if database will be updated by other applications +
- do not use in managed environments when connections were enlisted +in running transactions, e.g. when using DataSources of an application server +
- if set connection-pool attribute 'whenExhaustedAction' to 'block' (wait for +connection), under heavy load the this SM could block application. +
- superfluously to mention, do not use if other applications insert objects


1.22 +54 -61 db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java Index: SequenceManagerHighLowImpl.java =================================================================== RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- SequenceManagerHighLowImpl.java 3 Sep 2003 18:45:29 -0000 1.21 +++ SequenceManagerHighLowImpl.java 5 Sep 2003 22:06:59 -0000 1.22 @@ -55,8 +55,9 @@ */ import org.apache.commons.lang.SystemUtils; -import org.apache.ojb.broker.OptimisticLockException; import org.apache.ojb.broker.PersistenceBroker; +import org.apache.ojb.broker.PersistenceBrokerFactory; +import org.apache.ojb.broker.OptimisticLockException; import org.apache.ojb.broker.metadata.FieldDescriptor; import org.apache.ojb.broker.query.Criteria; import org.apache.ojb.broker.query.Query; @@ -120,9 +121,9 @@ *

* Limitations: *

    - *
  • Do NOT use this implementation in j2ee environment or + *
  • Do NOT use this implementation in managed environment or * any comparable system where any connection was associated - * with the running tx.
  • + * with the running transaction. *
*

* @@ -150,13 +151,12 @@ public static final String PROPERTY_GLOBAL_SEQUENCE_START = "globalSequenceStart"; - private static Map sequencesMap = new HashMap(); - private static int attempts; + protected static Map sequencesMap = new HashMap(); protected boolean useGlobalSequenceIdentities; protected int grabSize; protected long globalSequenceStart; - + protected int attempts; public SequenceManagerHighLowImpl(PersistenceBroker broker) { @@ -212,22 +212,43 @@ SystemUtils.LINE_SEPARATOR + "PB: " + getBrokerForClass()); } } - return id; } } - private HighLowSequence getSequence(PersistenceBroker brokerForSequence, + protected HighLowSequence getSequence(PersistenceBroker brokerForSequence, FieldDescriptor field, String sequenceName) { HighLowSequence newSequence = null; + PersistenceBroker internBroker = null; try { - Query q = buildQuery(sequenceName, field); + Criteria c = new Criteria(); + c.addLike("tableName", sequenceName); + if (useGlobalSequenceIdentities) + { + c.addLike("fieldName", PROPERTY_GLOBAL_SEQUENCE_ID); + } + else + { + c.addLike("fieldName", field.getColumnName()); + } + Query q = new QueryByCriteria(HighLowSequence.class, c); + /* + arminw: + we use a new internBroker instance, because we run into problems + when current internBroker was rollback, then we have new sequence + in memory, but not in database and a concurrent thread will + get the same sequence. + Thus we use a new internBroker instance (with new connection) to + avoid this problem. + */ + internBroker = PersistenceBrokerFactory.createPersistenceBroker(brokerForSequence.getPBKey()); + internBroker.beginTransaction(); // first we lookup sequence object in database - newSequence = (HighLowSequence) brokerForSequence.getObjectByQuery(q); + newSequence = (HighLowSequence) internBroker.getObjectByQuery(q); //not in db --> we have to store a new sequence if (newSequence == null) @@ -245,6 +266,8 @@ } //set current grab size newSequence.setGrabSize(grabSize); + //use copy to avoid sync problems!! + // newSequence = newSequence.getCopy(); //grab the next key scope newSequence.grabNextKeySet(); @@ -252,58 +275,43 @@ //store the sequence to db try { - // brokerForSequence.store(newSequence); - newSequence = storeSequence(brokerForSequence, newSequence); + /* + arminw: + remove object from cache to avoid problems when same + objects where used with different databases. Currently + Identity does not difference between databases, thus + we can found an object in cache although it is not + in the second database, it was used in the first database. + If we not remove it PB try to update instead of insert. + TODO: Find a better solution + */ + internBroker.removeFromCache(newSequence); + internBroker.store(newSequence); } catch (OptimisticLockException e) { // we try five times to get a new sequence - if (attempts < 5) + if(attempts < 5) { - log.info("OptimisticLockException was thrown, will try again to store sequence. Sequence was " + newSequence); + log.info("OptimisticLockException was thrown, will try again to store sequence. Sequence was "+newSequence); attempts++; getSequence(brokerForSequence, field, sequenceName); } - else - throw e; + else throw e; } + internBroker.commitTransaction(); + if (log.isDebugEnabled()) log.debug("new sequence was " + newSequence); } finally { attempts = 0; + if (internBroker != null) internBroker.close(); } return newSequence; } - private HighLowSequence storeSequence( - PersistenceBroker brokerForSequence, - HighLowSequence newSequence) throws OptimisticLockException - { - try - { - /* - arminw: - remove object from cache to avoid problems when same - objects where used with different databases. Currently - Identity does not difference between databases, thus - e.g. we could found an object in cache although it is not - in the second database, it was used in the first database. - If we not remove it, PB try to update instead of insert. - TODO: Find a better solution - */ - brokerForSequence.removeFromCache(newSequence); - brokerForSequence.store(newSequence); - } - catch (OptimisticLockException e) - { - throw e; - } - - return newSequence; - } - - private HighLowSequence newSequenceObject(String sequenceName, + protected HighLowSequence newSequenceObject(String sequenceName, FieldDescriptor field) { HighLowSequence seq = new HighLowSequence(); @@ -320,8 +328,8 @@ return seq; } - private long getMaxKeyForSequence(PersistenceBroker broker, - FieldDescriptor field) + protected long getMaxKeyForSequence(PersistenceBroker broker, + FieldDescriptor field) { long maxKey = 0; if (useGlobalSequenceIdentities) @@ -336,20 +344,5 @@ maxKey = SequenceManagerHelper.getMaxForExtent(broker, field); } return maxKey; - } - - private Query buildQuery(String sequenceName, FieldDescriptor field) - { - Criteria c = new Criteria(); - c.addLike("tableName", sequenceName); - if (useGlobalSequenceIdentities) - { - c.addLike("fieldName", PROPERTY_GLOBAL_SEQUENCE_ID); - } - else - { - c.addLike("fieldName", field.getColumnName()); - } - return new QueryByCriteria(HighLowSequence.class, c); } } --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org