[exo-jcr-commits] exo-jcr SVN: r1361 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/lab/cluster/test and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Jan 12 08:13:22 EST 2010
Author: nzamosenchuk
Date: 2010-01-12 08:13:21 -0500 (Tue, 12 Jan 2010)
New Revision: 1361
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestCacheDeadLockDetection.java
Log:
EXOJCR-371: Completed DeadLockDetectionTest, added some comments and license to BufferedJBossCache.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-01-12 12:39:16 UTC (rev 1360)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-01-12 13:13:21 UTC (rev 1361)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
import org.jboss.cache.Cache;
@@ -21,6 +39,13 @@
import javax.transaction.TransactionManager;
+/**
+ * Decorator over the JBossCache that stores changes in buffer, then sorts and applies to JBossCache.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: BufferedJBossCache.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
@SuppressWarnings("unchecked")
public class BufferedJBossCache implements Cache<Serializable, Object>
{
@@ -513,8 +538,6 @@
/**
* Container for changes
- * @author sj
- *
*/
public static abstract class ChangesContainer implements Comparable<ChangesContainer>
{
@@ -579,8 +602,6 @@
/**
* Put object container;
- * @author sj
- *
*/
public static class PutObjectContainer extends ChangesContainer
{
@@ -603,8 +624,6 @@
/**
* Put container.
- * @author sj
- *
*/
public static class PutKeyValueContainer extends ChangesContainer
{
@@ -629,8 +648,6 @@
/**
* Remove container.
- * @author sj
- *
*/
public static class RemoveKeyContainer extends ChangesContainer
{
@@ -653,8 +670,6 @@
/**
* Remove container.
- * @author sj
- *
*/
public static class RemoveNodeContainer extends ChangesContainer
{
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestCacheDeadLockDetection.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestCacheDeadLockDetection.java 2010-01-12 12:39:16 UTC (rev 1360)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestCacheDeadLockDetection.java 2010-01-12 13:13:21 UTC (rev 1361)
@@ -25,11 +25,25 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
/**
+ * Test that proves BufferedJBossCache as a solution against dead-locks.
+ * Was tested with lockAcquisitionTimeout="10000" (10s).
+ * If ordering is not done in BufferedJBossCache then this test shown TimeOutException
+ * when one thread waits for another one. Like this:
+ *
+ * org.jboss.cache.lock.TimeoutException: Unable to acquire lock on Fqn [/$CHILD_NODES_LIST/2235b1da7f0000014f62cf6a381e342f]
+ * after [10000] milliseconds for requestor [GlobalTransaction:<null>:243]! Lock held by [GlobalTransaction:<null>:244]
+ * org.jboss.cache.lock.TimeoutException: Unable to acquire lock on Fqn [/$CHILD_NODES_LIST/2235b1d67f0000017209d9af66cfae9a]
+ * after [10000] milliseconds for requestor [GlobalTransaction:<null>:244]! Lock held by [GlobalTransaction:<null>:243]
+ *
+ * When running this test you should manually check that this is really a dead-lock when the first thread is waiting for
+ * the second and the second for the first one. (like example when TX243 waits TX244 and contrary)
+ *
* @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
* @version $Id: TestLoadIndexerWriter.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
*
@@ -57,8 +71,10 @@
private int propertyCount = 200;
- private int nodeCount = 100;
+ private int nodeCount = 10;
+ private CountDownLatch latch;
+
public void testWrite() throws RepositoryException
{
log.info("Creating threads...");
@@ -83,6 +99,11 @@
stop = true;
}
+ /**
+ * sleeps for milliseconds.
+ *
+ * @param time
+ */
private void sleep(long time)
{
try
@@ -95,6 +116,23 @@
}
}
+ /**
+ * returns "active" latch if it is not null and not achieved 0.
+ * otherwise returns new latch.
+ * @return
+ */
+ private synchronized CountDownLatch getLatch()
+ {
+ if (latch == null || latch.getCount() == 0)
+ {
+ latch = new CountDownLatch(threadCount);
+ }
+ return latch;
+ }
+
+ /**
+ * This is the runnable task, that performs write to 2 different nodes, but in different contrary order.
+ */
private class WriterTask implements Runnable
{
private int id;
@@ -136,9 +174,19 @@
fillNode(nodeB, index);
fillNode(nodeA, index);
}
+ // session.save() should be synchronized between threads.
+ CountDownLatch latch = getLatch();
+ latch.countDown();
+ try
+ {
+ // when all threads are ready, await will resume the control flow
+ latch.await();
+ }
+ catch (InterruptedException e)
+ {
+ }
sessionLocal.save();
- log.info("#");
- //System.out.print("#");
+ System.out.print("#");
}
}
catch (RepositoryException e)
@@ -151,6 +199,13 @@
}
}
+ /**
+ * Simply adds lots of nodes and properties to the given parent.
+ *
+ * @param node
+ * @param index
+ * @throws RepositoryException
+ */
public void fillNode(Node node, int index) throws RepositoryException
{
for (int n = 0; n < nodeCount; n++)
More information about the exo-jcr-commits
mailing list