You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2005/09/01 14:02:45 UTC

svn commit: r265703 - in /incubator/jackrabbit/trunk/core/src: java/org/apache/jackrabbit/core/state/ItemState.java test/org/apache/jackrabbit/core/ConcurrencyTest.java

Author: stefan
Date: Thu Sep  1 05:02:39 2005
New Revision: 265703

URL: http://svn.apache.org/viewcvs?rev=265703&view=rev
Log:
fixing concurrency issue that could cause incorrect InvalidItemStateExceptions being thrown under heavy load

Modified:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java
    incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/ConcurrencyTest.java

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java?rev=265703&r1=265702&r2=265703&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java Thu Sep  1 05:02:39 2005
@@ -203,6 +203,7 @@
         // prepare this instance so it can be gc'ed
         listeners.clear();
         disconnect();
+        overlayedState = null;
         status = STATUS_UNDEFINED;
     }
 
@@ -211,19 +212,36 @@
      */
     protected void connect(ItemState overlayedState) {
         if (this.overlayedState != null) {
-            throw new IllegalStateException("Item state already connected: " + this);
+            if (this.overlayedState != overlayedState) {
+                throw new IllegalStateException("Item state already connected to another underlying state: " + this);
+            }
         }
         this.overlayedState = overlayedState;
         this.overlayedState.addListener(this);
     }
 
     /**
+     * Reconnect this state to the overlayed state that it has been
+     * disconnected from earlier.
+     */
+    protected void reconnect() {
+        if (this.overlayedState == null) {
+            throw new IllegalStateException("Item state cannot be reconnected because there's no underlying state to reconnect to: " + this);
+        }
+        this.overlayedState.addListener(this);
+    }
+
+    /**
      * Disconnect this state from the underlying overlayed state.
      */
     protected void disconnect() {
         if (overlayedState != null) {
+            // de-register listener on overlayed state...
             overlayedState.removeListener(this);
-            overlayedState = null;
+            // ...but still keep reference to overlayed state to allow
+            // reconnecting at a later stage and to make sure
+            // it is not accidentally collected by the gc
+            //overlayedState = null;
         }
     }
 

Modified: incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/ConcurrencyTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/ConcurrencyTest.java?rev=265703&r1=265702&r2=265703&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/ConcurrencyTest.java (original)
+++ incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/ConcurrencyTest.java Thu Sep  1 05:02:39 2005
@@ -28,7 +28,7 @@
 public class ConcurrencyTest extends AbstractJCRTest {
 
     private static final int NUM_ITERATIONS = 2;
-    private static final int NUM_SESSIONS = 5;
+    private static final int NUM_SESSIONS = 100;
     private static final int NUM_NODES = 100;
 
     final ArrayList exceptions = new ArrayList();
@@ -145,6 +145,7 @@
                 session.save();
             } catch (Exception e) {
                 log.println("Exception while " + state + ": " + e.getMessage());
+                //e.printStackTrace();
                 exceptions.add(e);
             } finally {
                 session.logout();