jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1041379 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version: InternalVersionManagerBase.java InternalVersionManagerImpl.java InternalXAVersionManager.java
Date Thu, 02 Dec 2010 13:58:09 GMT
Author: jukka
Date: Thu Dec  2 13:58:09 2010
New Revision: 1041379

URL: http://svn.apache.org/viewvc?rev=1041379&view=rev
Log:
JCR-2828: InternalVersionManager deadlock

Move the write lock higher up in the call chain to prevent this problem.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java?rev=1041379&r1=1041378&r2=1041379&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
Thu Dec  2 13:58:09 2010
@@ -16,6 +16,10 @@
  */
 package org.apache.jackrabbit.core.version;
 
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_ACTIVITY;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_VERSIONHISTORY;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.MIX_VERSIONABLE;
+
 import java.util.Calendar;
 
 import javax.jcr.ItemNotFoundException;
@@ -554,6 +558,45 @@ abstract class InternalVersionManagerBas
     }
 
     /**
+     * Creates a new version of the given node using the given version
+     * creation time.
+     *
+     * @param node the node to be checked in
+     * @param created version creation time
+     * @return the new version
+     * @throws RepositoryException if an error occurs
+     */
+    protected InternalVersion checkin(NodeStateEx node, Calendar created)
+            throws RepositoryException {
+        WriteOperation operation = startWriteOperation();
+        try {
+            boolean simple =
+                !node.getEffectiveNodeType().includesNodeType(MIX_VERSIONABLE);
+            InternalVersionHistoryImpl vh;
+            if (simple) {
+                // in simple versioning the history id needs to be calculated
+                vh = (InternalVersionHistoryImpl) getVersionHistoryOfNode(
+                        node.getNodeId());
+            } else {
+                // in full versioning, the history id can be retrieved via
+                // the property
+                vh = (InternalVersionHistoryImpl) getVersionHistory(
+                        node.getPropertyValue(JCR_VERSIONHISTORY).getNodeId());
+            }
+
+            InternalVersion version =
+                internalCheckin(vh, node, simple, created);
+
+            operation.save();
+            return version;
+        } catch (ItemStateException e) {
+            throw new RepositoryException(e);
+        } finally {
+            operation.close();
+        }
+    }
+
+    /**
      * Checks in a node
      *
      * @param history the version history
@@ -568,26 +611,19 @@ abstract class InternalVersionManagerBas
             InternalVersionHistoryImpl history,
             NodeStateEx node, boolean simple, Calendar created)
             throws RepositoryException {
-        WriteOperation operation = startWriteOperation();
-        try {
-            String versionName = calculateCheckinVersionName(history, node, simple);
-            InternalVersionImpl v = history.checkin(
-                    NameFactoryImpl.getInstance().create("", versionName),
-                    node, created);
-
-            // check for jcr:activity
-            if (node.hasProperty(NameConstants.JCR_ACTIVITY)) {
-                NodeId actId = node.getPropertyValue(NameConstants.JCR_ACTIVITY).getNodeId();
-                InternalActivityImpl act = (InternalActivityImpl) getItem(actId);
-                act.addVersion(v);
-            }
-            operation.save();
-            return v;
-        } catch (ItemStateException e) {
-            throw new RepositoryException(e);
-        } finally {
-            operation.close();
+        String versionName = calculateCheckinVersionName(history, node, simple);
+        InternalVersionImpl v = history.checkin(
+                NameFactoryImpl.getInstance().create("", versionName),
+                node, created);
+
+        // check for jcr:activity
+        if (node.hasProperty(JCR_ACTIVITY)) {
+            NodeId actId = node.getPropertyValue(JCR_ACTIVITY).getNodeId();
+            InternalActivityImpl act = (InternalActivityImpl) getItem(actId);
+            act.addVersion(v);
         }
+
+        return v;
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerImpl.java?rev=1041379&r1=1041378&r2=1041379&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerImpl.java
Thu Dec  2 13:58:09 2010
@@ -401,26 +401,15 @@ public class InternalVersionManagerImpl 
      * item-reading listeners in the observation thread.
      */
     public InternalVersion checkin(
-            final Session session,
-            final NodeStateEx node, final Calendar created)
+            Session session, final NodeStateEx node, final Calendar created)
             throws RepositoryException {
-        return (InternalVersion)
-                escFactory.doSourced((SessionImpl) session, new SourcedTarget() {
-            public Object run() throws RepositoryException {
-                InternalVersionHistoryImpl vh;
-                if (node.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE))
{
-                    // in full versioning, the history id can be retrieved via
-                    // the property
-                    NodeId histId = node.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
-                    vh = (InternalVersionHistoryImpl) getVersionHistory(histId);
-                    return internalCheckin(vh, node, false, created);
-                } else {
-                    // in simple versioning the history id needs to be calculated
-                    vh = (InternalVersionHistoryImpl) getVersionHistoryOfNode(node.getNodeId());
-                    return internalCheckin(vh, node, true, created);
-                }
-            }
-        });
+        return (InternalVersion) escFactory.doSourced(
+                (SessionImpl) session,
+                new SourcedTarget() {
+                    public Object run() throws RepositoryException {
+                        return checkin(node, created);
+                    }
+                });
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java?rev=1041379&r1=1041378&r2=1041379&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java
Thu Dec  2 13:58:09 2010
@@ -233,20 +233,7 @@ public class InternalXAVersionManager ex
             Session session, NodeStateEx node, Calendar created)
             throws RepositoryException {
         if (isInXA()) {
-            InternalVersionHistoryImpl vh;
-            InternalVersion version;
-            if (node.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE))
{
-                // in full versioning, the history id can be retrieved via
-                // the property
-                NodeId histId = node.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
-                vh = (InternalVersionHistoryImpl) getVersionHistory(histId);
-                version = internalCheckin(vh, node, false, created);
-            } else {
-                // in simple versioning the history id needs to be calculated
-                vh = (InternalVersionHistoryImpl) getVersionHistoryOfNode(node.getNodeId());
-                version = internalCheckin(vh, node, true, created);
-            }
-            return version;
+            return checkin(node, created);
         } else {
             return vMgr.checkin(session, node, created);
         }
@@ -480,6 +467,7 @@ public class InternalXAVersionManager ex
      * <p/>
      * Before modifying version history given, make a local copy of it.
      */
+    @Override
     protected InternalVersion internalCheckin(
             InternalVersionHistoryImpl history,
             NodeStateEx node, boolean simple, Calendar created)



Mime
View raw message