lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r447570 - in /lucene/java/trunk/src: java/org/apache/lucene/index/IndexWriter.java test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
Date Mon, 18 Sep 2006 21:26:02 GMT
Author: yonik
Date: Mon Sep 18 14:26:02 2006
New Revision: 447570

URL: http://svn.apache.org/viewvc?view=rev&rev=447570
Log:
retain zero size segments resulting from a merge: LUCENE-672

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?view=diff&rev=447570&r1=447569&r2=447570
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Mon Sep 18 14:26:02
2006
@@ -734,15 +734,14 @@
   /** Merges all RAM-resident segments, then may merge segments. */
   private final void flushRamSegments() throws IOException {
     if (ramSegmentInfos.size() > 0) {
-      if (mergeSegments(ramSegmentInfos, 0, ramSegmentInfos.size()) > 0) {
-        maybeMergeSegments();
-      }
+      mergeSegments(ramSegmentInfos, 0, ramSegmentInfos.size());
+      maybeMergeSegments();
     }
   }
 
   /** Incremental segment merger.  */
   private final void maybeMergeSegments() throws IOException {
-    long lowerBound = 0;
+    long lowerBound = -1;
     long upperBound = minMergeDocs;
 
     while (upperBound * mergeFactor <= maxMergeDocs) {
@@ -782,7 +781,7 @@
             // continue to merge the rest of the worthy segments on this level
             minSegment++;
             exceedsUpperLimit = true;
-          } else if (docCount > 0) {
+          } else {
             // if the merged segment does not exceed upperBound, consider
             // this segment for further merges on this same level
             numSegments++;
@@ -810,7 +809,6 @@
     if (infoStream != null) infoStream.print("merging segments");
     SegmentMerger merger = new SegmentMerger(this, mergedName);
 
-    boolean fromRAM = false;
     final Vector segmentsToDelete = new Vector();
     for (int i = minSegment; i < end; i++) {
       SegmentInfo si = sourceSegments.info(i);
@@ -821,9 +819,6 @@
       if ((reader.directory() == this.directory) || // if we own the directory
           (reader.directory() == this.ramDirectory))
         segmentsToDelete.addElement(reader);   // queue segment for deletion
-      if (!fromRAM && (reader.directory() == this.ramDirectory)) {
-        fromRAM = true;
-      }
     }
 
     int mergedDocCount = merger.merge();
@@ -834,17 +829,13 @@
 
     SegmentInfo newSegment = new SegmentInfo(mergedName, mergedDocCount,
         directory);
-    if (fromRAM) {
+    if (sourceSegments == ramSegmentInfos) {
       sourceSegments.removeAllElements();
-      if (mergedDocCount > 0)
-        segmentInfos.addElement(newSegment);
+      segmentInfos.addElement(newSegment);
     } else {
       for (int i = end-1; i > minSegment; i--)     // remove old infos & add new
         sourceSegments.remove(i);
-      if (mergedDocCount > 0)
-        segmentInfos.set(minSegment, newSegment);
-      else
-        sourceSegments.remove(minSegment);
+      segmentInfos.set(minSegment, newSegment);
     }
 
     // close readers before we attempt to delete now-obsolete segments

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java?view=diff&rev=447570&r1=447569&r2=447570
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java Mon
Sep 18 14:26:02 2006
@@ -157,9 +157,9 @@
     writer.setMaxBufferedDocs(10);
     writer.setMergeFactor(5);
 
+    // merge factor is changed, so check invariants after all adds
     for (int i = 0; i < 10; i++) {
       addDoc(writer);
-      checkInvariants(writer);
     }
     checkInvariants(writer);
     assertEquals(10, writer.docCount());
@@ -173,7 +173,7 @@
     writer.addDocument(doc);
   }
 
-  private void checkInvariants(IndexWriter writer) {
+  private void checkInvariants(IndexWriter writer) throws IOException {
     int maxBufferedDocs = writer.getMaxBufferedDocs();
     int mergeFactor = writer.getMergeFactor();
     int maxMergeDocs = writer.getMaxMergeDocs();
@@ -188,10 +188,10 @@
     int segmentCount = writer.getSegmentCount();
     for (int i = segmentCount - 1; i >= 0; i--) {
       int docCount = writer.getDocCount(i);
-      assertTrue(docCount > lowerBound);
+      assertTrue(docCount > lowerBound || docCount == 0);
 
       if (docCount <= upperBound) {
-        segmentCount++;
+        numSegments++;
       } else {
         if (upperBound * mergeFactor <= maxMergeDocs) {
           assertTrue(numSegments < mergeFactor);
@@ -199,12 +199,21 @@
 
         lowerBound = upperBound;
         upperBound *= mergeFactor;
-        segmentCount = 1;
+        numSegments = 1;
       }
     }
     if (upperBound * mergeFactor <= maxMergeDocs) {
       assertTrue(numSegments < mergeFactor);
     }
+
+    String[] files = writer.getDirectory().list();
+    int segmentCfsCount = 0;
+    for (int i = 0; i < files.length; i++) {
+      if (files[i].endsWith(".cfs")) {
+        segmentCfsCount++;
+      }
+    }
+    assertEquals(segmentCount, segmentCfsCount);
   }
 
   private void printSegmentDocCounts(IndexWriter writer) {



Mime
View raw message