mirror of https://github.com/apache/lucene.git
LUCENE-669: don't double-close RandomAccessFile in finalize
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@480785 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
16d9dc0f49
commit
2b39422870
|
@ -230,6 +230,12 @@ Bug fixes
|
||||||
classes from contrib/similarity, as their new home is under
|
classes from contrib/similarity, as their new home is under
|
||||||
contrib/queries.
|
contrib/queries.
|
||||||
|
|
||||||
|
25. LUCENE-669: Do not double-close the RandomAccessFile in
|
||||||
|
FSIndexInput/Output during finalize(). Besides sending an
|
||||||
|
IOException up to the GC, this may also be the cause intermittent
|
||||||
|
"The handle is invalid" IOExceptions on Windows when trying to
|
||||||
|
close readers or writers.
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
|
|
||||||
1. LUCENE-586: TermDocs.skipTo() is now more efficient for
|
1. LUCENE-586: TermDocs.skipTo() is now more efficient for
|
||||||
|
|
|
@ -504,11 +504,17 @@ class FSIndexInput extends BufferedIndexInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Descriptor file = null;
|
private Descriptor file = null;
|
||||||
|
|
||||||
|
// remember if the file is open, so that we don't try to close it
|
||||||
|
// more than once
|
||||||
|
private boolean isOpen;
|
||||||
|
|
||||||
boolean isClone;
|
boolean isClone;
|
||||||
private long length;
|
private long length;
|
||||||
|
|
||||||
public FSIndexInput(File path) throws IOException {
|
public FSIndexInput(File path) throws IOException {
|
||||||
file = new Descriptor(path, "r");
|
file = new Descriptor(path, "r");
|
||||||
|
isOpen = true;
|
||||||
length = file.length();
|
length = file.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,8 +539,12 @@ class FSIndexInput extends BufferedIndexInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
if (!isClone)
|
// only close the file if this is not a clone and the
|
||||||
|
// file has not been closed yet
|
||||||
|
if (!isClone && isOpen) {
|
||||||
file.close();
|
file.close();
|
||||||
|
isOpen = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void seekInternal(long position) {
|
protected void seekInternal(long position) {
|
||||||
|
@ -566,8 +576,13 @@ class FSIndexInput extends BufferedIndexInput {
|
||||||
class FSIndexOutput extends BufferedIndexOutput {
|
class FSIndexOutput extends BufferedIndexOutput {
|
||||||
RandomAccessFile file = null;
|
RandomAccessFile file = null;
|
||||||
|
|
||||||
|
// remember if the file is open, so that we don't try to close it
|
||||||
|
// more than once
|
||||||
|
private boolean isOpen;
|
||||||
|
|
||||||
public FSIndexOutput(File path) throws IOException {
|
public FSIndexOutput(File path) throws IOException {
|
||||||
file = new RandomAccessFile(path, "rw");
|
file = new RandomAccessFile(path, "rw");
|
||||||
|
isOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** output methods: */
|
/** output methods: */
|
||||||
|
@ -575,8 +590,12 @@ class FSIndexOutput extends BufferedIndexOutput {
|
||||||
file.write(b, 0, size);
|
file.write(b, 0, size);
|
||||||
}
|
}
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
// only close the file if it has not been closed yet
|
||||||
|
if (isOpen) {
|
||||||
super.close();
|
super.close();
|
||||||
file.close();
|
file.close();
|
||||||
|
isOpen = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Random-access methods */
|
/** Random-access methods */
|
||||||
|
@ -589,7 +608,7 @@ class FSIndexOutput extends BufferedIndexOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void finalize() throws IOException {
|
protected void finalize() throws IOException {
|
||||||
file.close(); // close the file
|
close(); // close the file
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue