You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by al...@apache.org on 2012/11/29 10:06:37 UTC

svn commit: r1415093 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ main/java/org/apache/jackrabbit/core/query/lucene/directory/ test/java/org/apache/jackrabbit/core/integration/ test/resources/org/apache...

Author: alexparvulescu
Date: Thu Nov 29 09:06:35 2012
New Revision: 1415093

URL: http://svn.apache.org/viewvc?rev=1415093&view=rev
Log:
JCR-3469 Thread interrupt may result in closed index files

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java   (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/integration/repository-with-SimpleFSDirectory.xml   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java?rev=1415093&r1=1415092&r2=1415093&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java Thu Nov 29 09:06:35 2012
@@ -296,8 +296,7 @@ public abstract class QueryResultImpl im
             // update numResults
             numResults = result.getSize();
         } catch (IOException e) {
-            log.error("Exception while executing query: ", e);
-            // todo throw?
+            throw new RepositoryException(e);
         } finally {
             if (result != null) {
                 try {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=1415093&r1=1415092&r2=1415093&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Thu Nov 29 09:06:35 2012
@@ -472,6 +472,14 @@ public class SearchIndex extends Abstrac
     private DirectoryManager directoryManager;
 
     /**
+     * Flat that indicates whether the {@link DirectoryManager} should
+     * use the <code>SimpleFSDirectory</code> instead of letting Lucene
+     * automatically pick an implementation based on the platform we are
+     * running on.
+     */
+    private boolean useSimpleFSDirectory = false;
+
+    /**
      * The termInfosIndexDivisor.
      */
     private int termInfosIndexDivisor = DEFAULT_TERM_INFOS_INDEX_DIVISOR;
@@ -2379,6 +2387,26 @@ public class SearchIndex extends Abstrac
     }
 
     /**
+     * If set <code>true</code> will indicate to the {@link DirectoryManager}
+     * to use the <code>SimpleFSDirectory</code>.
+     *
+     * @param useSimpleFSDirectory whether to use <code>SimpleFSDirectory</code>
+     *                             or automatically pick an implementation based
+     *                             on the current platform.
+     */
+    public void setUseSimpleFSDirectory(boolean useSimpleFSDirectory) {
+        this.useSimpleFSDirectory = useSimpleFSDirectory;
+    }
+
+    /**
+     * @return <code>true</code> if the {@link DirectoryManager} should use
+     * the <code>SimpleFSDirectory</code>.
+     */
+    public boolean isUseSimpleFSDirectory() {
+        return useSimpleFSDirectory;
+    }
+
+    /**
      * @return the current value for termInfosIndexDivisor.
      */
     public int getTermInfosIndexDivisor() {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java?rev=1415093&r1=1415092&r2=1415093&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java Thu Nov 29 09:06:35 2012
@@ -25,6 +25,7 @@ import org.apache.lucene.store.IndexOutp
 import org.apache.lucene.store.Lock;
 import org.apache.lucene.store.LockFactory;
 import org.apache.lucene.store.NativeFSLockFactory;
+import org.apache.lucene.store.SimpleFSDirectory;
 
 import java.io.File;
 import java.io.FileFilter;
@@ -41,11 +42,14 @@ public class FSDirectoryManager implemen
      */
     private File baseDir;
 
+    private boolean useSimpleFSDirectory;
+
     /**
      * {@inheritDoc}
      */
     public void init(SearchIndex handler) throws IOException {
         baseDir = new File(handler.getPath());
+        useSimpleFSDirectory = handler.isUseSimpleFSDirectory();
     }
 
     /**
@@ -66,7 +70,7 @@ public class FSDirectoryManager implemen
         } else {
             dir = new File(baseDir, name);
         }
-        return new FSDir(dir);
+        return new FSDir(dir, useSimpleFSDirectory);
     }
 
     /**
@@ -140,14 +144,18 @@ public class FSDirectoryManager implemen
 
         private final FSDirectory directory;
 
-        public FSDir(File dir) throws IOException {
+        public FSDir(File dir, boolean simpleFS) throws IOException {
             if (!dir.mkdirs()) {
                 if (!dir.isDirectory()) {
                     throw new IOException("Unable to create directory: '" + dir + "'");
                 }
             }
-            directory = FSDirectory.open(dir,
-                    new NativeFSLockFactory(dir));
+            LockFactory lockFactory = new NativeFSLockFactory(dir);
+            if (simpleFS) {
+                directory = new SimpleFSDirectory(dir, lockFactory);
+            } else {
+                directory = FSDirectory.open(dir, lockFactory);
+            }
         }
 
         @Override

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java?rev=1415093&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java Thu Nov 29 09:06:35 2012
@@ -0,0 +1,120 @@
+/*
+ * 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.integration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.lucene.util.Constants;
+
+/**
+ * @see <a href="https://issues.apache.org/jira/browse/JCR-3469">JCR-3469</a>
+ */
+public class InterruptedQueryTest extends TestCase {
+
+    private RepositoryImpl repo;
+
+    private Session session;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        if (Constants.WINDOWS) {
+            return;
+        }
+        deleteAll();
+        FileUtils.copyInputStreamToFile(
+                getClass().getResourceAsStream("repository-with-SimpleFSDirectory.xml"),
+                new File(getTestDir(), "repository.xml"));
+        repo = RepositoryImpl.create(RepositoryConfig.create(getTestDir()));
+        session = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (session != null) {
+            session.logout();
+        }
+        if (repo != null) {
+            repo.shutdown();
+        }
+        deleteAll();
+        super.tearDown();
+    }
+
+    public void testQuery() throws Exception {
+        if (Constants.WINDOWS) {
+            return;
+        }
+        for (int i = 0; i < 100; i++) {
+            session.getRootNode().addNode("node" + i, "nt:unstructured");
+        }
+        session.save();
+        final QueryManager qm = session.getWorkspace().getQueryManager();
+        final AtomicBoolean stop = new AtomicBoolean(false);
+        final List<Exception> exceptions = Collections.synchronizedList(
+                new ArrayList<Exception>());
+        Thread t = new Thread(new Runnable() {
+            @Override
+            public void run() {
+                while (!stop.get() && exceptions.isEmpty()) {
+                    try {
+                        // execute query
+                        String stmt = "//*[@jcr:primaryType='nt:unstructured']";
+                        qm.createQuery(stmt, Query.XPATH).execute();
+                    } catch (RepositoryException e) {
+                        exceptions.add(e);
+                    }
+                }
+            }
+        });
+        t.start();
+        for (int i = 0; i < 200 && t.isAlive(); i++) {
+            t.interrupt();
+            Thread.sleep((long) (100.0 * Math.random())); 
+        }
+        stop.set(true);
+        t.join();
+        if (!exceptions.isEmpty()) {
+            fail(exceptions.get(0).toString());
+        }
+    }
+
+    private static void deleteAll() throws IOException {
+        FileUtils.deleteDirectory(getTestDir());
+    }
+
+    private static File getTestDir() throws IOException {
+        return new File("target",
+                InterruptedQueryTest.class.getSimpleName());
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/integration/repository-with-SimpleFSDirectory.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/integration/repository-with-SimpleFSDirectory.xml?rev=1415093&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/integration/repository-with-SimpleFSDirectory.xml (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/integration/repository-with-SimpleFSDirectory.xml Thu Nov 29 09:06:35 2012
@@ -0,0 +1,74 @@
+<?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">
+<Repository>
+    <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+        <param name="path" value="${rep.home}/repository"/>
+    </FileSystem>
+
+    <DataStore class="org.apache.jackrabbit.core.data.FileDataStore"/>
+    
+    <Security appName="Jackrabbit">
+        <SecurityManager class="org.apache.jackrabbit.core.DefaultSecurityManager" workspaceName="security"/>
+        <AccessManager class="org.apache.jackrabbit.core.security.DefaultAccessManager"/>
+
+        <LoginModule class="org.apache.jackrabbit.core.security.authentication.DefaultLoginModule">
+           <param name="anonymousId" value="anonymous"/>
+           <param name="adminId" value="admin"/>
+        </LoginModule>
+    </Security>
+
+    <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
+
+    <Workspace name="${wsp.name}">
+        <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+            <param name="path" value="${wsp.home}"/>
+        </FileSystem>
+
+        <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.DerbyPersistenceManager">
+          <param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
+          <param name="schemaObjectPrefix" value="${wsp.name}_"/>
+        </PersistenceManager>
+
+        <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+            <param name="path" value="${wsp.home}/index"/>
+            <param name="useSimpleFSDirectory" value="true"/>
+        </SearchIndex>
+    </Workspace>
+
+    <Versioning rootPath="${rep.home}/version">
+        <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+            <param name="path" value="${rep.home}/version" />
+        </FileSystem>
+
+        <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.DerbyPersistenceManager">
+          <param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
+          <param name="schemaObjectPrefix" value="version_"/>
+        </PersistenceManager>
+    </Versioning>
+
+    <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+        <param name="path" value="${rep.home}/repository/index"/>
+        <param name="useSimpleFSDirectory" value="true"/>
+    </SearchIndex>
+    
+    <Cluster id="node1">
+        <Journal class="org.apache.jackrabbit.core.journal.MemoryJournal"/>
+    </Cluster>
+</Repository>

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/integration/repository-with-SimpleFSDirectory.xml
------------------------------------------------------------------------------
    svn:eol-style = native