jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1429838 - in /jackrabbit/branches/2.4: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/ jackrabbit-core/src/test/java/org/apache/jack...
Date Mon, 07 Jan 2013 15:20:14 GMT
Author: mreutegg
Date: Mon Jan  7 15:20:13 2013
New Revision: 1429838

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

Added:
    jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java
      - copied, changed from r1415093, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java
    jackrabbit/branches/2.4/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/integration/repository-with-SimpleFSDirectory.xml
      - copied unchanged from r1415093, jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/integration/repository-with-SimpleFSDirectory.xml
Modified:
    jackrabbit/branches/2.4/   (props changed)
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java

Propchange: jackrabbit/branches/2.4/
------------------------------------------------------------------------------
  Merged /jackrabbit/trunk:r1415093,1416387,1416863

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java?rev=1429838&r1=1429837&r2=1429838&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
Mon Jan  7 15:20:13 2013
@@ -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/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=1429838&r1=1429837&r2=1429838&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Mon Jan  7 15:20:13 2013
@@ -471,6 +471,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;
@@ -2421,6 +2429,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/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java?rev=1429838&r1=1429837&r2=1429838&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java
Mon Jan  7 15:20:13 2013
@@ -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

Copied: jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java
(from r1415093, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java?p2=jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java&p1=jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java&r1=1415093&r2=1429838&rev=1429838&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/InterruptedQueryTest.java
Mon Jan  7 15:20:13 2013
@@ -17,7 +17,9 @@
 package org.apache.jackrabbit.core.integration;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InterruptedIOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -29,38 +31,40 @@ 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.commons.io.IOUtils;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 import org.apache.lucene.util.Constants;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * @see <a href="https://issues.apache.org/jira/browse/JCR-3469">JCR-3469</a>
  */
-public class InterruptedQueryTest extends TestCase {
+public class InterruptedQueryTest {
 
     private RepositoryImpl repo;
 
     private Session session;
     
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setUp() throws Exception {
         if (Constants.WINDOWS) {
             return;
         }
         deleteAll();
-        FileUtils.copyInputStreamToFile(
-                getClass().getResourceAsStream("repository-with-SimpleFSDirectory.xml"),
-                new File(getTestDir(), "repository.xml"));
+        File f = getTestDir();
+        f.mkdirs();
+        IOUtils.copy(getClass().getResourceAsStream("repository-with-SimpleFSDirectory.xml"),
+                new FileOutputStream(new File(f, "repository.xml")));
         repo = RepositoryImpl.create(RepositoryConfig.create(getTestDir()));
         session = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
     }
 
-    @Override
-    protected void tearDown() throws Exception {
+    @After
+    public void tearDown() throws Exception {
         if (session != null) {
             session.logout();
         }
@@ -68,9 +72,9 @@ public class InterruptedQueryTest extend
             repo.shutdown();
         }
         deleteAll();
-        super.tearDown();
     }
 
+    @Test
     public void testQuery() throws Exception {
         if (Constants.WINDOWS) {
             return;
@@ -92,7 +96,20 @@ public class InterruptedQueryTest extend
                         String stmt = "//*[@jcr:primaryType='nt:unstructured']";
                         qm.createQuery(stmt, Query.XPATH).execute();
                     } catch (RepositoryException e) {
-                        exceptions.add(e);
+                        if (Constants.SUN_OS) {
+                            // on Solaris it's OK when the root cause
+                            // of the exception is an InterruptedIOException
+                            // the underlying file is not closed
+                            Throwable t = e;
+                            while (t.getCause() != null) {
+                                t = t.getCause();
+                            }
+                            if (!(t instanceof InterruptedIOException)) {
+                                exceptions.add(e);
+                            }
+                        } else {
+                            exceptions.add(e);
+                        }
                     }
                 }
             }
@@ -105,7 +122,7 @@ public class InterruptedQueryTest extend
         stop.set(true);
         t.join();
         if (!exceptions.isEmpty()) {
-            fail(exceptions.get(0).toString());
+            throw exceptions.get(0);
         }
     }
 



Mime
View raw message