jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1173166 - in /jackrabbit/branches/JCR-2272/jackrabbit-core: ./ src/main/java/org/apache/jackrabbit/core/ src/main/java/org/apache/jackrabbit/core/persistence/pool/ src/main/java/org/apache/jackrabbit/core/state/ src/main/java/org/apache/ja...
Date Tue, 20 Sep 2011 14:29:42 GMT
Author: jukka
Date: Tue Sep 20 14:29:42 2011
New Revision: 1173166

URL: http://svn.apache.org/viewvc?rev=1173166&view=rev
Log:
JCR-2272: Errors during concurrent session import of nodes with same UUIDs

Patch by Julian Reschke

Modified:
    jackrabbit/branches/JCR-2272/jackrabbit-core/pom.xml
    jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
    jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java
    jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
    jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
    jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
    jackrabbit/branches/JCR-2272/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java
    jackrabbit/branches/JCR-2272/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java

Modified: jackrabbit/branches/JCR-2272/jackrabbit-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2272/jackrabbit-core/pom.xml?rev=1173166&r1=1173165&r2=1173166&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2272/jackrabbit-core/pom.xml (original)
+++ jackrabbit/branches/JCR-2272/jackrabbit-core/pom.xml Tue Sep 20 14:29:42 2011
@@ -100,7 +100,6 @@
               <name>known.issues</name>
               <value>
 org.apache.jackrabbit.core.xml.DocumentViewTest#testMultiValue
-org.apache.jackrabbit.core.ConcurrentImportTest
 org.apache.jackrabbit.core.NodeImplTest#testReferentialIntegrityCorruptionGetPath
 org.apache.jackrabbit.core.integration.ConcurrentQueryTest#testConcurrentQueryWithDeletes
 org.apache.jackrabbit.test.api.ShareableNodeTest#testGetName

Modified: jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java?rev=1173166&r1=1173165&r2=1173166&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
(original)
+++ jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
Tue Sep 20 14:29:42 2011
@@ -1093,7 +1093,6 @@ public class ItemManager implements Item
             itemDestroyed(destroyed.getId(), data);
 
             data.setStatus(ItemImpl.STATUS_DESTROYED);
-            data.setState(null);
         }
     }
 

Modified: jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java?rev=1173166&r1=1173165&r2=1173166&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java
(original)
+++ jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java
Tue Sep 20 14:29:42 2011
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.SQLIntegrityConstraintViolationException;
 import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -493,6 +494,10 @@ public class BundleDbPersistenceManager
                 } catch (SQLException e2) {
                     DbUtility.logException("rollback failed", e2);
                 }
+
+                // if we got here due to a constraint violation and we are running in
+                // test mode, we really want to stop
+                assert !(e.getCause() instanceof SQLIntegrityConstraintViolationException);
             }
             failures++;
             log.error("Failed to persist ChangeLog (stacktrace on DEBUG log level), blockOnConnectionLoss
= "
@@ -1103,11 +1108,21 @@ public class BundleDbPersistenceManager
             Object[] params = createParams(bundle.getId(), out.toByteArray(), true);
             conHelper.update(sql, params);
         } catch (Exception e) {
-            String msg = "failed to write bundle: " + bundle.getId();
+            String msg;
+
+            if (e instanceof SQLIntegrityConstraintViolationException) {
+                // we should never get an integrity constraint violation here
+                // other PMs may not be able to detect this and end up with
+                // corrupted data
+                msg = "FATAL error while writing the bundle: " + bundle.getId();
+            } else {
+                msg = "failed to write bundle: " + bundle.getId();
+            }
+
             log.error(msg, e);
             throw new ItemStateException(msg, e);
         }
-    }
+   }
 
     /**
      * {@inheritDoc}

Modified: jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java?rev=1173166&r1=1173165&r2=1173166&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
(original)
+++ jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
Tue Sep 20 14:29:42 2011
@@ -408,10 +408,20 @@ public class LocalItemStateManager
             try {
                 local = changeLog.get(created.getId());
                 if (local != null) {
-                    // underlying state has been permanently created
-                    local.pull();
-                    local.setStatus(ItemState.STATUS_EXISTING);
-                    cache.cache(local);
+                    if (local.isNode() && local.getOverlayedState() != created) {
+                        // mid-air collision of concurrent node state creation
+                        // with same id (JCR-2272)
+                        if (local.getStatus() == ItemState.STATUS_NEW) {
+                            local.setStatus(ItemState.STATUS_UNDEFINED); // we need a state
that is != NEW
+                        }
+                    } else {
+                        if (local.getOverlayedState() == created) {
+                            // underlying state has been permanently created
+                            local.pull();
+                            local.setStatus(ItemState.STATUS_EXISTING);
+                            cache.cache(local);
+                        }
+                    }
                 }
             } catch (NoSuchItemStateException e) {
                 /* ignore */

