lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1428437 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/index/IndexWriter.java lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
Date Thu, 03 Jan 2013 16:13:00 GMT
Author: mikemccand
Date: Thu Jan  3 16:12:59 2013
New Revision: 1428437

URL: http://svn.apache.org/viewvc?rev=1428437&view=rev
Log:
LUCENE-4653: make test more evil; fix leak on exception in IW.getReader

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java?rev=1428437&r1=1428436&r2=1428437&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
Thu Jan  3 16:12:59 2013
@@ -338,7 +338,7 @@ public class IndexWriter implements Clos
     // obtained during this flush are pooled, the first time
     // this method is called:
     poolReaders = true;
-    final DirectoryReader r;
+    DirectoryReader r = null;
     doBeforeFlush();
     boolean anySegmentFlushed = false;
     /*
@@ -348,46 +348,54 @@ public class IndexWriter implements Clos
      * We release the two stage full flush after we are done opening the
      * directory reader!
      */
-    synchronized (fullFlushLock) {
-      boolean success = false;
-      try {
-        anySegmentFlushed = docWriter.flushAllThreads();
-        if (!anySegmentFlushed) {
-          // prevent double increment since docWriter#doFlush increments the flushcount
-          // if we flushed anything.
-          flushCount.incrementAndGet();
-        }
-        success = true;
-        // Prevent segmentInfos from changing while opening the
-        // reader; in theory we could do similar retry logic,
-        // just like we do when loading segments_N
-        synchronized(this) {
-          maybeApplyDeletes(applyAllDeletes);
-          r = StandardDirectoryReader.open(this, segmentInfos, applyAllDeletes);
-          if (infoStream.isEnabled("IW")) {
-            infoStream.message("IW", "return reader version=" + r.getVersion() + " reader="
+ r);
+    boolean success2 = false;
+    try {
+      synchronized (fullFlushLock) {
+        boolean success = false;
+        try {
+          anySegmentFlushed = docWriter.flushAllThreads();
+          if (!anySegmentFlushed) {
+            // prevent double increment since docWriter#doFlush increments the flushcount
+            // if we flushed anything.
+            flushCount.incrementAndGet();
           }
-        }
-      } catch (OutOfMemoryError oom) {
-        handleOOM(oom, "getReader");
-        // never reached but javac disagrees:
-        return null;
-      } finally {
-        if (!success) {
-          if (infoStream.isEnabled("IW")) {
-            infoStream.message("IW", "hit exception during NRT reader");
+          success = true;
+          // Prevent segmentInfos from changing while opening the
+          // reader; in theory we could do similar retry logic,
+          // just like we do when loading segments_N
+          synchronized(this) {
+            maybeApplyDeletes(applyAllDeletes);
+            r = StandardDirectoryReader.open(this, segmentInfos, applyAllDeletes);
+            if (infoStream.isEnabled("IW")) {
+              infoStream.message("IW", "return reader version=" + r.getVersion() + " reader="
+ r);
+            }
+          }
+        } catch (OutOfMemoryError oom) {
+          handleOOM(oom, "getReader");
+          // never reached but javac disagrees:
+          return null;
+        } finally {
+          if (!success) {
+            if (infoStream.isEnabled("IW")) {
+              infoStream.message("IW", "hit exception during NRT reader");
+            }
           }
+          // Done: finish the full flush!
+          docWriter.finishFullFlush(success);
+          doAfterFlush();
         }
-        // Done: finish the full flush!
-        docWriter.finishFullFlush(success);
-        doAfterFlush();
       }
-    }
-    if (anySegmentFlushed) {
-      maybeMerge(MergeTrigger.FULL_FLUSH, UNBOUNDED_MAX_MERGE_SEGMENTS);
-    }
-    if (infoStream.isEnabled("IW")) {
-      infoStream.message("IW", "getReader took " + (System.currentTimeMillis() - tStart)
+ " msec");
+      if (anySegmentFlushed) {
+        maybeMerge(MergeTrigger.FULL_FLUSH, UNBOUNDED_MAX_MERGE_SEGMENTS);
+      }
+      if (infoStream.isEnabled("IW")) {
+        infoStream.message("IW", "getReader took " + (System.currentTimeMillis() - tStart)
+ " msec");
+      }
+      success2 = true;
+    } finally {
+      if (!success2) {
+        IOUtils.closeWhileHandlingException(r);
+      }
     }
     return r;
   }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1428437&r1=1428436&r2=1428437&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
Thu Jan  3 16:12:59 2013
@@ -17,7 +17,6 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
@@ -1028,14 +1027,33 @@ public class TestIndexWriter extends Luc
             doc.add(newField("field", "some text contents", storedTextType));
             for(int i=0;i<100;i++) {
               idField.setStringValue(Integer.toString(i));
-              if (i%2 == 0) {
+              if (i%30 == 0) {
+                w.deleteAll();
+              } else if (i%2 == 0) {
                 w.updateDocument(new Term("id", idField.stringValue()), doc);
               } else {
                 w.addDocument(doc);
               }
+              if (i%3 == 0) {
+                IndexReader r = null;
+                boolean success = false;
+                try {
+                  r = DirectoryReader.open(w, true);
+                  success = true;
+                } finally {
+                  if (success) {
+                    r.close();
+                  } else {
+                    IOUtils.closeWhileHandlingException(r);
+                  }
+                }
+              }
               if (i%10 == 0) {
                 w.commit();
               }
+              if (i%40 == 0) {
+                w.forceMerge(1);
+              }
             }
             w.close();
             w = null;



Mime
View raw message