You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2013/01/21 16:55:26 UTC
svn commit: r1436430 -
/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/DocValuesProcessor.java
Author: rmuir
Date: Mon Jan 21 15:55:25 2013
New Revision: 1436430
URL: http://svn.apache.org/viewvc?rev=1436430&view=rev
Log:
ensure we close the dv consumer even if we hit exception when writing
Modified:
lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/DocValuesProcessor.java
Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/DocValuesProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/DocValuesProcessor.java?rev=1436430&r1=1436429&r2=1436430&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/DocValuesProcessor.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/DocValuesProcessor.java Mon Jan 21 15:55:25 2013
@@ -26,6 +26,7 @@ import org.apache.lucene.codecs.DocValue
import org.apache.lucene.index.FieldInfo.DocValuesType;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.Counter;
+import org.apache.lucene.util.IOUtils;
final class DocValuesProcessor extends StoredFieldsConsumer {
@@ -80,26 +81,22 @@ final class DocValuesProcessor extends S
void flush(SegmentWriteState state) throws IOException {
if (!writers.isEmpty()) {
DocValuesFormat fmt = state.segmentInfo.getCodec().docValuesFormat();
- // nocommit once we make
- // Codec.simpleDocValuesFormat abstract, change
- // this to assert fmt != null!
- if (fmt == null) {
- return;
- }
-
DocValuesConsumer dvConsumer = fmt.fieldsConsumer(state);
- // nocommit change to assert != null:
- if (dvConsumer == null) {
- return;
- }
-
- for(DocValuesWriter writer : writers.values()) {
- writer.finish(state.segmentInfo.getDocCount());
- writer.flush(state, dvConsumer);
+ boolean success = false;
+ try {
+ for(DocValuesWriter writer : writers.values()) {
+ writer.finish(state.segmentInfo.getDocCount());
+ writer.flush(state, dvConsumer);
+ }
+ writers.clear();
+ success = true;
+ } finally {
+ if (success) {
+ IOUtils.close(dvConsumer);
+ } else {
+ IOUtils.closeWhileHandlingException(dvConsumer);
+ }
}
-
- writers.clear();
- dvConsumer.close();
}
}