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/08/26 17:34:23 UTC

svn commit: r240263 - in /incubator/jackrabbit/trunk/core/src: java/org/apache/jackrabbit/core/ java/org/apache/jackrabbit/core/state/ test/org/apache/jackrabbit/core/

Author: stefan
Date: Fri Aug 26 08:34:15 2005
New Revision: 240263

URL: http://svn.apache.org/viewcvs?rev=240263&view=rev
Log:
fixing concurrency issue that could lead to inconsistent repository content

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

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/NodeImpl.java?rev=240263&r1=240262&r2=240263&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/NodeImpl.java Fri Aug 26 08:34:15 2005
@@ -897,20 +897,24 @@
             // this node is 'new'
             persistentState = stateMgr.createNew(transientState);
         }
-        // copy state from transient state:
-        // parent uuid's
-        persistentState.setParentUUID(transientState.getParentUUID());
-        // mixin types
-        persistentState.setMixinTypeNames(transientState.getMixinTypeNames());
-        // id of definition
-        persistentState.setDefinitionId(transientState.getDefinitionId());
-        // child node entries
-        persistentState.setChildNodeEntries(transientState.getChildNodeEntries());
-        // property entries
-        persistentState.setPropertyNames(transientState.getPropertyNames());
 
-        // make state persistent
-        stateMgr.store(persistentState);
+        synchronized (persistentState) {
+            // copy state from transient state:
+            // parent uuid's
+            persistentState.setParentUUID(transientState.getParentUUID());
+            // mixin types
+            persistentState.setMixinTypeNames(transientState.getMixinTypeNames());
+            // id of definition
+            persistentState.setDefinitionId(transientState.getDefinitionId());
+            // child node entries
+            persistentState.setChildNodeEntries(transientState.getChildNodeEntries());
+            // property entries
+            persistentState.setPropertyNames(transientState.getPropertyNames());
+
+            // make state persistent
+            stateMgr.store(persistentState);
+        }
+
         // remove listener from transient state
         transientState.removeListener(this);
         // add listener to persistent state

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=240263&r1=240262&r2=240263&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/PropertyImpl.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/PropertyImpl.java Fri Aug 26 08:34:15 2005
@@ -110,13 +110,17 @@
             // this property is 'new'
             persistentState = stateMgr.createNew(transientState);
         }
-        // copy state from transient state
-        persistentState.setDefinitionId(transientState.getDefinitionId());
-        persistentState.setType(transientState.getType());
-        persistentState.setMultiValued(transientState.isMultiValued());
-        persistentState.setValues(transientState.getValues());
-        // make state persistent
-        stateMgr.store(persistentState);
+
+        synchronized (persistentState) {
+            // copy state from transient state
+            persistentState.setDefinitionId(transientState.getDefinitionId());
+            persistentState.setType(transientState.getType());
+            persistentState.setMultiValued(transientState.isMultiValued());
+            persistentState.setValues(transientState.getValues());
+            // make state persistent
+            stateMgr.store(persistentState);
+        }
+
         // remove listener from transient state
         transientState.removeListener(this);
         // add listener to persistent state

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=240263&r1=240262&r2=240263&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 Fri Aug 26 08:34:15 2005
@@ -151,9 +151,11 @@
      * Copy state information from a state into this state
      * @param state source state information
      */
-    protected void copy(ItemState state) {
-        parentUUID = state.getParentUUID();
-        id = state.getId();
+    protected synchronized void copy(ItemState state) {
+        synchronized (state) {
+            parentUUID = state.getParentUUID();
+            id = state.getId();
+        }
     }
 
     /**
@@ -478,9 +480,11 @@
         if (isTransient) {
             status = STATUS_STALE_MODIFIED;
         } else {
-            // this instance represents existing state, update it
-            pull();
-            notifyStateUpdated();
+            synchronized (this) {
+                // this instance represents existing state, update it
+                pull();
+                notifyStateUpdated();
+            }
         }
     }
 

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/NodeState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/NodeState.java?rev=240263&r1=240262&r2=240263&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/NodeState.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/NodeState.java Fri Aug 26 08:34:15 2005
@@ -106,16 +106,18 @@
      * {@inheritDoc}
      */
     protected synchronized void copy(ItemState state) {
-        super.copy(state);
+        synchronized (state) {
+            super.copy(state);
 
-        NodeState nodeState = (NodeState) state;
-        nodeTypeName = nodeState.getNodeTypeName();
-        mixinTypeNames = new HashSet(nodeState.getMixinTypeNames());
-        defId = nodeState.getDefinitionId();
-        uuid = nodeState.getUUID();
-        propertyNames = new HashSet(nodeState.getPropertyNames());
-        childNodeEntries = new ChildNodeEntries();
-        childNodeEntries.addAll(nodeState.getChildNodeEntries());
+            NodeState nodeState = (NodeState) state;
+            nodeTypeName = nodeState.getNodeTypeName();
+            mixinTypeNames = new HashSet(nodeState.getMixinTypeNames());
+            defId = nodeState.getDefinitionId();
+            uuid = nodeState.getUUID();
+            propertyNames = new HashSet(nodeState.getPropertyNames());
+            childNodeEntries = new ChildNodeEntries();
+            childNodeEntries.addAll(nodeState.getChildNodeEntries());
+        }
     }
 
     //-------------------------------------------------------< public methods >

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/PropertyState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/PropertyState.java?rev=240263&r1=240262&r2=240263&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/PropertyState.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/PropertyState.java Fri Aug 26 08:34:15 2005
@@ -84,14 +84,16 @@
      * {@inheritDoc}
      */
     protected synchronized void copy(ItemState state) {
-        super.copy(state);
+        synchronized (state) {
+            super.copy(state);
 
-        PropertyState propState = (PropertyState) state;
-        name = propState.getName();
-        type = propState.getType();
-        defId = propState.getDefinitionId();
-        values = propState.getValues();
-        multiValued = propState.isMultiValued();
+            PropertyState propState = (PropertyState) state;
+            name = propState.getName();
+            type = propState.getType();
+            defId = propState.getDefinitionId();
+            values = propState.getValues();
+            multiValued = propState.isMultiValued();
+        }
     }
 
     //-------------------------------------------------------< public methods >

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=240263&r1=240262&r2=240263&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 Fri Aug 26 08:34:15 2005
@@ -58,7 +58,7 @@
                 Session session = helper.getSuperuserSession();
                 TestSession ts = new TestSession("s" + i, session);
                 Thread t = new Thread(ts);
-                t.setName("s" + i);
+                t.setName((NUM_ITERATIONS - n) + "-s" + i);
                 t.start();
                 threads[i] = t;
                 Thread.sleep(100);