lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1049039 - /lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java
Date Tue, 14 Dec 2010 11:05:01 GMT
Author: mikemccand
Date: Tue Dec 14 11:05:00 2010
New Revision: 1049039

URL: http://svn.apache.org/viewvc?rev=1049039&view=rev
Log:
on exception close any opened per-field fieldsProducers

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java?rev=1049039&r1=1049038&r2=1049039&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java Tue
Dec 14 11:05:00 2010
@@ -102,16 +102,34 @@ final class PerFieldCodecWrapper extends
 
       final int fieldCount = fieldInfos.size();
       final Map<Codec, FieldsProducer> producers = new HashMap<Codec, FieldsProducer>();
-      for (int i = 0; i < fieldCount; i++) {
-        FieldInfo fi = fieldInfos.fieldInfo(i);
-        if (fi.isIndexed) { // TODO this does not work for non-indexed fields
-          fields.add(fi.name);
-          Codec codec = segmentCodecs.codecs[fi.codecId];
-          if (!producers.containsKey(codec)) {
-            producers.put(codec, codec.fieldsProducer(new SegmentReadState(dir,
-                si, fieldInfos, readBufferSize, indexDivisor, ""+fi.codecId)));
+      boolean success = false;
+      try {
+        for (int i = 0; i < fieldCount; i++) {
+          FieldInfo fi = fieldInfos.fieldInfo(i);
+          if (fi.isIndexed) { // TODO this does not work for non-indexed fields
+            fields.add(fi.name);
+            Codec codec = segmentCodecs.codecs[fi.codecId];
+            if (!producers.containsKey(codec)) {
+              producers.put(codec, codec.fieldsProducer(new SegmentReadState(dir,
+                                                                             si, fieldInfos,
readBufferSize, indexDivisor, ""+fi.codecId)));
+            }
+            codecs.put(fi.name, producers.get(codec));
+          }
+        }
+        success = true;
+      } finally {
+        if (!success) {
+          // If we hit exception (eg, IOE because writer was
+          // committing, or, for any other reason) we must
+          // go back and close all FieldsProducers we opened:
+          for(FieldsProducer fp : producers.values()) {
+            try {
+              fp.close();
+            } catch (Throwable t) {
+              // Suppress all exceptions here so we continue
+              // to throw the original one
+            }
           }
-          codecs.put(fi.name, producers.get(codec));
         }
       }
     }



Mime
View raw message