Modified: jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=1173166&r1=1173165&r2=1173166&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Tue Sep 20 14:29:42 2011
@@ -683,6 +683,16 @@ public class SharedItemStateManager
                     shared.deleted(state.getOverlayedState());
                 }
                 for (ItemState state : local.addedStates()) {
+                    if (state.isNode() && state.getStatus() != ItemState.STATUS_NEW)
{
+                        // another node with same id had been created
+                        // in the meantime, probably caused by mid-air collision
+                        // of concurrent versioning operations (JCR-2272)
+                        String msg = state.getId()
+                                + " has been created externally  (status "
+                                + state.getStatus() + ")";
+                        log.debug(msg);
+                        throw new StaleItemStateException(msg);
+                    }
                     state.connect(createInstance(state));
                     shared.added(state.getOverlayedState());
                 }

Modified: jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java?rev=1173166&r1=1173165&r2=1173166&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
(original)
+++ jackrabbit/branches/JCR-2272/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
Tue Sep 20 14:29:42 2011
@@ -427,7 +427,9 @@ public class NodeStateEx {
                 ItemState state = stateMgr.getItemState(propId);
                 stateMgr.destroy(state);
                 nodeState.removePropertyName(name);
-                nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
+                if (nodeState.getStatus() != ItemState.STATUS_NEW) {
+                    nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
+                }
                 return true;
             }
         } catch (ItemStateException e) {

Modified: jackrabbit/branches/JCR-2272/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2272/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java?rev=1173166&r1=1173165&r2=1173166&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2272/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java
(original)
+++ jackrabbit/branches/JCR-2272/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java
Tue Sep 20 14:29:42 2011
@@ -20,18 +20,17 @@ import java.util.UUID;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.Node;
-import javax.jcr.ImportUUIDBehavior;
-import javax.jcr.InvalidItemStateException;
 
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.spi.Name;
+import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
-import org.xml.sax.Attributes;
 import org.xml.sax.helpers.AttributesImpl;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.JcrConstants;
 
 /**
  * <code>ConcurrentVersioningTest</code> contains test cases that run version
@@ -87,12 +86,17 @@ public class ConcurrentImportTest extend
                         }
                         try {
                             session.refresh(false);
-                            addNode(test, uuid, JcrConstants.NT_UNSTRUCTURED, uuid, mixins);
                             try {
+                                addNode(test, uuid,
+                                        JcrConstants.NT_UNSTRUCTURED, uuid,
+                                        mixins);
                                 session.save();
-                                log.println("Added " + test.getPath() + "/" + uuid);
+                                log.println("Added " + test.getPath() + "/"
+                                        + uuid);
                                 log.flush();
-                            } catch (InvalidItemStateException e) {
+                            } catch (RepositoryException e) {
+                                // we allow all kinds of REs here; this is temporary
+                                // in theory, we shouldn't get exceptions at all; see JCR-3068
                                 log.println("Ignoring expected error: " + e.toString());
                                 log.flush();
                                 session.refresh(false);

Modified: jackrabbit/branches/JCR-2272/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2272/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java?rev=1173166&r1=1173165&r2=1173166&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2272/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
(original)
+++ jackrabbit/branches/JCR-2272/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
Tue Sep 20 14:29:42 2011
@@ -48,8 +48,7 @@ public class TestAll extends TestCase {
         suite.addTestSuite(ReplaceTest.class);
 
         // test related to NodeStateMerger
-        // temporarily disabled see JCR-2272 and JCR-2295
-        // suite.addTestSuite(ConcurrentImportTest.class);
+        suite.addTestSuite(ConcurrentImportTest.class);
         suite.addTestSuite(ConcurrentAddRemoveMoveTest.class);
         suite.addTestSuite(ConcurrentAddRemovePropertyTest.class);
         suite.addTestSuite(ConcurrentMixinModificationTest.class);



Mime
View raw message