jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r383935 - /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Date Tue, 07 Mar 2006 17:14:43 GMT
Author: dpfister
Date: Tue Mar  7 09:14:42 2006
New Revision: 383935

URL: http://svn.apache.org/viewcvs?rev=383935&view=rev
Log:
JCR-335 Deadlock caused by versioning operations within transaction

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=383935&r1=383934&r2=383935&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Tue Mar  7 09:14:42 2006
@@ -424,6 +424,11 @@
         private EventStateCollection events;
 
         /**
+         * Flag indicating whether we are holding write lock.
+         */
+        private boolean holdingWriteLock;
+
+        /**
          * Create a new instance of this class.
          */
         public Update(ChangeLog local, EventStateCollectionFactory factory,
@@ -454,6 +459,7 @@
             }
 
             acquireWriteLock();
+            holdingWriteLock = true;
 
             boolean succeeded = false;
 
@@ -572,8 +578,6 @@
                 }
             }
 
-            boolean holdingWriteLock = true;
-
             try {
                 /* Let the shared item listeners know about the change */
                 shared.persisted();
@@ -601,6 +605,7 @@
                 if (holdingWriteLock) {
                     // exception occured before downgrading lock
                     rwLock.writeLock().release();
+                    holdingWriteLock = false;
                 } else {
                     rwLock.readLock().release();
                 }
@@ -612,29 +617,35 @@
          * on the item state manager will have been released.
          */
         public void cancel() {
-            local.disconnect();
+            try {
+                local.disconnect();
 
-            for (Iterator iter = shared.modifiedStates(); iter.hasNext();) {
-                ItemState state = (ItemState) iter.next();
-                try {
-                    state.copy(loadItemState(state.getId()));
-                } catch (ItemStateException e) {
-                    state.discard();
+                for (Iterator iter = shared.modifiedStates(); iter.hasNext();) {
+                    ItemState state = (ItemState) iter.next();
+                    try {
+                        state.copy(loadItemState(state.getId()));
+                    } catch (ItemStateException e) {
+                        state.discard();
+                    }
                 }
-            }
-            for (Iterator iter = shared.deletedStates(); iter.hasNext();) {
-                ItemState state = (ItemState) iter.next();
-                try {
-                    state.copy(loadItemState(state.getId()));
-                } catch (ItemStateException e) {
+                for (Iterator iter = shared.deletedStates(); iter.hasNext();) {
+                    ItemState state = (ItemState) iter.next();
+                    try {
+                        state.copy(loadItemState(state.getId()));
+                    } catch (ItemStateException e) {
+                        state.discard();
+                    }
+                }
+                for (Iterator iter = shared.addedStates(); iter.hasNext();) {
+                    ItemState state = (ItemState) iter.next();
                     state.discard();
                 }
+            } finally {
+                if (holdingWriteLock) {
+                    rwLock.writeLock().release();
+                    holdingWriteLock = false;
+                }
             }
-            for (Iterator iter = shared.addedStates(); iter.hasNext();) {
-                ItemState state = (ItemState) iter.next();
-                state.discard();
-            }
-            rwLock.writeLock().release();
         }
     }
 



Mime
View raw message