lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r698026 - in /lucene/java/branches/lucene_2_4/src: java/org/apache/lucene/index/ConcurrentMergeScheduler.java java/org/apache/lucene/index/IndexWriter.java test/org/apache/lucene/index/TestIndexWriter.java
Date Mon, 22 Sep 2008 22:55:12 GMT
Author: mikemccand
Date: Mon Sep 22 15:55:11 2008
New Revision: 698026

URL: http://svn.apache.org/viewvc?rev=698026&view=rev
Log:
LUCENE-1397: fix thread hazard whereby optimize can throw 'BG merge hit exception' IOException
without setting the root cause

Modified:
    lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java
    lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java?rev=698026&r1=698025&r2=698026&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java
(original)
+++ lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java
Mon Sep 22 15:55:11 2008
@@ -273,11 +273,6 @@
 
       } catch (Throwable exc) {
 
-        if (merge != null) {
-          merge.setException(exc);
-          writer.addMergeException(merge);
-        }
-
         // Ignore the exception if it was due to abort:
         if (!(exc instanceof MergePolicy.MergeAbortedException)) {
           synchronized(ConcurrentMergeScheduler.this) {

Modified: lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/IndexWriter.java?rev=698026&r1=698025&r2=698026&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/IndexWriter.java Mon
Sep 22 15:55:11 2008
@@ -3919,6 +3919,33 @@
     }
   }
 
+  final private void handleMergeException(Throwable t, MergePolicy.OneMerge merge) throws
IOException {
+    // Set the exception on the merge, so if
+    // optimize() is waiting on us it sees the root
+    // cause exception:
+    merge.setException(t);
+    addMergeException(merge);
+
+    if (t instanceof MergePolicy.MergeAbortedException) {
+      // We can ignore this exception (it happens when
+      // close(false) or rollback is called), unless the
+      // merge involves segments from external directories,
+      // in which case we must throw it so, for example, the
+      // rollbackTransaction code in addIndexes* is
+      // executed.
+      if (merge.isExternal)
+        throw (MergePolicy.MergeAbortedException) t;
+    } else if (t instanceof IOException)
+      throw (IOException) t;
+    else if (t instanceof RuntimeException)
+      throw (RuntimeException) t;
+    else if (t instanceof Error)
+      throw (Error) t;
+    else
+      // Should not get here
+      throw new RuntimeException(t);
+  }
+
   /**
    * Merges the indicated segments, replacing them in the stack with a
    * single segment.
@@ -3939,17 +3966,8 @@
 
           mergeMiddle(merge);
           success = true;
-        } catch (MergePolicy.MergeAbortedException e) {
-          merge.setException(e);
-          addMergeException(merge);
-
-          // We can ignore this exception, unless the merge
-          // involves segments from external directories, in
-          // which case we must throw it so, for example, the
-          // rollbackTransaction code in addIndexes* is
-          // executed.
-          if (merge.isExternal)
-            throw e;
+        } catch (Throwable t) {
+          handleMergeException(t, merge);
         }
       } finally {
         synchronized(this) {
@@ -3960,7 +3978,6 @@
             if (!success) {
               if (infoStream != null)
                 message("hit exception during merge");
-              addMergeException(merge);
               if (merge.info != null && !segmentInfos.contains(merge.info))
                 deleter.refresh(merge.info.name);
             }
@@ -4340,14 +4357,15 @@
             // remove the partially created CFS:
             success = true;
           } else
-            throw ioe;
+            handleMergeException(ioe, merge);
         }
+      } catch (Throwable t) {
+        handleMergeException(t, merge);
       } finally {
         if (!success) {
           if (infoStream != null)
             message("hit exception creating compound file during merge");
           synchronized(this) {
-            addMergeException(merge);
             deleter.deleteFile(compoundFileName);
           }
         }
@@ -4393,6 +4411,7 @@
   }
 
   synchronized void addMergeException(MergePolicy.OneMerge merge) {
+    assert merge.getException() != null;
     if (!mergeExceptions.contains(merge) && mergeGen == merge.mergeGen)
       mergeExceptions.add(merge);
   }

Modified: lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=698026&r1=698025&r2=698026&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/index/TestIndexWriter.java
(original)
+++ lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/index/TestIndexWriter.java
Mon Sep 22 15:55:11 2008
@@ -4118,4 +4118,29 @@
       _TestUtil.rmDir(indexDir);
     }
   }
+
+  public void testOptimizeExceptions() throws IOException {
+    RAMDirectory startDir = new MockRAMDirectory();
+    IndexWriter w = new IndexWriter(startDir, false, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
   
+    w.setMaxBufferedDocs(2);
+    w.setMergeFactor(100);
+    for(int i=0;i<27;i++)
+      addDoc(w);
+    w.close();
+
+    for(int i=0;i<200;i++) {
+      MockRAMDirectory dir = new MockRAMDirectory(startDir);
+      w = new IndexWriter(dir, false, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+      ((ConcurrentMergeScheduler) w.getMergeScheduler()).setSuppressExceptions();
+      dir.setRandomIOExceptionRate(0.5, 100);
+      try {
+        w.optimize();
+      } catch (IOException ioe) {
+        if (ioe.getCause() == null)
+          fail("optimize threw IOException without root cause");
+      }
+      w.close();
+      dir.close();
+    }
+  }
 }



Mime
View raw message