LUCENE-5611: lazy-init the stored fields writer like before to prevent leaks

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1591807 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-05-02 02:48:40 +00:00
parent ccccb0b377
commit 9839ad461e
2 changed files with 12 additions and 5 deletions

View File

@ -51,7 +51,8 @@ final class DefaultIndexingChain extends DocConsumer {
// Writes postings and term vectors:
final TermsHash termsHash;
final StoredFieldsWriter storedFieldsWriter;
// lazy init:
private StoredFieldsWriter storedFieldsWriter;
private int lastStoredDocID;
// NOTE: I tried using Hash Map<String,PerField>
@ -75,12 +76,16 @@ final class DefaultIndexingChain extends DocConsumer {
this.docState = docWriter.docState;
this.bytesUsed = docWriter.bytesUsed;
// Writes stored fields:
storedFieldsWriter = docWriter.codec.storedFieldsFormat().fieldsWriter(docWriter.directory, docWriter.getSegmentInfo(), IOContext.DEFAULT);
TermsHash termVectorsWriter = new TermVectorsConsumer(docWriter);
termsHash = new FreqProxTermsWriter(docWriter, termVectorsWriter);
}
// TODO: can we remove this lazy-init / make cleaner / do it another way...?
private void initStoredFieldsWriter() throws IOException {
if (storedFieldsWriter == null) {
storedFieldsWriter = docWriter.codec.storedFieldsFormat().fieldsWriter(docWriter.directory, docWriter.getSegmentInfo(), IOContext.DEFAULT);
}
}
@Override
public void flush(SegmentWriteState state) throws IOException {
@ -92,6 +97,8 @@ final class DefaultIndexingChain extends DocConsumer {
writeNorms(state);
writeDocValues(state);
// its possible all docs hit non-aborting exceptions...
initStoredFieldsWriter();
fillStoredFields(numDocs);
storedFieldsWriter.finish(state.fieldInfos, numDocs);
storedFieldsWriter.close();
@ -246,6 +253,7 @@ final class DefaultIndexingChain extends DocConsumer {
private void startStoredFields() throws IOException {
boolean success = false;
try {
initStoredFieldsWriter();
storedFieldsWriter.startDocument();
success = true;
} finally {

View File

@ -2188,7 +2188,6 @@ public class TestIndexWriter extends LuceneTestCase {
IOUtils.close(reader, dir);
}
@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/LUCENE-5611")
public void testIterableThrowsException2() throws IOException {
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(