mirror of https://github.com/apache/lucene.git
LUCENE-768: make sure IndexReader.close releases write lock even after hitting an exception in one of the methods that acquire the write lock
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@494492 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ceaa0c3091
commit
853c03ac43
|
@ -295,6 +295,11 @@ Bug fixes
|
|||
in mergeSegments, when the corrupted segment is merged with
|
||||
segment(s) after it. (Mike McCandless)
|
||||
|
||||
30. LUCENE-768: Fix case where an Exception during deleteDocument,
|
||||
undeleteAll or setNorm in IndexReader could leave the reader in a
|
||||
state where close() fails to release the write lock.
|
||||
(Mike McCandless)
|
||||
|
||||
Optimizations
|
||||
|
||||
1. LUCENE-586: TermDocs.skipTo() is now more efficient for
|
||||
|
|
|
@ -425,8 +425,8 @@ public abstract class IndexReader {
|
|||
throws IOException{
|
||||
if(directoryOwner)
|
||||
aquireWriteLock();
|
||||
doSetNorm(doc, field, value);
|
||||
hasChanges = true;
|
||||
doSetNorm(doc, field, value);
|
||||
}
|
||||
|
||||
/** Implements setNorm in subclass.*/
|
||||
|
@ -580,8 +580,8 @@ public abstract class IndexReader {
|
|||
public final synchronized void undeleteAll() throws IOException{
|
||||
if(directoryOwner)
|
||||
aquireWriteLock();
|
||||
doUndeleteAll();
|
||||
hasChanges = true;
|
||||
doUndeleteAll();
|
||||
}
|
||||
|
||||
/** Implements actual undeleteAll() in subclass. */
|
||||
|
|
|
@ -789,6 +789,38 @@ public class TestIndexReader extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
public void testExceptionReleaseWriteLockJIRA768() throws IOException {
|
||||
|
||||
Directory dir = new RAMDirectory();
|
||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
addDoc(writer, "aaa");
|
||||
writer.close();
|
||||
|
||||
IndexReader reader = IndexReader.open(dir);
|
||||
try {
|
||||
reader.deleteDocument(1);
|
||||
fail("did not hit exception when deleting an invalid doc number");
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
reader.close();
|
||||
if (IndexReader.isLocked(dir)) {
|
||||
fail("write lock is still held after close");
|
||||
}
|
||||
|
||||
reader = IndexReader.open(dir);
|
||||
try {
|
||||
reader.setNorm(1, "content", (float) 2.0);
|
||||
fail("did not hit exception when calling setNorm on an invalid doc number");
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
reader.close();
|
||||
if (IndexReader.isLocked(dir)) {
|
||||
fail("write lock is still held after close");
|
||||
}
|
||||
}
|
||||
|
||||
private String arrayToString(String[] l) {
|
||||
String s = "";
|
||||
for(int i=0;i<l.length;i++) {
|
||||
|
|
Loading…
Reference in New Issue