mirror of https://github.com/apache/lucene.git
LUCENE-978: ensure all streams are closed when we hit exception in constructor
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@567253 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
06d4849ca8
commit
c1a76d9dbe
|
@ -72,6 +72,10 @@ Bug fixes
|
|||
sharing an index over NFS and using a custom deletion policy (Mike
|
||||
McCandless)
|
||||
|
||||
11. LUCENE-978: Ensure TermInfosReader, FieldsReader, and FieldsReader
|
||||
close any streams they had opened if an exception is hit in the
|
||||
constructor. (Ning Li via Mike McCandless)
|
||||
|
||||
New features
|
||||
|
||||
1. LUCENE-906: Elision filter for French.
|
||||
|
|
|
@ -66,6 +66,9 @@ final class FieldsReader {
|
|||
}
|
||||
|
||||
FieldsReader(Directory d, String segment, FieldInfos fn, int readBufferSize, int docStoreOffset, int size) throws IOException {
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
fieldInfos = fn;
|
||||
|
||||
cloneableFieldsStream = d.openInput(segment + ".fdt", readBufferSize);
|
||||
|
@ -84,6 +87,18 @@ final class FieldsReader {
|
|||
this.docStoreOffset = 0;
|
||||
this.size = (int) (indexStream.length() >> 3);
|
||||
}
|
||||
|
||||
success = true;
|
||||
} finally {
|
||||
// With lock-less commits, it's entirely possible (and
|
||||
// fine) to hit a FileNotFound exception above. In
|
||||
// this case, we want to explicitly close any subset
|
||||
// of things that were opened so that we don't have to
|
||||
// wait for a GC to do so.
|
||||
if (!success) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,9 +118,15 @@ final class FieldsReader {
|
|||
*/
|
||||
final void close() throws IOException {
|
||||
if (!closed) {
|
||||
if (fieldsStream != null) {
|
||||
fieldsStream.close();
|
||||
}
|
||||
if (cloneableFieldsStream != null) {
|
||||
cloneableFieldsStream.close();
|
||||
}
|
||||
if (indexStream != null) {
|
||||
indexStream.close();
|
||||
}
|
||||
IndexInput localFieldsStream = (IndexInput) fieldsStreamTL.get();
|
||||
if (localFieldsStream != null) {
|
||||
localFieldsStream.close();
|
||||
|
|
|
@ -48,17 +48,31 @@ final class TermInfosReader {
|
|||
|
||||
TermInfosReader(Directory dir, String seg, FieldInfos fis, int readBufferSize)
|
||||
throws CorruptIndexException, IOException {
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
directory = dir;
|
||||
segment = seg;
|
||||
fieldInfos = fis;
|
||||
|
||||
origEnum = new SegmentTermEnum(directory.openInput(segment + ".tis", readBufferSize),
|
||||
fieldInfos, false);
|
||||
origEnum = new SegmentTermEnum(directory.openInput(segment + ".tis",
|
||||
readBufferSize), fieldInfos, false);
|
||||
size = origEnum.size;
|
||||
|
||||
indexEnum =
|
||||
new SegmentTermEnum(directory.openInput(segment + ".tii", readBufferSize),
|
||||
fieldInfos, true);
|
||||
indexEnum = new SegmentTermEnum(directory.openInput(segment + ".tii",
|
||||
readBufferSize), fieldInfos, true);
|
||||
|
||||
success = true;
|
||||
} finally {
|
||||
// With lock-less commits, it's entirely possible (and
|
||||
// fine) to hit a FileNotFound exception above. In
|
||||
// this case, we want to explicitly close any subset
|
||||
// of things that were opened so that we don't have to
|
||||
// wait for a GC to do so.
|
||||
if (!success) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getSkipInterval() {
|
||||
|
|
|
@ -53,6 +53,9 @@ class TermVectorsReader implements Cloneable {
|
|||
|
||||
TermVectorsReader(Directory d, String segment, FieldInfos fieldInfos, int readBufferSize, int docStoreOffset, int size)
|
||||
throws CorruptIndexException, IOException {
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
if (d.fileExists(segment + TermVectorsWriter.TVX_EXTENSION)) {
|
||||
tvx = d.openInput(segment + TermVectorsWriter.TVX_EXTENSION, readBufferSize);
|
||||
checkValidFormat(tvx);
|
||||
|
@ -73,6 +76,17 @@ class TermVectorsReader implements Cloneable {
|
|||
}
|
||||
|
||||
this.fieldInfos = fieldInfos;
|
||||
success = true;
|
||||
} finally {
|
||||
// With lock-less commits, it's entirely possible (and
|
||||
// fine) to hit a FileNotFound exception above. In
|
||||
// this case, we want to explicitly close any subset
|
||||
// of things that were opened so that we don't have to
|
||||
// wait for a GC to do so.
|
||||
if (!success) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int checkValidFormat(IndexInput in) throws CorruptIndexException, IOException
|
||||
|
|
Loading…
Reference in New Issue