jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r410655 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: TransactionContext.java state/SharedItemStateManager.java version/XAVersionManager.java
Date Wed, 31 May 2006 20:09:23 GMT
Author: tripod
Date: Wed May 31 13:09:22 2006
New Revision: 410655

URL: http://svn.apache.org/viewvc?rev=410655&view=rev
Log:
JCR-447 deadlock on concurrent commit/locking

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransactionContext.java?rev=410655&r1=410654&r2=410655&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
Wed May 31 13:09:22 2006
@@ -135,14 +135,20 @@
         afterOperation();
         status = Status.STATUS_PREPARED;
 
-        Thread rollbackThread = new Thread(this, "RollbackThread");
-        rollbackThread.start();
-
         if (txe != null) {
+            // force immediate rollback on error.
+            try {
+                rollback();
+            } catch (XAException e) {
+                /* ignore */
+            }
             XAException e = new XAException(XAException.XA_RBOTHER);
             e.initCause(txe);
             throw e;
         }
+
+        // start rollback thread in case the commit is never issued
+        new Thread(this, "RollbackThread").start();
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=410655&r1=410654&r2=410655&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Wed May 31 13:09:22 2006
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.core.ItemId;
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.version.XAVersionManager;
 import org.apache.jackrabbit.core.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.core.nodetype.NodeDefId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeConflictException;
@@ -150,6 +151,13 @@
             new VirtualItemStateProvider[0];
 
     /**
+     * special flag for then this manager is used by the version manager and
+     * transactional versioning operations. in this case, deadlocks could occurr
+     * (see issue JCR-447).
+     */
+    private boolean noLockHack = false;
+
+    /**
      * Read-/Write-Lock to synchronize access on this item state manager.
      */
     private final ReadWriteLock rwLock =
@@ -157,10 +165,13 @@
                 /**
                  * Allow reader when there is no active writer, or current
                  * thread owns the write lock (reentrant).
+                 * <p/>
+                 * the 'noLockHack' is only temporary (hopefully)
                  */
                 protected boolean allowReader() {
                     return activeWriter_ == null
-                        || activeWriter_ == Thread.currentThread();
+                        || activeWriter_ == Thread.currentThread()
+                        || noLockHack;
                 }
             };
 
@@ -185,6 +196,16 @@
         if (!hasNonVirtualItemState(rootNodeId)) {
             createRootNodeState(rootNodeId, ntReg);
         }
+    }
+
+    /**
+     * enables or disables the write-lock hack. this should only be called by
+     * the {@link XAVersionManager}.
+     *
+     * @param noLockHack
+     */
+    public void setNoLockHack(boolean noLockHack) {
+        this.noLockHack = noLockHack;
     }
 
     //-----------------------------------------------------< ItemStateManager >

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java?rev=410655&r1=410654&r2=410655&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
Wed May 31 13:09:22 2006
@@ -438,6 +438,7 @@
      * Delegate the call to our XA item state manager.
      */
     public void prepare(TransactionContext tx) throws TransactionException {
+        vMgr.getSharedStateMgr().setNoLockHack(true);
         ((XAItemStateManager) stateMgr).prepare(tx);
     }
 
@@ -449,6 +450,7 @@
      */
     public void commit(TransactionContext tx) throws TransactionException {
         ((XAItemStateManager) stateMgr).commit(tx);
+        vMgr.getSharedStateMgr().setNoLockHack(false);
 
         Map xaItems = (Map) tx.getAttribute(ITEMS_ATTRIBUTE_NAME);
         vMgr.itemsUpdated(xaItems.values());
@@ -461,6 +463,7 @@
      */
     public void rollback(TransactionContext tx) {
         ((XAItemStateManager) stateMgr).rollback(tx);
+        vMgr.getSharedStateMgr().setNoLockHack(false);
     }
 
     /**



Mime
View raw message