LUCENE-3404: fix cases where we were incorrectly passing true as first arg to IOUtils.closeSafely

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1162375 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2011-08-27 15:15:01 +00:00
parent 4dad0ba89f
commit ce5a9a107f
7 changed files with 46 additions and 39 deletions

View File

@ -87,7 +87,7 @@ final class DocFieldProcessor extends DocConsumer {
consumers.finish(state.numDocs);
};
// close perDocConsumer during flush to ensure all files are flushed due to PerCodec CFS
IOUtils.closeSafely(true, perDocConsumers.values());
IOUtils.closeSafely(false, perDocConsumers.values());
}
@Override

View File

@ -2606,7 +2606,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
}
}
} finally {
IOUtils.closeSafely(true, cfsdir);
IOUtils.closeSafely(false, cfsdir);
}
info.dir = directory;

View File

@ -104,41 +104,39 @@ class FixedStraightBytesImpl {
datOut = getDataOut();
boolean success = false;
try {
if (state.liveDocs == null && state.reader instanceof Reader) {
Reader reader = (Reader) state.reader;
final int maxDocs = reader.maxDoc;
if (maxDocs == 0) {
return;
}
if (size == -1) {
size = reader.size;
datOut.writeInt(size);
}
if (lastDocID+1 < state.docBase) {
fill(datOut, state.docBase);
lastDocID = state.docBase-1;
}
// TODO should we add a transfer to API to each reader?
final IndexInput cloneData = reader.cloneData();
try {
datOut.copyBytes(cloneData, size * maxDocs);
} finally {
IOUtils.closeSafely(true, cloneData);
}
if (state.liveDocs == null && state.reader instanceof Reader) {
Reader reader = (Reader) state.reader;
final int maxDocs = reader.maxDoc;
if (maxDocs == 0) {
return;
}
if (size == -1) {
size = reader.size;
datOut.writeInt(size);
}
if (lastDocID+1 < state.docBase) {
fill(datOut, state.docBase);
lastDocID = state.docBase-1;
}
// TODO should we add a transfer to API to each reader?
final IndexInput cloneData = reader.cloneData();
try {
datOut.copyBytes(cloneData, size * maxDocs);
} finally {
IOUtils.closeSafely(false, cloneData);
}
lastDocID += maxDocs;
} else {
super.merge(state);
}
success = true;
lastDocID += maxDocs;
} else {
super.merge(state);
}
success = true;
} finally {
if (!success) {
IOUtils.closeSafely(!success, datOut);
}
}
}
@Override
protected void mergeDoc(int docID) throws IOException {

View File

@ -128,13 +128,13 @@ class VarStraightBytesImpl {
address += numDataBytes; // this is the address after all addr pointers are updated
iter.close();
} finally {
IOUtils.closeSafely(true, cloneIdx);
IOUtils.closeSafely(false, cloneIdx);
}
final IndexInput cloneData = reader.cloneData();
try {
datOut.copyBytes(cloneData, numDataBytes);
} finally {
IOUtils.closeSafely(true, cloneData);
IOUtils.closeSafely(false, cloneData);
}
} else {
super.merge(state);

View File

@ -95,10 +95,10 @@ public final class CompoundFileDirectory extends Directory {
if (firstInt == CompoundFileWriter.FORMAT_CURRENT) {
IndexInput input = null;
try {
input = dir.openInput(IndexFileNames.segmentFileName(
IndexFileNames.stripExtension(name), "",
IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION),
IOContext.READONCE);
final String entriesFileName = IndexFileNames.segmentFileName(
IndexFileNames.stripExtension(name), "",
IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION);
input = dir.openInput(entriesFileName, IOContext.READONCE);
final int readInt = input.readInt(); // unused right now
assert readInt == CompoundFileWriter.ENTRY_FORMAT_CURRENT;
final int numEntries = input.readVInt();
@ -112,7 +112,7 @@ public final class CompoundFileDirectory extends Directory {
}
return mapping;
} finally {
IOUtils.closeSafely(true, input);
IOUtils.closeSafely(false, input);
}
} else {
// TODO remove once 3.x is not supported anymore

View File

@ -153,7 +153,10 @@ public class MockDirectoryWrapper extends Directory {
@Override
public String toString() {
maybeYield();
// NOTE: do not maybeYield here, since it consumes
// randomness and can thus (unexpectedly during
// debugging) change the behavior of a seed
// maybeYield();
return "MockDirWrapper(" + delegate + ")";
}

View File

@ -132,7 +132,13 @@ public class TestIndexWriterOnDiskFull extends LuceneTestCase {
}
}
}
// TODO: make @Nightly variant that provokes more disk
// fulls
// TODO: have test fail if on any given top
// iter there was not a single IOE hit
/*
Test: make sure when we run out of disk space or hit
random IOExceptions in any of the addIndexes(*) calls