From ba67596a0ec94f4c27785feeb8c68f1da90babfc Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 21 Jan 2013 15:29:11 +0000 Subject: [PATCH] add a numeric dv field to disk full test and fix diskdv (some codecs still fail) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1436414 13f79535-47bb-0310-9956-ffa450edef68 --- .../codecs/diskdv/DiskDocValuesConsumer.java | 41 ++++++++++++++----- .../index/TestIndexWriterOnDiskFull.java | 3 ++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/diskdv/DiskDocValuesConsumer.java b/lucene/codecs/src/java/org/apache/lucene/codecs/diskdv/DiskDocValuesConsumer.java index a75ee8e2f1c..f04f1088014 100644 --- a/lucene/codecs/src/java/org/apache/lucene/codecs/diskdv/DiskDocValuesConsumer.java +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/diskdv/DiskDocValuesConsumer.java @@ -37,15 +37,23 @@ class DiskDocValuesConsumer extends DocValuesConsumer { final int maxDoc; DiskDocValuesConsumer(SegmentWriteState state) throws IOException { - String dataName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, "ddvd"); - data = state.directory.createOutput(dataName, state.context); - CodecUtil.writeHeader(data, DiskDocValuesFormat.DATA_CODEC, - DiskDocValuesFormat.VERSION_CURRENT); - String metaName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, "ddvm"); - meta = state.directory.createOutput(metaName, state.context); - CodecUtil.writeHeader(meta, DiskDocValuesFormat.METADATA_CODEC, - DiskDocValuesFormat.VERSION_CURRENT); - maxDoc = state.segmentInfo.getDocCount(); + boolean success = false; + try { + String dataName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, "ddvd"); + data = state.directory.createOutput(dataName, state.context); + CodecUtil.writeHeader(data, DiskDocValuesFormat.DATA_CODEC, + DiskDocValuesFormat.VERSION_CURRENT); + String metaName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, "ddvm"); + meta = state.directory.createOutput(metaName, state.context); + CodecUtil.writeHeader(meta, DiskDocValuesFormat.METADATA_CODEC, + DiskDocValuesFormat.VERSION_CURRENT); + maxDoc = state.segmentInfo.getDocCount(); + success = true; + } finally { + if (!success) { + IOUtils.closeWhileHandlingException(this); + } + } } @Override @@ -146,7 +154,18 @@ class DiskDocValuesConsumer extends DocValuesConsumer { public void close() throws IOException { // nocommit: just write this to a RAMfile or something and flush it here, with #fields first. // this meta is a tiny file so this hurts nobody - meta.writeVInt(-1); - IOUtils.close(data, meta); + boolean success = false; + try { + if (meta != null) { + meta.writeVInt(-1); + } + success = true; + } finally { + if (success) { + IOUtils.close(data, meta); + } else { + IOUtils.closeWhileHandlingException(data, meta); + } + } } } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnDiskFull.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnDiskFull.java index 401f5fb9274..184a0c2fa94 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnDiskFull.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnDiskFull.java @@ -24,6 +24,7 @@ import org.apache.lucene.codecs.LiveDocsFormat; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.LongDocValuesField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.search.IndexSearcher; @@ -558,6 +559,7 @@ public class TestIndexWriterOnDiskFull extends LuceneTestCase { { Document doc = new Document(); doc.add(newTextField("content", "aaa", Field.Store.NO)); + doc.add(new LongDocValuesField("numericdv", 1)); writer.addDocument(doc); } @@ -566,6 +568,7 @@ public class TestIndexWriterOnDiskFull extends LuceneTestCase { Document doc = new Document(); doc.add(newTextField("content", "aaa " + index, Field.Store.NO)); doc.add(newTextField("id", "" + index, Field.Store.NO)); + doc.add(new LongDocValuesField("numericdv", 1)); writer.addDocument(doc); } }