Apache Solr open-source search software
LUCENE-3462: Release lock in DocumentsWriterPerThreadPool if new state has been deactivated during close.
Simon Willnauerd607980a5ae3
diff --git a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.java b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.javaindex cf2a1653d08..eb6f20944d1 100644--- a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.java+++ b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.java@@ -186,13 +186,41 @@ public abstract class DocumentsWriterPerThreadPool {if (numThreadStatesActive < perThreads.length) {final ThreadState threadState = perThreads[numThreadStatesActive];threadState.lock(); // lock so nobody else will get this ThreadState- numThreadStatesActive++; // increment will publish the ThreadState- threadState.perThread.initialize();- return threadState;+ boolean unlock = true;+ try {+ if (threadState.isActive()) {+ // unreleased thread states are deactivated during DW#close()+ numThreadStatesActive++; // increment will publish the ThreadState+ assert threadState.perThread != null;+ threadState.perThread.initialize();+ unlock = false;+ return threadState;+ }+ // unlock since the threadstate is not active anymore - we are closed!+ assert assertUnreleasedThreadStatesInactive();+ return null;+ } finally {+ if (unlock) {+ // in any case make sure we unlock if we fail+ threadState.unlock();+ }+ }}return null;}+ private synchronized boolean assertUnreleasedThreadStatesInactive() {+ for (int i = numThreadStatesActive; i < perThreads.length; i++) {+ assert perThreads[i].tryLock() : "unreleased threadstate should not be locked";+ try {+ assert !perThreads[i].isActive() : "expected unreleased thread state to be inactive";+ } finally {+ perThreads[i].unlock();+ }+ }+ return true;+ }+/*** Deactivate all unreleased threadstates*/