lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r651027 - in /lucene/java/branches/lucene_2_3: CHANGES.txt src/java/org/apache/lucene/index/IndexWriter.java src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java
Date Wed, 23 Apr 2008 19:47:21 GMT
Author: mikemccand
Date: Wed Apr 23 12:47:09 2008
New Revision: 651027

URL: http://svn.apache.org/viewvc?rev=651027&view=rev
Log:
LUCENE-1270: fix intermittant case where IW.close() can hang after IW.addIndexesNoOptimize
is called

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/TestAddIndexesNoOptimize.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=651027&r1=651026&r2=651027&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_3/CHANGES.txt Wed Apr 23 12:47:09 2008
@@ -32,13 +32,17 @@
     successfully created compound files. (Michael Busch)
 
 10. LUCENE-1150: Re-expose StandardTokenizer's constants publicly;
-     this was accidentally lost with LUCENE-966.  (Nicolas Lalevée via
-     Mike McCandless)
+    this was accidentally lost with LUCENE-966.  (Nicolas Lalevée via
+    Mike McCandless)
 
 11. LUCENE-1262: Fixed bug in BufferedIndexReader.refill whereby on
     hitting an exception in readInternal, the buffer is incorrectly
     filled with stale bytes such that subsequent calls to readByte()
     return incorrect results.  (Trejkaz via Mike McCandless)
+
+12. LUCENE-1270: Fixed intermittant case where IndexWriter.close()
+    would hang after IndexWriter.addIndexesNoOptimize had been
+    called.  (Stu Hood via Mike McCandless)
 	
 Build
 

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=651027&r1=651026&r2=651027&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 Wed
Apr 23 12:47:09 2008
@@ -1211,6 +1211,11 @@
       // going to wait for merges:
       flush(waitForMerges, true);
 
+      if (waitForMerges)
+        // Give merge scheduler last chance to run, in case
+        // any pending merges are waiting:
+        mergeScheduler.merge(this);
+
       mergePolicy.close();
 
       finishMerges(waitForMerges);
@@ -2322,6 +2327,9 @@
    * then copy them over.  Currently this is only used by
    * addIndexesNoOptimize(). */
   private void copyExternalSegments() throws CorruptIndexException, IOException {
+
+    boolean any = false;
+
     while(true) {
       SegmentInfo info = null;
       MergePolicy.OneMerge merge = null;
@@ -2340,6 +2348,7 @@
         if (registerMerge(merge)) {
           pendingMerges.remove(merge);
           runningMerges.add(merge);
+          any = true;
           merge(merge);
         } else
           // This means there is a bug in the
@@ -2355,6 +2364,11 @@
         // No more external segments
         break;
     }
+
+    if (any)
+      // Sometimes, on copying an external segment over,
+      // more merges may become necessary:
+      mergeScheduler.merge(this);
   }
 
   /** Merges the provided indexes into this index.

Modified: lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java?rev=651027&r1=651026&r2=651027&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java
(original)
+++ lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java
Wed Apr 23 12:47:09 2008
@@ -28,6 +28,7 @@
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.MockRAMDirectory;
 
 public class TestAddIndexesNoOptimize extends LuceneTestCase {
   public void testSimpleCase() throws IOException {
@@ -320,9 +321,8 @@
   private void addDocs(IndexWriter writer, int numDocs) throws IOException {
     for (int i = 0; i < numDocs; i++) {
       Document doc = new Document();
-      doc
-          .add(new Field("content", "aaa", Field.Store.NO,
-              Field.Index.TOKENIZED));
+      doc.add(new Field("content", "aaa", Field.Store.NO,
+                        Field.Index.TOKENIZED));
       writer.addDocument(doc);
     }
   }
@@ -330,9 +330,8 @@
   private void addDocs2(IndexWriter writer, int numDocs) throws IOException {
     for (int i = 0; i < numDocs; i++) {
       Document doc = new Document();
-      doc
-          .add(new Field("content", "bbb", Field.Store.NO,
-              Field.Index.TOKENIZED));
+      doc.add(new Field("content", "bbb", Field.Store.NO,
+                        Field.Index.TOKENIZED));
       writer.addDocument(doc);
     }
   }
@@ -382,5 +381,48 @@
     assertEquals(30, writer.docCount());
     assertEquals(3, writer.getSegmentCount());
     writer.close();
+  }
+
+  // LUCENE-1270
+  public void testHangOnClose() throws IOException {
+
+    Directory dir = new MockRAMDirectory();
+    IndexWriter writer = new IndexWriter(dir, false, new WhitespaceAnalyzer(), true);
+    writer.setMergePolicy(new LogByteSizeMergePolicy());
+    writer.setMaxBufferedDocs(5);
+    writer.setUseCompoundFile(false);
+    writer.setMergeFactor(100);
+
+    Document doc = new Document();
+    doc.add(new Field("content", "aaa bbb ccc ddd eee fff ggg hhh iii", Field.Store.YES,
+                      Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
+    for(int i=0;i<60;i++)
+      writer.addDocument(doc);
+    writer.setMaxBufferedDocs(200);
+    Document doc2 = new Document();
+    doc2.add(new Field("content", "aaa bbb ccc ddd eee fff ggg hhh iii", Field.Store.YES,
+                      Field.Index.NO));
+    doc2.add(new Field("content", "aaa bbb ccc ddd eee fff ggg hhh iii", Field.Store.YES,
+                      Field.Index.NO));
+    doc2.add(new Field("content", "aaa bbb ccc ddd eee fff ggg hhh iii", Field.Store.YES,
+                      Field.Index.NO));
+    doc2.add(new Field("content", "aaa bbb ccc ddd eee fff ggg hhh iii", Field.Store.YES,
+                      Field.Index.NO));
+    for(int i=0;i<10;i++)
+      writer.addDocument(doc2);
+    writer.close();
+
+    Directory dir2 = new MockRAMDirectory();
+    writer = new IndexWriter(dir2, false, new WhitespaceAnalyzer(), true);
+    LogByteSizeMergePolicy lmp = new LogByteSizeMergePolicy();
+    lmp.setMinMergeMB(0.0001);
+    writer.setMergePolicy(lmp);
+    writer.setMergeFactor(4);
+    writer.setUseCompoundFile(false);
+    writer.setMergeScheduler(new SerialMergeScheduler());
+    writer.addIndexesNoOptimize(new Directory[] {dir});
+    writer.close();
+    dir.close();
+    dir2.close();
   }
 }



Mime
View raw message