SOLR-4505: Possible deadlock around SolrCoreState update lock.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1451653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-03-01 17:24:47 +00:00
parent 202d3af9d0
commit 709824acf8
2 changed files with 19 additions and 29 deletions

View File

@ -61,7 +61,7 @@ public final class DefaultSolrCoreState extends SolrCoreState implements Recover
this.directoryFactory = directoryFactory;
}
private synchronized void closeIndexWriter(IndexWriterCloser closer) {
private void closeIndexWriter(IndexWriterCloser closer) {
try {
log.info("SolrCoreState ref count has reached 0 - closing IndexWriter");
if (closer != null) {
@ -77,7 +77,7 @@ public final class DefaultSolrCoreState extends SolrCoreState implements Recover
}
@Override
public synchronized RefCounted<IndexWriter> getIndexWriter(SolrCore core)
public RefCounted<IndexWriter> getIndexWriter(SolrCore core)
throws IOException {
if (closed) {
@ -141,25 +141,13 @@ public final class DefaultSolrCoreState extends SolrCoreState implements Recover
// then lets wait until its out of use
log.info("Waiting until IndexWriter is unused... core=" + coreName);
boolean yieldedCommitLock = false;
try {
if (commitLock.isHeldByCurrentThread()) {
yieldedCommitLock = true;
commitLock.unlock();
}
while (!writerFree) {
try {
writerPauseLock.wait(100);
} catch (InterruptedException e) {}
while (!writerFree) {
try {
writerPauseLock.wait(100);
} catch (InterruptedException e) {}
if (closed) {
throw new RuntimeException("SolrCoreState already closed");
}
}
} finally {
if (yieldedCommitLock) {
commitLock.lock();
if (closed) {
throw new RuntimeException("SolrCoreState already closed");
}
}

View File

@ -59,18 +59,20 @@ public abstract class SolrCoreState {
}
public void decrefSolrCoreState(IndexWriterCloser closer) {
boolean close = false;
synchronized (this) {
solrCoreStateRefCnt--;
if (solrCoreStateRefCnt == 0) {
try {
log.info("Closing SolrCoreState");
close(closer);
} catch (Throwable t) {
log.error("Error closing SolrCoreState", t);
}
close = true;
}
}
if (close) {
try {
log.info("Closing SolrCoreState");
close(closer);
} catch (Throwable t) {
log.error("Error closing SolrCoreState", t);
}
}
}