You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ck...@apache.org on 2012/08/28 12:02:10 UTC

svn commit: r1378050 - in /jackrabbit/branches/2.4/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/cluster/ main/java/org/apache/jackrabbit/core/state/ test/java/org/apache/jackrabbit/core/cluster/ test/resources/org/apache/jackrabbit/core/cl...

Author: ckoell
Date: Tue Aug 28 10:02:10 2012
New Revision: 1378050

URL: http://svn.apache.org/viewvc?rev=1378050&view=rev
Log:
JCR-3417 Failed Journal lock not propagated (Slightly modified because we do not have the commons-io 2.1 dependency)

Added:
    jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java   (with props)
    jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java   (with props)
    jackrabbit/branches/2.4/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml   (with props)
Modified:
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
    jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?rev=1378050&r1=1378049&r2=1378050&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java (original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java Tue Aug 28 10:02:10 2012
@@ -590,7 +590,7 @@ public class ClusterNode implements Runn
         /**
          * {@inheritDoc}
          */
-        public void updateCreated(Update update) {
+        public void updateCreated(Update update) throws ClusterException {
             if (status != STARTED) {
                 log.info("not started: update create ignored.");
                 return;
@@ -599,11 +599,12 @@ public class ClusterNode implements Runn
                 Record record = producer.append();
                 update.setAttribute(ATTRIBUTE_RECORD, record);
             } catch (JournalException e) {
-                String msg = "Unable to create log entry.";
-                log.error(msg, e);
+                String msg = "Unable to create log entry: " + e.getMessage();
+                throw new ClusterException(msg, e);
             } catch (Throwable e) {
-                String msg = "Unexpected error while creating log entry.";
-                log.error(msg, e);
+                String msg = "Unexpected error while creating log entry: "
+                        + e.getMessage();
+                throw new ClusterException(msg, e);
             }
         }
 

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java?rev=1378050&r1=1378049&r2=1378050&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java (original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java Tue Aug 28 10:02:10 2012
@@ -25,8 +25,9 @@ public interface UpdateEventChannel {
      * Called when an a update operation has been created.
      *
      * @param update update operation
+     * @throws ClusterException if an error occurs writing to the event channel.
      */
-    void updateCreated(Update update);
+    void updateCreated(Update update) throws ClusterException;
 
     /**
      * Called when an a update operation has been prepared.

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=1378050&r1=1378049&r2=1378050&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java (original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java Tue Aug 28 10:02:10 2012
@@ -27,6 +27,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 
 import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.cluster.ClusterException;
 import org.apache.jackrabbit.core.cluster.UpdateEventChannel;
 import org.apache.jackrabbit.core.id.ItemId;
 import org.apache.jackrabbit.core.id.NodeId;
@@ -562,7 +563,11 @@ public class SharedItemStateManager
             virtualNodeReferences = new ChangeLog[virtualProviders.length];
 
             // let listener know about change
-            eventChannel.updateCreated(this);
+            try {
+                eventChannel.updateCreated(this);
+            } catch (ClusterException e) {
+                throw new ItemStateException(e.getMessage(), e);
+            }
 
             try {
                 writeLock = acquireWriteLock(local);

Added: jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java?rev=1378050&view=auto
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java (added)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java Tue Aug 28 10:02:10 2012
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.cluster;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.test.JUnitTest;
+
+/**
+ * <code>FailUpdateOnJournalExceptionTest</code> checks if
+ * UpdateEventChannel.updateCreated(Update) throws a ClusterException
+ * when locking the Journal fails. See JCR-3417
+ */
+public class FailUpdateOnJournalExceptionTest extends JUnitTest {
+
+    private RepositoryImpl repo;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        deleteAll();
+        copyInputStreamToFile(
+                getClass().getResourceAsStream("repository-with-test-journal.xml"),
+                new File(getTestDir(), "repository.xml"));
+        repo = RepositoryImpl.create(RepositoryConfig.create(getTestDir()));
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (repo != null) {
+            repo.shutdown();
+        }
+        deleteAll();
+        super.tearDown();
+    }
+
+    public void testUpdate() throws Exception {
+        Session s = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
+        Node root = s.getRootNode();
+        root.addNode("foo");
+        s.save();
+        root.addNode("bar");
+        TestJournal.refuseLock = true;
+        try {
+            s.save();
+            fail("Session.save() must fail with RepositoryException when Journal cannot be locked.");
+        } catch (RepositoryException e) {
+            // expected
+        } finally {
+            TestJournal.refuseLock = false;
+        }
+    }
+
+    private static void deleteAll() throws IOException {
+        FileUtils.deleteDirectory(getTestDir());
+    }
+
+    private static File getTestDir() throws IOException {
+        return new File("target",
+                FailUpdateOnJournalExceptionTest.class.getSimpleName());
+    }
+    
+    public static void copyInputStreamToFile(InputStream source, File destination) throws IOException {
+        try {
+            FileOutputStream output = openOutputStream(destination, false);
+            try {
+                IOUtils.copy(source, output);
+                output.close(); // don't swallow close Exception if copy completes normally
+            } finally {
+                IOUtils.closeQuietly(output);
+            }
+        } finally {
+            IOUtils.closeQuietly(source);
+        }
+    }
+
+    public static FileOutputStream openOutputStream(File file, boolean append) throws IOException {
+        if (file.exists()) {
+            if (file.isDirectory()) {
+                throw new IOException("File '" + file + "' exists but is a directory");
+            }
+            if (file.canWrite() == false) {
+                throw new IOException("File '" + file + "' cannot be written to");
+            }
+        } else {
+            File parent = file.getParentFile();
+            if (parent != null) {
+                if (!parent.mkdirs() && !parent.isDirectory()) {
+                    throw new IOException("Directory '" + parent + "' could not be created");
+                }
+            }
+        }
+        return new FileOutputStream(file, append);
+    }
+
+}

Propchange: jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java?rev=1378050&r1=1378049&r2=1378050&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java (original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java Tue Aug 28 10:02:10 2012
@@ -41,6 +41,7 @@ public class TestAll extends TestCase {
         suite.addTestSuite(ClusterSyncTest.class);
         suite.addTestSuite(DbClusterTest.class);
         suite.addTestSuite(DbClusterTestJCR3162.class);
+        suite.addTestSuite(FailUpdateOnJournalExceptionTest.class);
 
         return suite;
     }

Added: jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java?rev=1378050&view=auto
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java (added)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java Tue Aug 28 10:02:10 2012
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.cluster;
+
+import org.apache.jackrabbit.core.journal.JournalException;
+import org.apache.jackrabbit.core.journal.MemoryJournal;
+
+/**
+* <code>TestJournal</code> extends the MemoryJournal with a static hook to
+* refuse lock acquisition.
+*/
+public final class TestJournal extends MemoryJournal {
+
+    static boolean refuseLock = false;
+
+    @Override
+    protected void doLock() throws JournalException {
+        if (refuseLock) {
+            throw new JournalException("lock refused");
+        } else {
+            super.doLock();
+        }
+    }
+}

Propchange: jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/branches/2.4/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml?rev=1378050&view=auto
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml (added)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml Tue Aug 28 10:02:10 2012
@@ -0,0 +1,164 @@
+<?xml version="1.0"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
+                            "http://jackrabbit.apache.org/dtd/repository-1.6.dtd">
+<!-- Example Repository Configuration File
+     Used by
+     - org.apache.jackrabbit.core.config.RepositoryConfigTest.java
+     -
+-->
+<Repository>
+    <!--
+        virtual file system where the repository stores global state
+        (e.g. registered namespaces, custom node types, etc.)
+    -->
+    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
+        <param name="url" value="jdbc:h2:${rep.home}/../db"/>
+        <param name="schemaObjectPrefix" value="fs_"/>
+        <param name="user" value="sa"/>
+        <param name="password" value="sa"/>
+    </FileSystem>
+
+    <!--
+        data store configuration
+    -->
+    <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
+        <param name="url" value="jdbc:h2:${rep.home}/../db"/>
+        <param name="schemaObjectPrefix" value="datastore_"/>
+        <param name="user" value="sa"/>
+        <param name="password" value="sa"/>
+    </DataStore>
+
+    <!--
+        security configuration
+    -->
+    <Security appName="Jackrabbit">
+        <!--
+            security manager:
+            class: FQN of class implementing the JackrabbitSecurityManager interface
+        -->
+        <SecurityManager class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager" workspaceName="security">
+            <!--
+            workspace access:
+            class: FQN of class implementing the WorkspaceAccessManager interface
+            -->
+            <!-- <WorkspaceAccessManager class="..."/> -->
+            <!-- <param name="config" value="${rep.home}/security.xml"/> -->
+        </SecurityManager>
+
+        <!--
+            access manager:
+            class: FQN of class implementing the AccessManager interface
+        -->
+        <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager">
+            <!-- <param name="config" value="${rep.home}/access.xml"/> -->
+        </AccessManager>
+
+        <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
+           <!-- 
+              anonymous user name ('anonymous' is the default value)
+            -->
+           <param name="anonymousId" value="anonymous"/>
+           <!--
+              administrator user id (default value if param is missing is 'admin')
+            -->
+           <param name="adminId" value="admin"/>
+        </LoginModule>
+    </Security>
+
+    <!--
+        location of workspaces root directory and name of default workspace
+    -->
+    <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
+    <!--
+        workspace configuration template:
+        used to create the initial workspace if there's no workspace yet
+    -->
+    <Workspace name="${wsp.name}">
+        <!--
+            virtual file system of the workspace:
+            class: FQN of class implementing the FileSystem interface
+        -->
+        <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+            <param name="path" value="${wsp.home}"/>
+        </FileSystem>
+        
+        <!--
+            persistence manager of the workspace:
+            class: FQN of class implementing the PersistenceManager interface
+        -->
+        <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager">
+            <param name="url" value="jdbc:h2:${rep.home}/../db"/>
+            <param name="schemaObjectPrefix" value="ws_${wsp.name}_"/>
+            <param name="user" value="sa"/>
+            <param name="password" value="sa"/>
+        </PersistenceManager>
+        
+        <!--
+            Search index and the file system it uses.
+            class: FQN of class implementing the QueryHandler interface
+        -->
+        <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+            <param name="path" value="${wsp.home}/index"/>
+            <param name="supportHighlighting" value="true"/>            
+        </SearchIndex>
+    </Workspace>
+
+    <!--
+        Configures the versioning
+    -->
+    <Versioning rootPath="${rep.home}/version">
+        <!--
+            Configures the filesystem to use for versioning for the respective
+            persistence manager
+        -->
+        <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+            <param name="path" value="${rep.home}/version" />
+        </FileSystem>
+
+        <!--
+            Configures the persistence manager to be used for persisting version state.
+            Please note that the current versioning implementation is based on
+            a 'normal' persistence manager, but this could change in future
+            implementations.
+        -->
+        <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager">
+            <param name="url" value="jdbc:h2:${rep.home}/../db"/>
+            <param name="schemaObjectPrefix" value="version_"/>
+            <param name="user" value="sa"/>
+            <param name="password" value="sa"/>
+        </PersistenceManager>
+    </Versioning>
+
+    <!--
+        Search index for content that is shared repository wide
+        (/jcr:system tree, contains mainly versions)
+    -->
+    <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+        <param name="path" value="${rep.home}/repository/index"/>
+        <param name="supportHighlighting" value="true"/>
+    </SearchIndex>
+    
+    <!--
+        Cluster configuration with system variables.
+    -->
+    <Cluster>
+        <Journal class="org.apache.jackrabbit.core.cluster.TestJournal"/>
+    </Cluster>
+    
+</Repository>

Propchange: jackrabbit/branches/2.4/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml
------------------------------------------------------------------------------
    svn:eol-style = native