mirror of https://github.com/apache/lucene.git
LUCENE-1715: null out a few things on closing SegmentReader; remove finalizers from Lucene's core
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@788319 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1e61831f8a
commit
9e49053ec1
13
CHANGES.txt
13
CHANGES.txt
|
@ -116,7 +116,18 @@ Changes in runtime behavior
|
|||
deleted. You can call IndexReader.isDeleted(n) prior to calling document(n).
|
||||
(Shai Erera via Mike McCandless)
|
||||
|
||||
API Changes
|
||||
8. LUCENE-1715: Finalizers have been removed from the 4 core classes
|
||||
that still had them, since they will cause GC to take longer, thus
|
||||
tying up memory for longer, and at best they mask buggy app code.
|
||||
DirectoryReader (returned from IndexReader.open) & IndexWriter
|
||||
previously released the write lock during finalize.
|
||||
SimpleFSDirectory.FSIndexInput closed the descriptor in its
|
||||
finalizer, and NativeFSLock released the lock. It's possible
|
||||
applications will be affected by this, but only if the application
|
||||
is failing to close reader/writers. (Brian Groose via Mike
|
||||
McCandless)
|
||||
|
||||
API Changes
|
||||
|
||||
1. LUCENE-1419: Add expert API to set custom indexing chain. This API is
|
||||
package-protected for now, so we don't have to officially support it.
|
||||
|
|
|
@ -794,6 +794,7 @@ class DirectoryReader extends IndexReader implements Cloneable {
|
|||
|
||||
protected synchronized void doClose() throws IOException {
|
||||
IOException ioe = null;
|
||||
normsCache = null;
|
||||
for (int i = 0; i < subReaders.length; i++) {
|
||||
// try to close each reader, even if an exception is thrown
|
||||
try {
|
||||
|
|
|
@ -745,6 +745,8 @@ class SegmentReader extends IndexReader implements Cloneable {
|
|||
|
||||
if (deletedDocs != null) {
|
||||
deletedDocsRef.decRef();
|
||||
// null so if an app hangs on to us we still free most ram
|
||||
deletedDocs = null;
|
||||
}
|
||||
|
||||
Iterator it = norms.values().iterator();
|
||||
|
@ -757,6 +759,8 @@ class SegmentReader extends IndexReader implements Cloneable {
|
|||
// close everything, nothing is shared anymore with other readers
|
||||
if (tis != null) {
|
||||
tis.close();
|
||||
// null so if an app hangs on to us we still free most ram
|
||||
tis = null;
|
||||
}
|
||||
|
||||
if (freqStream != null)
|
||||
|
|
|
@ -319,14 +319,4 @@ class NativeFSLock extends Lock {
|
|||
public String toString() {
|
||||
return "NativeFSLock@" + path;
|
||||
}
|
||||
|
||||
public void finalize() throws Throwable {
|
||||
try {
|
||||
if (isLocked()) {
|
||||
release();
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,14 +85,6 @@ public class SimpleFSDirectory extends FSDirectory {
|
|||
super.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
close();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected final Descriptor file;
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.apache.lucene.store.FSDirectory;
|
|||
import org.apache.lucene.store.MockRAMDirectory;
|
||||
import org.apache.lucene.store.AlreadyClosedException;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.BitVector;
|
||||
|
||||
public class TestIndexReaderReopen extends LuceneTestCase {
|
||||
|
||||
|
@ -1214,10 +1215,11 @@ public class TestIndexReaderReopen extends LuceneTestCase {
|
|||
|
||||
// At this point they share the same BitVector
|
||||
assertTrue(sr1.deletedDocs==sr2.deletedDocs);
|
||||
final BitVector delDocs = sr1.deletedDocs;
|
||||
r1.close();
|
||||
|
||||
r2.deleteDocument(0);
|
||||
assertTrue(sr1.deletedDocs==sr2.deletedDocs);
|
||||
assertTrue(delDocs==sr2.deletedDocs);
|
||||
r2.close();
|
||||
dir.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue