mirror of https://github.com/apache/lucene.git
fix a few cases where we fail to close IO if we hit exc during init
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1203398 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9e27723b37
commit
74076d2ce8
|
@ -112,12 +112,8 @@ final class DocFieldProcessor extends DocConsumer {
|
|||
field = next;
|
||||
}
|
||||
}
|
||||
try {
|
||||
IOUtils.closeWhileHandlingException(perDocConsumers.values());
|
||||
// TODO add abort to PerDocConsumer!
|
||||
} catch (IOException e) {
|
||||
// ignore on abort!
|
||||
}
|
||||
IOUtils.closeWhileHandlingException(perDocConsumers.values());
|
||||
// TODO add abort to PerDocConsumer!
|
||||
|
||||
try {
|
||||
fieldsWriter.abort();
|
||||
|
|
|
@ -26,8 +26,8 @@ import java.util.List;
|
|||
|
||||
import org.apache.lucene.index.CorruptIndexException;
|
||||
import org.apache.lucene.index.DocsEnum;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.apache.lucene.index.IndexFileNames;
|
||||
import org.apache.lucene.index.SegmentWriteState;
|
||||
import org.apache.lucene.index.codecs.PostingsWriterBase;
|
||||
|
@ -36,6 +36,7 @@ import org.apache.lucene.store.IndexOutput;
|
|||
import org.apache.lucene.store.RAMOutputStream;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.CodecUtil;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
|
||||
/** @lucene.experimental */
|
||||
public final class Lucene40PostingsWriter extends PostingsWriterBase {
|
||||
|
@ -92,14 +93,22 @@ public final class Lucene40PostingsWriter extends PostingsWriterBase {
|
|||
// this.segment = state.segmentName;
|
||||
String fileName = IndexFileNames.segmentFileName(state.segmentName, state.segmentSuffix, Lucene40PostingsFormat.FREQ_EXTENSION);
|
||||
freqOut = state.directory.createOutput(fileName, state.context);
|
||||
if (state.fieldInfos.hasProx()) {
|
||||
// At least one field does not omit TF, so create the
|
||||
// prox file
|
||||
fileName = IndexFileNames.segmentFileName(state.segmentName, state.segmentSuffix, Lucene40PostingsFormat.PROX_EXTENSION);
|
||||
proxOut = state.directory.createOutput(fileName, state.context);
|
||||
} else {
|
||||
// Every field omits TF so we will write no prox file
|
||||
proxOut = null;
|
||||
boolean success = false;
|
||||
try {
|
||||
if (state.fieldInfos.hasProx()) {
|
||||
// At least one field does not omit TF, so create the
|
||||
// prox file
|
||||
fileName = IndexFileNames.segmentFileName(state.segmentName, state.segmentSuffix, Lucene40PostingsFormat.PROX_EXTENSION);
|
||||
proxOut = state.directory.createOutput(fileName, state.context);
|
||||
} else {
|
||||
// Every field omits TF so we will write no prox file
|
||||
proxOut = null;
|
||||
}
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
IOUtils.closeWhileHandlingException(freqOut);
|
||||
}
|
||||
}
|
||||
|
||||
totalNumDocs = state.numDocs;
|
||||
|
|
|
@ -151,7 +151,6 @@ public final class SepPostingsWriter extends PostingsWriterBase {
|
|||
if (!success) {
|
||||
IOUtils.closeWhileHandlingException(docOut, skipOut, freqOut, posOut, payloadOut);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ public final class IOUtils {
|
|||
* @param objects
|
||||
* objects to call <tt>close()</tt> on
|
||||
*/
|
||||
public static void closeWhileHandlingException(Closeable... objects) throws IOException {
|
||||
public static void closeWhileHandlingException(Closeable... objects) {
|
||||
for (Closeable object : objects) {
|
||||
try {
|
||||
if (object != null) {
|
||||
|
@ -204,7 +204,7 @@ public final class IOUtils {
|
|||
/**
|
||||
* @see #closeWhileHandlingException(Closeable...)
|
||||
*/
|
||||
public static void closeWhileHandlingException(Iterable<? extends Closeable> objects) throws IOException {
|
||||
public static void closeWhileHandlingException(Iterable<? extends Closeable> objects) {
|
||||
for (Closeable object : objects) {
|
||||
try {
|
||||
if (object != null) {
|
||||
|
|
|
@ -50,15 +50,31 @@ class PreFlexFieldsWriter extends FieldsConsumer {
|
|||
state.fieldInfos,
|
||||
state.termIndexInterval);
|
||||
|
||||
final String freqFile = IndexFileNames.segmentFileName(state.segmentName, "", Lucene3xPostingsFormat.FREQ_EXTENSION);
|
||||
freqOut = state.directory.createOutput(freqFile, state.context);
|
||||
totalNumDocs = state.numDocs;
|
||||
boolean success = false;
|
||||
try {
|
||||
final String freqFile = IndexFileNames.segmentFileName(state.segmentName, "", Lucene3xPostingsFormat.FREQ_EXTENSION);
|
||||
freqOut = state.directory.createOutput(freqFile, state.context);
|
||||
totalNumDocs = state.numDocs;
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
IOUtils.closeWhileHandlingException(termsOut);
|
||||
}
|
||||
}
|
||||
|
||||
if (state.fieldInfos.hasProx()) {
|
||||
final String proxFile = IndexFileNames.segmentFileName(state.segmentName, "", Lucene3xPostingsFormat.PROX_EXTENSION);
|
||||
proxOut = state.directory.createOutput(proxFile, state.context);
|
||||
} else {
|
||||
proxOut = null;
|
||||
success = false;
|
||||
try {
|
||||
if (state.fieldInfos.hasProx()) {
|
||||
final String proxFile = IndexFileNames.segmentFileName(state.segmentName, "", Lucene3xPostingsFormat.PROX_EXTENSION);
|
||||
proxOut = state.directory.createOutput(proxFile, state.context);
|
||||
} else {
|
||||
proxOut = null;
|
||||
}
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
IOUtils.closeWhileHandlingException(termsOut, freqOut);
|
||||
}
|
||||
}
|
||||
|
||||
skipListWriter = new DefaultSkipListWriter(termsOut.skipInterval,
|
||||
|
|
|
@ -92,17 +92,12 @@ final class TermInfosWriter implements Closeable {
|
|||
initialize(directory, segment, fis, interval, false);
|
||||
boolean success = false;
|
||||
try {
|
||||
other = new TermInfosWriter(directory, segment, fis, interval, true);
|
||||
other.other = this;
|
||||
other = new TermInfosWriter(directory, segment, fis, interval, true);
|
||||
other.other = this;
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
try {
|
||||
IOUtils.closeWhileHandlingException(output);
|
||||
} catch (IOException e) {
|
||||
// cannot happen since we suppress exceptions
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
IOUtils.closeWhileHandlingException(output);
|
||||
|
||||
try {
|
||||
directory.deleteFile(IndexFileNames.segmentFileName(segment, "",
|
||||
|
@ -129,21 +124,16 @@ final class TermInfosWriter implements Closeable {
|
|||
: Lucene3xPostingsFormat.TERMS_EXTENSION)), IOContext.DEFAULT);
|
||||
boolean success = false;
|
||||
try {
|
||||
output.writeInt(FORMAT_CURRENT); // write format
|
||||
output.writeLong(0); // leave space for size
|
||||
output.writeInt(indexInterval); // write indexInterval
|
||||
output.writeInt(skipInterval); // write skipInterval
|
||||
output.writeInt(maxSkipLevels); // write maxSkipLevels
|
||||
assert initUTF16Results();
|
||||
output.writeInt(FORMAT_CURRENT); // write format
|
||||
output.writeLong(0); // leave space for size
|
||||
output.writeInt(indexInterval); // write indexInterval
|
||||
output.writeInt(skipInterval); // write skipInterval
|
||||
output.writeInt(maxSkipLevels); // write maxSkipLevels
|
||||
assert initUTF16Results();
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
try {
|
||||
IOUtils.closeWhileHandlingException(output);
|
||||
} catch (IOException e) {
|
||||
// cannot happen since we suppress exceptions
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
IOUtils.closeWhileHandlingException(output);
|
||||
|
||||
try {
|
||||
directory.deleteFile(IndexFileNames.segmentFileName(segment, "",
|
||||
|
|
|
@ -37,8 +37,9 @@ public class TestTransactions extends LuceneTestCase {
|
|||
private class RandomFailure extends MockDirectoryWrapper.Failure {
|
||||
@Override
|
||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||
if (TestTransactions.doFail && random.nextInt() % 10 <= 3)
|
||||
if (TestTransactions.doFail && random.nextInt() % 10 <= 3) {
|
||||
throw new IOException("now failing randomly but on purpose");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue