lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1039737 - in /lucene/dev/trunk/lucene/src: java/org/apache/lucene/index/IndexWriter.java java/org/apache/lucene/index/SegmentInfos.java test/org/apache/lucene/index/TestIndexWriter.java test/org/apache/lucene/util/LuceneTestCase.java
Date Sat, 27 Nov 2010 19:38:42 GMT
Author: mikemccand
Date: Sat Nov 27 19:38:41 2010
New Revision: 1039737

URL: http://svn.apache.org/viewvc?rev=1039737&view=rev
Log:
LUCENE-2782: fix rare thread hazard with IW.commit; also make tests slightly more evil

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentInfos.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java?rev=1039737&r1=1039736&r2=1039737&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java Sat Nov 27 19:38:41
2010
@@ -4385,6 +4385,7 @@ public class IndexWriter implements Clos
       synchronized(this) {
 
         assert lastCommitChangeCount <= changeCount;
+        myChangeCount = changeCount;
         
         if (changeCount == lastCommitChangeCount) {
           if (infoStream != null)
@@ -4401,7 +4402,24 @@ public class IndexWriter implements Clos
 
         readerPool.commit();
         
+        // It's possible another flush (that did not close
+        // the open do stores) snuck in after the flush we
+        // just did, so we remove any tail segments
+        // referencing the open doc store from the
+        // SegmentInfos we are about to sync (the main
+        // SegmentInfos will keep them):
         toSync = (SegmentInfos) segmentInfos.clone();
+        final String dss = docWriter.getDocStoreSegment();
+        if (dss != null) {
+          while(true) {
+            final String dss2 = toSync.info(toSync.size()-1).getDocStoreSegment();
+            if (dss2 == null || !dss2.equals(dss)) {
+              break;
+            }
+            toSync.remove(toSync.size()-1);
+            changeCount++;
+          }
+        }
         assert filesExist(toSync);
         
         if (commitUserData != null)
@@ -4413,7 +4431,6 @@ public class IndexWriter implements Clos
         // merge completes which would otherwise have
         // removed the files we are now syncing.
         deleter.incRef(toSync, false);
-        myChangeCount = changeCount;
       }
 
       assert testPoint("midStartCommit");

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentInfos.java?rev=1039737&r1=1039736&r2=1039737&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentInfos.java Sat Nov 27
19:38:41 2010
@@ -78,7 +78,7 @@ public final class SegmentInfos extends 
    * If non-null, information about loading segments_N files
    * will be printed here.  @see #setInfoStream.
    */
-  private static PrintStream infoStream;
+  private static PrintStream infoStream = null;
   
   public SegmentInfos() {
     this(CodecProvider.getDefault());
@@ -621,7 +621,7 @@ public final class SegmentInfos extends 
 
         try {
           Object v = doBody(segmentFileName);
-          if (exc != null && infoStream != null) {
+          if (infoStream != null) {
             message("success on " + segmentFileName);
           }
           return v;

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1039737&r1=1039736&r2=1039737&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Sat Nov
27 19:38:41 2010
@@ -981,7 +981,7 @@ public class TestIndexWriter extends Luc
       sis.read(dir);
       // Since we flushed w/o allowing merging we should now
       // have 10 segments
-      assert sis.size() == 10;
+      assertEquals(10, sis.size());
       dir.close();
     }
 
@@ -2363,9 +2363,8 @@ public class TestIndexWriter extends Luc
     final int NUM_THREADS = 5;
     final double RUN_SEC = 0.5;
     final Directory dir = newDirectory();
-    final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( 
-        TEST_VERSION_CURRENT, new MockAnalyzer()));
-    _TestUtil.reduceOpenFiles(w);
+    final RandomIndexWriter w = new RandomIndexWriter(random, dir);
+    _TestUtil.reduceOpenFiles(w.w);
     w.commit();
     final AtomicBoolean failed = new AtomicBoolean();
     Thread[] threads = new Thread[NUM_THREADS];

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java?rev=1039737&r1=1039736&r2=1039737&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java Sat Nov 27
19:38:41 2010
@@ -653,7 +653,11 @@ public abstract class LuceneTestCase ext
       c.setMergeScheduler(new SerialMergeScheduler());
     }
     if (r.nextBoolean()) {
-      c.setMaxBufferedDocs(_TestUtil.nextInt(r, 2, 1000));
+      if (r.nextInt(20) == 17) {
+        c.setMaxBufferedDocs(2);
+      } else {
+        c.setMaxBufferedDocs(_TestUtil.nextInt(r, 2, 1000));
+      }
     }
     if (r.nextBoolean()) {
       c.setTermIndexInterval(_TestUtil.nextInt(r, 1, 1000));
@@ -667,7 +671,11 @@ public abstract class LuceneTestCase ext
       logmp.setUseCompoundDocStore(r.nextBoolean());
       logmp.setUseCompoundFile(r.nextBoolean());
       logmp.setCalibrateSizeByDeletes(r.nextBoolean());
-      logmp.setMergeFactor(_TestUtil.nextInt(r, 2, 20));
+      if (r.nextInt(3) == 2) {
+        logmp.setMergeFactor(2);
+      } else {
+        logmp.setMergeFactor(_TestUtil.nextInt(r, 2, 20));
+      }
     }
     
     c.setReaderPooling(r.nextBoolean());



Mime
View raw message