jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1598058 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/cluster/ main/java/org/apache/jackrabbit/core/state/ test/java/org/apache/jackrabbit/core/cluster/
Date Wed, 28 May 2014 16:14:46 GMT
Author: mreutegg
Date: Wed May 28 16:14:45 2014
New Revision: 1598058

URL: http://svn.apache.org/r1598058
Log:
JCR-3783: Deadlock due to IOException in WorkspaceUpdateChannel.updatePrepared()

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?rev=1598058&r1=1598057&r2=1598058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
Wed May 28 16:14:45 2014
@@ -647,7 +647,7 @@ public class ClusterNode implements Runn
         /**
          * {@inheritDoc}
          */
-        public void updatePrepared(Update update) {
+        public void updatePrepared(Update update) throws ClusterException {
             if (status != STARTED) {
                 log.info("not started: update prepare ignored.");
                 return;
@@ -671,12 +671,12 @@ public class ClusterNode implements Runn
                 succeeded = true;
             } catch (JournalException e) {
                 String msg = "Unable to create log entry: " + e.getMessage();
-                log.error(msg);
+                throw new ClusterException(msg, e);
             } catch (Throwable e) {
                 String msg = "Unexpected error while preparing log entry.";
-                log.error(msg, e);
+                throw new ClusterException(msg, e);
             } finally {
-                if (!succeeded && record != null) {
+                if (!succeeded) {
                     record.cancelUpdate();
                     update.setAttribute(ATTRIBUTE_RECORD, null);
                 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java?rev=1598058&r1=1598057&r2=1598058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
Wed May 28 16:14:45 2014
@@ -33,8 +33,9 @@ public interface UpdateEventChannel {
      * Called when an a update operation has been prepared.
      *
      * @param update update operation
+     * @throws ClusterException if an error occurs writing to the event channel.
      */
-    void updatePrepared(Update update);
+    void updatePrepared(Update update) throws ClusterException;
 
     /**
      * Called when an a update operation has been committed.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=1598058&r1=1598057&r2=1598058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Wed May 28 16:14:45 2014
@@ -747,7 +747,11 @@ public class SharedItemStateManager
                 events.createEventStates(rootNodeId, local, SharedItemStateManager.this);
 
                 // let listener know about change
-                eventChannel.updatePrepared(this);
+                try {
+                    eventChannel.updatePrepared(this);
+                } catch (ClusterException e) {
+                    throw new ItemStateException(e.getMessage(), e);
+                }
 
                 if (VALIDATE_HIERARCHY) {
                     log.debug("Validating change-set hierarchy");

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java?rev=1598058&r1=1598057&r2=1598058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
Wed May 28 16:14:45 2014
@@ -74,6 +74,28 @@ public class FailUpdateOnJournalExceptio
         }
     }
 
+    // JCR-3783
+    public void testFailedWrite() throws Exception {
+        Session s = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
+        Node root = s.getRootNode();
+        root.addNode("foo");
+        s.save();
+        root.addNode("bar");
+        TestJournal.failRecordWrite = true;
+        try {
+            s.save();
+            fail("Session.save() must fail with RepositoryException when Journal write fails.");
+        } catch (RepositoryException e) {
+            // expected
+        } finally {
+            TestJournal.failRecordWrite = false;
+        }
+        // must succeed after refresh
+        s.refresh(false);
+        root.addNode("bar");
+        s.save();
+    }
+
     private static void deleteAll() throws IOException {
         FileUtils.deleteDirectory(getTestDir());
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java?rev=1598058&r1=1598057&r2=1598058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
Wed May 28 16:14:45 2014
@@ -16,8 +16,11 @@
  */
 package org.apache.jackrabbit.core.cluster;
 
+import org.apache.jackrabbit.core.journal.AppendRecord;
+import org.apache.jackrabbit.core.journal.DefaultRecordProducer;
 import org.apache.jackrabbit.core.journal.JournalException;
 import org.apache.jackrabbit.core.journal.MemoryJournal;
+import org.apache.jackrabbit.core.journal.RecordProducer;
 
 /**
 * <code>TestJournal</code> extends the MemoryJournal with a static hook to
@@ -27,6 +30,8 @@ public final class TestJournal extends M
 
     static boolean refuseLock = false;
 
+    static boolean failRecordWrite = false;
+
     @Override
     protected void doLock() throws JournalException {
         if (refuseLock) {
@@ -35,4 +40,23 @@ public final class TestJournal extends M
             super.doLock();
         }
     }
+
+    @Override
+    protected RecordProducer createProducer(final String identifier) {
+        return new DefaultRecordProducer(this, identifier) {
+            @Override
+            protected AppendRecord createRecord() throws JournalException {
+                return new AppendRecord(TestJournal.this, identifier) {
+                    @Override
+                    public void writeString(String s) throws JournalException {
+                        if (failRecordWrite) {
+                            throw new JournalException("write failed");
+                        } else {
+                            super.writeString(s);
+                        }
+                    }
+                };
+            }
+        };
+    }
 }



Mime
View raw message