Skip to content

Apache Lucene open-source search software

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

Michael McCandless04c8590b8019
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 181fb3681eb..82d6001beec 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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
diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.java
index 2833f6533df..855d4fe8d09 100644
--- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java
@@ -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) {
- writeLock.release();
- writeLock = null;
- throw 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;
+ }
}
}