lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1035222 - in /lucene/java/branches/lucene_2_9: CHANGES.txt src/java/org/apache/lucene/index/IndexWriter.java
Date Mon, 15 Nov 2010 10:57:13 GMT
Author: mikemccand
Date: Mon Nov 15 10:57:12 2010
New Revision: 1035222

URL: http://svn.apache.org/viewvc?rev=1035222&view=rev
Log:
LUCENE-2618: if normal merges run at same time as optimize, upgrade them to optimize merges
if they involve segments marked for optimize

Modified:
    lucene/java/branches/lucene_2_9/CHANGES.txt
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/IndexWriter.java

Modified: lucene/java/branches/lucene_2_9/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/CHANGES.txt?rev=1035222&r1=1035221&r2=1035222&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_9/CHANGES.txt Mon Nov 15 10:57:12 2010
@@ -85,6 +85,10 @@ Bug fixes
   may be opened for read even though they are still open for write.
   (Mike McCandless)
 
+* LUCENE-2618: Fix rare thread safety issue whereby
+  IndexWriter.optimize could sometimes return even though the index
+  wasn't fully optimized (Mike McCandless)
+
 Optimizations
 
 * LUCENE-2556: Improve memory usage after cloning TermAttribute.

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/IndexWriter.java?rev=1035222&r1=1035221&r2=1035222&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/IndexWriter.java Mon
Nov 15 10:57:12 2010
@@ -342,6 +342,7 @@ public class IndexWriter {
   private IndexFileDeleter deleter;
 
   private Set segmentsToOptimize = new HashSet();           // used by optimize to note those
needing optimization
+  private int optimizeMaxNumSegments;
 
   private Lock writeLock;
 
@@ -2871,6 +2872,7 @@ public class IndexWriter {
     synchronized(this) {
       resetMergeExceptions();
       segmentsToOptimize = new HashSet();
+      optimizeMaxNumSegments = maxNumSegments;
       final int numSegments = segmentInfos.size();
       for(int i=0;i<numSegments;i++)
         segmentsToOptimize.add(segmentInfos.info(i));
@@ -3078,8 +3080,9 @@ public class IndexWriter {
     throws CorruptIndexException, IOException {
     assert !optimize || maxNumSegmentsOptimize > 0;
 
-    if (stopMerges)
+    if (stopMerges) {
       return;
+    }
 
     // Do not start new merges if we've hit OOME
     if (hitOOM) {
@@ -4625,8 +4628,10 @@ public class IndexWriter {
     // disk, updating SegmentInfo, etc.:
     readerPool.clear(merge.segments);
 
-    if (merge.optimize)
+    if (merge.optimize) {
+      // cascade the optimize:
       segmentsToOptimize.add(merge.info);
+    }
     return true;
   }
   
@@ -4738,12 +4743,19 @@ public class IndexWriter {
     boolean isExternal = false;
     for(int i=0;i<count;i++) {
       final SegmentInfo info = merge.segments.info(i);
-      if (mergingSegments.contains(info))
+      if (mergingSegments.contains(info)) {
         return false;
-      if (segmentInfos.indexOf(info) == -1)
+      }
+      if (segmentInfos.indexOf(info) == -1) {
         return false;
-      if (info.dir != directory)
+      }
+      if (info.dir != directory) {
         isExternal = true;
+      }
+      if (segmentsToOptimize.contains(info)) {
+        merge.optimize = true;
+        merge.maxNumSegmentsOptimize = optimizeMaxNumSegments;
+      }
     }
 
     ensureContiguousMerge(merge);



Mime
View raw message