You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2007/04/27 18:01:35 UTC
svn commit: r533152 - in /jackrabbit/trunk/jackrabbit-core/src:
main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
test/java/org/apache/jackrabbit/core/ConcurrentVersioningTest.java
Author: mreutegg
Date: Fri Apr 27 09:01:34 2007
New Revision: 533152
URL: http://svn.apache.org/viewvc?view=rev&rev=533152
Log:
JCR-672: Deadlock on concurrent save/checkin operations possible
Added:
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningTest.java (with props)
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?view=diff&rev=533152&r1=533151&r2=533152
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java Fri Apr 27 09:01:34 2007
@@ -701,6 +701,11 @@
/* Let the shared item listeners know about the change */
shared.persisted();
+ // downgrade to read lock
+ acquireReadLock();
+ rwLock.writeLock().release();
+ holdingWriteLock = false;
+
/* notify virtual providers about node references */
for (int i = 0; i < virtualNodeReferences.length; i++) {
List virtualRefs = virtualNodeReferences[i];
@@ -711,11 +716,6 @@
}
}
}
-
- // downgrade to read lock
- acquireReadLock();
- rwLock.writeLock().release();
- holdingWriteLock = false;
/* dispatch the events */
events.dispatch();
Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningTest.java?view=auto&rev=533152
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningTest.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningTest.java Fri Apr 27 09:01:34 2007
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Node;
+
+/**
+ * <code>ConcurrentVersioningTest</code> contains test cases that run version
+ * operations with concurrent threads.
+ */
+public class ConcurrentVersioningTest extends AbstractJCRTest {
+
+ /**
+ * The number of threads.
+ */
+ private static final int CONCURRENCY = 10;
+
+ /**
+ * The total number of operations to execute. E.g. number of checkins
+ * performed by the threads.
+ */
+ private static final int NUM_OPERATIONS = 100;
+
+ public void testConcurrentAddVersionable() throws RepositoryException {
+ runTask(new Task() {
+ public void execute(Session session, Node test) throws RepositoryException {
+ try {
+ // add versionable nodes
+ for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
+ Node n = test.addNode("test" + i);
+ n.addMixin(mixVersionable);
+ session.save();
+ }
+ } finally {
+ session.logout();
+ }
+ }
+ }, CONCURRENCY);
+ }
+
+ public void testConcurrentCheckin() throws RepositoryException {
+ runTask(new Task() {
+ public void execute(Session session, Node test) throws RepositoryException {
+ try {
+ Node n = test.addNode("test");
+ n.addMixin(mixVersionable);
+ session.save();
+ for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
+ n.checkout();
+ n.checkin();
+ }
+ n.checkout();
+ } finally {
+ session.logout();
+ }
+ }
+ }, CONCURRENCY);
+ }
+
+ public void testConcurrentCreateAndCheckinCheckout() throws RepositoryException {
+ runTask(new Task() {
+ public void execute(Session session, Node test) throws RepositoryException {
+ try {
+ // add versionable nodes
+ for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
+ Node n = test.addNode("test" + i);
+ n.addMixin(mixVersionable);
+ session.save();
+ n.checkout();
+ n.checkin();
+ n.checkout();
+ }
+ } finally {
+ session.logout();
+ }
+ }
+ }, CONCURRENCY);
+ }
+
+ //----------------------------< internal >----------------------------------
+
+ private void runTask(Task task, int concurrency) throws RepositoryException {
+ Thread[] threads = new Thread[concurrency];
+ for (int i = 0; i < concurrency; i++) {
+ Session s = helper.getSuperuserSession();
+ Node test = s.getRootNode().addNode(testPath + "/node" + i);
+ s.save();
+ threads[i] = new Thread(new Executor(s, test, task));
+ }
+ for (int i = 0; i < threads.length; i++) {
+ threads[i].start();
+ }
+ for (int i = 0; i < threads.length; i++) {
+ try {
+ threads[i].join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public interface Task {
+
+ public abstract void execute(Session session, Node test)
+ throws RepositoryException;
+ }
+
+ private static class Executor implements Runnable {
+
+ protected final Session session;
+
+ protected final Node test;
+
+ protected final Task task;
+
+ public Executor(Session session, Node test, Task task) {
+ this.session = session;
+ this.test = test;
+ this.task = task;
+ }
+
+ public void run() {
+ try {
+ task.execute(session, test);
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningTest.java
------------------------------------------------------------------------------
svn:eol-style = native