LUCENE-2476: release write lock on any exception during IndexWriter ctor

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@948082 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2010-05-25 16:05:03 +00:00
parent 7baa7b17ac
commit 04c8590b80
2 changed files with 21 additions and 4 deletions

View File

@ -402,6 +402,10 @@ Bug fixes
demo resulted in ArrayIndexOutOfBoundsException.
(Sami Siren via Robert Muir)
* LUCENE-2476: If any exception is hit init'ing IW, release the write
lock (previously we only released on IOException). (Tamas Cservenak
via Mike McCandless)
New features
* LUCENE-2128: Parallelized fetching document frequencies during weight

View File

@ -1110,9 +1110,12 @@ public class IndexWriter implements Closeable {
}
writeLock = directory.makeLock(WRITE_LOCK_NAME);
if (!writeLock.obtain(writeLockTimeout)) // obtain write lock
throw new LockObtainFailedException("Index locked for write: " + writeLock);
boolean success = false;
try {
if (create) {
// Try to read first. This is to allow create
@ -1179,10 +1182,20 @@ public class IndexWriter implements Closeable {
messageState();
}
} catch (IOException e) {
success = true;
} finally {
if (!success) {
if (infoStream != null) {
message("init: hit exception on init; releasing write lock");
}
try {
writeLock.release();
} catch (Throwable t) {
// don't mask the original exception
}
writeLock = null;
throw e;
}
}
}