Author: bpapez
Date: Thu Jun 14 08:54:41 2007
New Revision: 17555
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17555&repname=
=3Djahia
Log:
* Prevent that IDGeneratorDao returns the same ID twice
* Use newest JBossCache release (needed locking API)
* upgrade some other libraries to newer versions (like in Jahia 4.2)
Modified:
branches/JAHIA-5-0-SP-BRANCH/core/project.xml
branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/dao/IDGe=
neratorDAO.java
branches/JAHIA-5-0-SP-BRANCH/core/src/scripts/jahia.bat
branches/JAHIA-5-0-SP-BRANCH/core/src/scripts/jahia.sh
Modified: branches/JAHIA-5-0-SP-BRANCH/core/project.xml
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/project.xml&rev=3D17555&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/project.xml (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/project.xml Thu Jun 14 08:54:41 2007
@@ -1,4 +1,4 @@
-<?xml version=3D"1.0" encoding=3D"UTF-8"?>
+=C3=AF=C2=BB=C2=BF<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<!DOCTYPE project [
<!ENTITY % locator-entities SYSTEM "file:locator.ent"> %locator-entiti=
es;
]>
@@ -139,7 +139,7 @@
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
- <version>1.2.1</version>
+ <version>1.2.2</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
@@ -155,7 +155,7 @@
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
- <version>1.5</version>
+ <version>1.6</version>
<properties>
<war.bundle>true</war.bundle>
<!-- ktlili: clipbuilder
@@ -175,7 +175,7 @@
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
- <version>2.0</version>
+ <version>2.0.1</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
@@ -197,14 +197,22 @@
<dependency>
<groupId>commons-jexl</groupId>
<artifactId>commons-jexl</artifactId>
- <version>1.0-beta-1</version>
+ <version>1.1</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
</dependency>
<dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
+ </dependency> =
+ <dependency>
<id>commons-logging</id>
- <version>1.0.3</version>
+ <version>1.1</version>
<properties>
<war.bundle>true</war.bundle>
<!-- ktlili: clipbuilder
@@ -222,24 +230,16 @@
</properties>
</dependency>
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.1</version>
- <properties>
- <war.bundle>true</war.bundle>
- </properties>
- </dependency>
- <dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
- <version>1.2</version>
+ <version>1.3</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
</dependency>
<dependency>
<id>commons-transaction</id>
- <version>1.1.1pre1</version>
+ <version>1.2</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
@@ -330,7 +330,6 @@
<war.bundle>true</war.bundle>
</properties>
</dependency>
-
<dependency>
<groupId>imagej</groupId>
<artifactId>imagej</artifactId>
@@ -410,7 +409,7 @@
<dependency>
<groupId>jgroups</groupId>
<artifactId>jgroups-all</artifactId>
- <version>2.3-beta</version>
+ <version>2.4.1</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
@@ -477,7 +476,7 @@
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
- <version>1.2.8</version>
+ <version>1.2.14</version>
<properties>
<war.bundle>true</war.bundle>
<!-- ktlili: clipbuilder
@@ -799,7 +798,7 @@
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
- <version>1.0.4</version>
+ <version>1.1.2</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
@@ -1392,7 +1391,7 @@
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-cache</artifactId>
- <version>1.2.4</version>
+ <version>1.4.1.SP3</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
@@ -1466,7 +1465,7 @@
<war.bundle>true</war.bundle>
</properties>
</dependency>
- <dependency>
+ <dependency>
<groupId>zimbra</groupId>
<artifactId>zimbra-tools</artifactId>
<version>3.1</version>
@@ -1537,7 +1536,7 @@
</properties>
</dependency>
<!-- End of dependencies for JAMon monitoring library -->
- =
+
<!--to generate taglib documentation-->
<dependency>
<groupId>maven-taglib</groupId>
@@ -1559,7 +1558,7 @@
</properties>
</dependency>
<!--END to generate taglib documentation-->
- =
+
</dependencies>
=
<build>
Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/da=
o/IDGeneratorDAO.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/hibernate/dao/IDGeneratorDAO.java&rev=3D175=
55&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/dao/IDGe=
neratorDAO.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/dao/IDGe=
neratorDAO.java Thu Jun 14 08:54:41 2007
@@ -17,8 +17,12 @@
*/package org.jahia.hibernate.dao;
=
import org.jahia.exceptions.JahiaException;
+import org.jboss.cache.DataNode;
+import org.jboss.cache.Node;
+import org.jboss.cache.ReplicationException;
import org.jboss.cache.TreeCache;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.lock.TimeoutException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.hibernate.Hibernate;
import org.hibernate.Session;
@@ -28,21 +32,32 @@
import java.util.HashMap;
=
/**
- * User: Serge Huber
- * Date: 3 nov. 2005
- * Time: 17:41:09
- * Copyright (C) Jahia Inc.
+ * User: Serge Huber Date: 3 nov. 2005 Time: 17:41:09 Copyright (C) Jahia =
Inc.
*/
public class IDGeneratorDAO extends HibernateDaoSupport {
=
+ int lockAcquisitionRetryCount;
+
+ long lockAcquisitionTimeout;
+
+ private final static String CACHE_ENTRY_KEY =3D "entryKey";
+
TreeCache cache;
+
Map dbSequences;
+
Map simpleSequences;
+
String clusterName;
+
String clusterProperties;
+
long maxLo =3D 100;
+
Map lowCounters =3D new HashMap();
+
Map highCounters =3D new HashMap();
+
boolean clusterActivated =3D false;
=
public synchronized Long getNextLong(String sequenceName) throws Excep=
tion {
@@ -60,29 +75,75 @@
}
long highCounter =3D highCounterLong.longValue();
if (lowCounter >=3D maxLo) {
- Long newValue =3D (Long) cache.get("/idgenerators", sequenceNa=
me);
- if (newValue !=3D null) {
- newValue =3D new Long(newValue.longValue() + maxLo);
+ Long newValue =3D null;
+ int retryCounter =3D lockAcquisitionRetryCount;
+ boolean success =3D false;
+
+ do {
+ Node node =3D null;
+ Long oldValue =3D null;
+ boolean acquired =3D false;
try {
- cache.put("/idgenerators", sequenceName, newValue);
- } catch (org.jboss.cache.ReplicationException re) {
- logger.warn("Error while replicating last used high va=
lue " + newValue + ", cluster nodes may have crashed or unreacheable" , re);
+ node =3D cache.get("/idgenerators/" + sequenceName);
+ if (node.acquire(Thread.currentThread(), cache
+ .getLockAcquisitionTimeout(),
+ DataNode.LOCK_TYPE_WRITE)) {
+ acquired =3D true;
+ oldValue =3D (Long) cache.get("/idgenerators/"
+ + sequenceName, CACHE_ENTRY_KEY);
+ if (oldValue !=3D null) {
+ newValue =3D new Long(((Long) oldValue).longVa=
lue()
+ + maxLo);
+ oldValue =3D (Long) cache.put("/idgenerators/"
+ + sequenceName, CACHE_ENTRY_KEY, newVa=
lue);
+ if (!newValue.equals(oldValue)) {
+ lowCounter =3D 0;
+ highCounter =3D newValue.longValue();
+ highCounters.put(sequenceName, new Long(
+ highCounter));
+
+ success =3D true;
+ }
+ }
+ }
+ } catch (TimeoutException rep) {
+ logger.error("Timeout while updating last used high va=
lue "
+ + newValue, rep);
+ } catch (ReplicationException rep) {
+ logger.error("Error while replicating last used high v=
alue "
+ + newValue
+ + ", cluster nodes may have crashed or unreach=
eable",
+ rep);
+ } finally {
+ if (acquired)
+ node.release(Thread.currentThread());
}
- lowCounter =3D 0;
- highCounter =3D newValue.longValue();
- highCounters.put(sequenceName, new Long(highCounter));
+ retryCounter--;
+ } while (retryCounter >=3D 0 && !success);
+
+ if (retryCounter =3D=3D 0) {
+ throw new JahiaException(
+ "ID incrementor service does not work",
+ "Acquire idgenerators cache timed out",
+ JahiaException.CACHE_ERROR,
+ JahiaException.CRITICAL_SEVERITY);
}
+
lowCounters.put(sequenceName, new Long(lowCounter));
- logger.debug("Returning new ID=3D" + newValue + " for sequence=
" + sequenceName);
+ logger.debug("Returning new ID=3D" + newValue + " for sequence=
"
+ + sequenceName);
return newValue;
} else {
lowCounters.put(sequenceName, new Long(lowCounter));
- logger.debug("Returning new ID=3D" + new Long(highCounter + lo=
wCounter) + " for sequence " + sequenceName);
+ logger.debug("Returning new ID=3D"
+ + new Long(highCounter + lowCounter) + " for sequence "
+ + sequenceName);
return new Long(highCounter + lowCounter);
}
}
=
- public synchronized Integer getNextInteger(String sequenceName) throws=
Exception {
+ public synchronized Integer getNextInteger(String sequenceName)
+ throws Exception {
Long result =3D getNextLong(sequenceName);
if (result =3D=3D null) {
return null;
@@ -106,50 +167,68 @@
=
// ok cache is alive, we must now initialize all the generators wi=
th the
// appropriate default values.
- Session session =3D getSession();
- Iterator dbSequencesIter =3D dbSequences.entrySet().iterator();
- while (dbSequencesIter.hasNext()) {
- Map.Entry curEntry =3D (Map.Entry) dbSequencesIter.next();
- String sequenceName =3D (String) curEntry.getKey();
- String fqnID =3D (String) curEntry.getValue();
-
- int separatorPos =3D fqnID.indexOf(".");
- String tableName =3D fqnID.substring(0, separatorPos);
- String columnName =3D fqnID.substring(separatorPos+1);
-
- long initialHighValue;
- long initialLowValue;
-
- Long curClusterHighValue =3D (Long) cache.get("/idgenerators",=
sequenceName);
- if (curClusterHighValue =3D=3D null) {
- // not found in cluster cache, let's initialize.
- // @todo add code to perform SELECT MAX() query on database
- Long maxValue =3D (Long) session.createSQLQuery("SELECT MA=
X("+columnName+") as maxValue FROM " + tableName).addScalar("maxValue", Hib=
ernate.LONG).uniqueResult();
- initialHighValue =3D 0;
- initialLowValue =3D 0;
- if (maxValue =3D=3D null) {
- maxValue =3D new Long(0);
+ Session session =3D null;
+ try {
+ session =3D getSession();
+
+ Iterator dbSequencesIter =3D dbSequences.entrySet().iterator();
+ while (dbSequencesIter.hasNext()) {
+ Map.Entry curEntry =3D (Map.Entry) dbSequencesIter.next();
+ String sequenceName =3D (String) curEntry.getKey();
+ String fqnID =3D (String) curEntry.getValue();
+
+ int separatorPos =3D fqnID.indexOf(".");
+ String tableName =3D fqnID.substring(0, separatorPos);
+ String columnName =3D fqnID.substring(separatorPos + 1);
+
+ long initialHighValue;
+ long initialLowValue;
+
+ Long curClusterHighValue =3D (Long) cache.get("/idgenerato=
rs/"
+ + sequenceName, CACHE_ENTRY_KEY);
+ if (curClusterHighValue =3D=3D null) {
+ // not found in cluster cache, let's initialize.
+ // @todo add code to perform SELECT MAX() query on dat=
abase
+ Long maxValue =3D (Long) session.createSQLQuery(
+ "SELECT MAX(" + columnName + ") as maxValue FR=
OM "
+ + tableName).addScalar("maxValue",
+ Hibernate.LONG).uniqueResult();
+ initialHighValue =3D 0;
+ initialLowValue =3D 0;
+ if (maxValue =3D=3D null) {
+ maxValue =3D new Long(0);
+ } else {
+ initialHighValue =3D ((maxValue.longValue() / maxL=
o))
+ * maxLo;
+ initialLowValue =3D maxValue.longValue() % maxLo;
+ lowCounters
+ .put(sequenceName, new Long(initialLowValu=
e));
+ }
+ highCounters.put(sequenceName, new Long(initialHighVal=
ue));
+ logger.debug("Sequence " + sequenceName
+ + " initial values : low=3D" + initialLowValue
+ + " high=3D" + initialHighValue);
+ try {
+ cache.put("/idgenerators/" + sequenceName,
+ CACHE_ENTRY_KEY, new Long(initialHighValue=
));
+ } catch (org.jboss.cache.ReplicationException re) {
+ logger
+ .warn(
+ "Error while replicating last used=
high value "
+ + initialHighValue
+ + ", cluster nodes may hav=
e crashed or unreacheable",
+ re);
+ }
} else {
- initialHighValue =3D ((maxValue.longValue() / maxLo)) =
* maxLo;
- initialLowValue =3D maxValue.longValue() % maxLo;
+ initialLowValue =3D maxLo; // force high increment on =
first retrieval.
+ highCounters.put(sequenceName, curClusterHighValue);
lowCounters.put(sequenceName, new Long(initialLowValue=
));
}
- highCounters.put(sequenceName, new Long(initialHighValue));
- logger.debug("Sequence "+sequenceName+" initial values : l=
ow=3D" + initialLowValue +
- " high=3D" + initialHighValue );
- try {
- cache.put("/idgenerators", sequenceName, new Long(init=
ialHighValue));
- } catch (org.jboss.cache.ReplicationException re) {
- logger.warn("Error while replicating last used high va=
lue " + initialHighValue + ", cluster nodes may have crashed or unreacheabl=
e" , re);
- }
- } else {
- initialLowValue =3D maxLo; // force high increment on firs=
t retrieval.
- highCounters.put(sequenceName, curClusterHighValue);
- lowCounters.put(sequenceName, new Long(initialLowValue));
}
+ session.flush();
+ } finally {
+ releaseSession(session);
}
- session.flush();
- releaseSession(session);
}
=
public void stop() throws JahiaException {
@@ -204,4 +283,20 @@
public void setClusterActivated(boolean clusterActivated) {
this.clusterActivated =3D clusterActivated;
}
+
+ public long getLockAcquisitionTimeout() {
+ return lockAcquisitionTimeout;
+ }
+
+ public void setLockAcquisitionTimeout(long lockAcquisitionTimeout) {
+ this.lockAcquisitionTimeout =3D lockAcquisitionTimeout;
+ }
+
+ public int getLockAcquisitionRetryCount() {
+ return lockAcquisitionRetryCount;
+ }
+
+ public void setLockAcquisitionRetryCount(int lockAcquisitionRetryCount=
) {
+ this.lockAcquisitionRetryCount =3D lockAcquisitionRetryCount;
+ }
}
Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/scripts/jahia.bat
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/scripts/jahia.bat&rev=3D17555&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/scripts/jahia.bat (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/scripts/jahia.bat Thu Jun 14 08:5=
4:41 2007
@@ -35,7 +35,7 @@
:skipjikes
cd ..\bin
cd ..\tomcat\webapps\jahia
-java -classpath "%CLASSPATH%;.\;.\WEB-INF\lib\jahia-5.0-SNAPSHOT.jar;.\WEB=
-INF\lib\log4j-1.2.8.jar" org.jahia.init.TomcatWait
+java -classpath "%CLASSPATH%;.\;.\WEB-INF\lib\jahia-5.0-SNAPSHOT.jar;.\WEB=
-INF\lib\log4j-1.2.14.jar" org.jahia.init.TomcatWait
cd ..\..\..\bin
echo Starting browser...
start http://localhost:8080/jahia/html/startup/loadingjahia.html
Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/scripts/jahia.sh
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/scripts/jahia.sh&rev=3D17555&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/scripts/jahia.sh (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/scripts/jahia.sh Thu Jun 14 08:54=
:41 2007
@@ -53,8 +53,8 @@
cd ../bin
#echo Started. Waiting for browser startup...
#cd ../tomcat/webapps/jahia
-##java -classpath $CLASSPATH:./:./WEB-INF/lib/jahia-5.0-SNAPSHOT.jar:../..=
/shared/lib/log4j-1.2.8.jar org.jahia.init.TomcatWait http://localhost:8080=
/jahia/html/startup/startjahia.html
-#java -classpath "$CLASSPATH:./:./WEB-INF/lib/jahia-5.0-SNAPSHOT.jar:./WEB=
-INF/lib/log4j-1.2.8.jar" org.jahia.init.TomcatWait
+##java -classpath $CLASSPATH:./:./WEB-INF/lib/jahia-5.0-SNAPSHOT.jar:../..=
/shared/lib/log4j-1.2.14.jar org.jahia.init.TomcatWait http://localhost:808=
0/jahia/html/startup/startjahia.html
+#java -classpath "$CLASSPATH:./:./WEB-INF/lib/jahia-5.0-SNAPSHOT.jar:./WEB=
-INF/lib/log4j-1.2.14.jar" org.jahia.init.TomcatWait
#cd ../../../bin
#MOZILLAPATH=3D`which mozilla`
#if [ -x $MOZILLAPATH ] ; then
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list