diff --git a/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java b/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java index 3281afb6f94..5fc4c38eef5 100644 --- a/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java +++ b/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java @@ -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 getIndexWriter(SolrCore core) + public RefCounted 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"); } } diff --git a/solr/core/src/java/org/apache/solr/update/SolrCoreState.java b/solr/core/src/java/org/apache/solr/update/SolrCoreState.java index 850d739dd20..12483736cff 100644 --- a/solr/core/src/java/org/apache/solr/update/SolrCoreState.java +++ b/solr/core/src/java/org/apache/solr/update/SolrCoreState.java @@ -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); } } }