lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r620799 - in /lucene/java/branches/lucene_2_3: CHANGES.txt src/java/org/apache/lucene/index/IndexWriter.java src/test/org/apache/lucene/index/TestIndexWriter.java
Date Tue, 12 Feb 2008 13:48:48 GMT
Author: mikemccand
Date: Tue Feb 12 05:48:44 2008
New Revision: 620799

URL: http://svn.apache.org/viewvc?rev=620799&view=rev
Log:
LUCENE-1177 (backport to 2.3): fix rare case where optimize() can do too many merges at the
end

Modified:
    lucene/java/branches/lucene_2_3/CHANGES.txt
    lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/branches/lucene_2_3/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/CHANGES.txt?rev=620799&r1=620798&r2=620799&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_3/CHANGES.txt Tue Feb 12 05:48:44 2008
@@ -21,6 +21,9 @@
     offset, int len) that was ignoring offset and thus giving the
     wrong answer.  (Thomas Peuss via Mike McCandless)
 	
+ 5. LUCENE-1177: Fix rare case where IndexWriter.optimize might do doo
+    many merges at the end.  (Mike McCandless)
+	
 New features
 
 Optimizations

Modified: lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java?rev=620799&r1=620798&r2=620799&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java Tue
Feb 12 05:48:44 2008
@@ -3039,6 +3039,11 @@
                                  docStoreOffset,
                                  docStoreSegment,
                                  docStoreIsCompoundFile);
+    // Also enroll the merged segment into mergingSegments;
+    // this prevents it from getting selected for a merge
+    // after our merge is done but while we are building the
+    // CFS:
+    mergingSegments.add(merge.info);
   }
 
   /** Does fininishing for a merge, which is fast but holds
@@ -3054,6 +3059,7 @@
     final int end = sourceSegments.size();
     for(int i=0;i<end;i++)
       mergingSegments.remove(sourceSegments.info(i));
+    mergingSegments.remove(merge.info);
     merge.registerDone = false;
   }
 

Modified: lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=620799&r1=620798&r2=620799&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java
(original)
+++ lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java
Tue Feb 12 05:48:44 2008
@@ -2793,4 +2793,48 @@
     reader.close();
     dir.close();
   }
+
+  // Just intercepts all merges & verifies that we are never
+  // merging a segment with >= 20 (maxMergeDocs) docs
+  private class MyIndexWriter extends IndexWriter {
+    int mergeCount;
+    Directory myDir;
+    public MyIndexWriter(Directory dir) throws IOException {
+      super(dir, new StandardAnalyzer());
+      myDir = dir;
+    }
+    synchronized MergePolicy.OneMerge getNextMerge() {
+      MergePolicy.OneMerge merge = super.getNextMerge();
+      if (merge != null)
+        mergeCount++;
+      return merge;
+    }
+  }
+
+  public void testOptimizeOverMerge() throws IOException {
+    Directory dir = new MockRAMDirectory();
+    IndexWriter writer = new IndexWriter(dir,
+                                         false, new StandardAnalyzer());
+    writer.setMaxBufferedDocs(2);
+    writer.setMergeFactor(100);
+    writer.setRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
+
+    Document document = new Document();
+
+    document = new Document();
+    Field storedField = new Field("stored", "stored", Field.Store.YES,
+                                  Field.Index.NO);
+    document.add(storedField);
+    Field termVectorField = new Field("termVector", "termVector",
+                                      Field.Store.NO, Field.Index.UN_TOKENIZED,
+                                      Field.TermVector.WITH_POSITIONS_OFFSETS);
+    document.add(termVectorField);
+    for(int i=0;i<170;i++)
+      writer.addDocument(document);
+
+    writer.close();
+    MyIndexWriter myWriter = new MyIndexWriter(dir);
+    myWriter.optimize();
+    assertEquals(10, myWriter.mergeCount);
+  }
 }



Mime
View raw message