lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1033417 - /lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java
Date Wed, 10 Nov 2010 11:23:01 GMT
Author: mikemccand
Date: Wed Nov 10 11:23:00 2010
New Revision: 1033417

URL: http://svn.apache.org/viewvc?rev=1033417&view=rev
Log:
LUCENE-2576: fix one case of intermittent failure (unclosed files when using PreFlex codec)

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java?rev=1033417&r1=1033416&r2=1033417&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java
(original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java
Wed Nov 10 11:23:00 2010
@@ -74,39 +74,51 @@ public class PreFlexFields extends Field
     if (indexDivisor < 0) {
       indexDivisor = -indexDivisor;
     }
+    
+    boolean success = false;
+    try {
+      TermInfosReader r = new TermInfosReader(dir, info.name, fieldInfos, readBufferSize,
indexDivisor);    
+      if (indexDivisor == -1) {
+        tisNoIndex = r;
+      } else {
+        tisNoIndex = null;
+        tis = r;
+      }
+      this.readBufferSize = readBufferSize;
+      this.fieldInfos = fieldInfos;
 
-    TermInfosReader r = new TermInfosReader(dir, info.name, fieldInfos, readBufferSize, indexDivisor);
   
-    if (indexDivisor == -1) {
-      tisNoIndex = r;
-    } else {
-      tisNoIndex = null;
-      tis = r;
-    }
-    this.readBufferSize = readBufferSize;
-    this.fieldInfos = fieldInfos;
-
-    // make sure that all index files have been read or are kept open
-    // so that if an index update removes them we'll still have them
-    freqStream = dir.openInput(info.name + ".frq", readBufferSize);
-    boolean anyProx = false;
-    final int numFields = fieldInfos.size();
-    for(int i=0;i<numFields;i++) {
-      final FieldInfo fieldInfo = fieldInfos.fieldInfo(i);
-      if (fieldInfo.isIndexed) {
-        fields.put(fieldInfo.name, fieldInfo);
-        preTerms.put(fieldInfo.name, new PreTerms(fieldInfo));
-        if (!fieldInfo.omitTermFreqAndPositions) {
-          anyProx = true;
+      // make sure that all index files have been read or are kept open
+      // so that if an index update removes them we'll still have them
+      freqStream = dir.openInput(info.name + ".frq", readBufferSize);
+      boolean anyProx = false;
+      final int numFields = fieldInfos.size();
+      for(int i=0;i<numFields;i++) {
+        final FieldInfo fieldInfo = fieldInfos.fieldInfo(i);
+        if (fieldInfo.isIndexed) {
+          fields.put(fieldInfo.name, fieldInfo);
+          preTerms.put(fieldInfo.name, new PreTerms(fieldInfo));
+          if (!fieldInfo.omitTermFreqAndPositions) {
+            anyProx = true;
+          }
         }
       }
-    }
 
-    if (anyProx) {
-      proxStream = dir.openInput(info.name + ".prx", readBufferSize);
-    } else {
-      proxStream = null;
+      if (anyProx) {
+        proxStream = dir.openInput(info.name + ".prx", readBufferSize);
+      } else {
+        proxStream = null;
+      }
+      success = true;
+    } finally {
+      // With lock-less commits, it's entirely possible (and
+      // fine) to hit a FileNotFound exception above. In
+      // this case, we want to explicitly close any subset
+      // of things that were opened so that we don't have to
+      // wait for a GC to do so.
+      if (!success) {
+        close();
+      }
     }
-
     this.dir = dir;
   }
 



Mime
View raw message