From 0b55ddeedf221b3f85e45574dd51d9425fce8d3f Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 12 Sep 2011 19:18:05 +0000 Subject: [PATCH] LUCENE-3428: force DWPT unlock if unchecked exception is thrown by DWFC#addFlushableState git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1169877 13f79535-47bb-0310-9956-ffa450edef68 --- .../index/DocumentsWriterFlushControl.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java b/lucene/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java index 35a372cd95f..cdef910f570 100644 --- a/lucene/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java +++ b/lucene/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java @@ -366,15 +366,23 @@ public final class DocumentsWriterFlushControl { ThreadState obtainAndLock() { final ThreadState perThread = perThreadPool.getAndLock(Thread .currentThread(), documentsWriter); - if (perThread.isActive() - && perThread.perThread.deleteQueue != documentsWriter.deleteQueue) { - // There is a flush-all in process and this DWPT is - // now stale -- enroll it for flush and try for - // another DWPT: - addFlushableState(perThread); + boolean success = false; + try { + if (perThread.isActive() + && perThread.perThread.deleteQueue != documentsWriter.deleteQueue) { + // There is a flush-all in process and this DWPT is + // now stale -- enroll it for flush and try for + // another DWPT: + addFlushableState(perThread); + } + success = true; + // simply return the ThreadState even in a flush all case sine we already hold the lock + return perThread; + } finally { + if (!success) { // make sure we unlock if this fails + perThread.unlock(); + } } - // simply return the ThreadState even in a flush all case sine we already hold the lock - return perThread; } void markForFullFlush() {