From 74037691e64c8db7d95b73eb7489c2ba3f8965b0 Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Mon, 27 Feb 2012 02:52:49 +0000 Subject: [PATCH] do not hold the cores lock while calling cancel on recovery git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1294004 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/core/CoreContainer.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index 4f5b4895984..bb33a3fa6e7 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -66,6 +66,7 @@ import org.apache.solr.handler.admin.CoreAdminHandler; import org.apache.solr.handler.component.HttpShardHandlerFactory; import org.apache.solr.handler.component.ShardHandlerFactory; import org.apache.solr.schema.IndexSchema; +import org.apache.solr.update.SolrCoreState; import org.apache.zookeeper.KeeperException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -485,14 +486,16 @@ public class CoreContainer * Stops all cores. */ public void shutdown() { - log.info("Shutting down CoreContainer instance="+System.identityHashCode(this)); + log.info("Shutting down CoreContainer instance="+System.identityHashCode(this)); + if (isZooKeeperAware()) { + cancelCoreRecoveries(); + } + synchronized(cores) { try { for (SolrCore core : cores.values()) { try { core.close(); - // make sure we wait for any recoveries to stop - core.getUpdateHandler().getSolrCoreState().cancelRecovery(); } catch (Throwable t) { SolrException.log(log, "Error shutting down core", t); } @@ -512,6 +515,28 @@ public class CoreContainer } } } + + private void cancelCoreRecoveries() { + ArrayList coreStates = null; + synchronized (cores) { + for (SolrCore core : cores.values()) { + try { + coreStates = new ArrayList(cores.size()); + // make sure we wait for any recoveries to stop + coreStates.add(core.getUpdateHandler().getSolrCoreState()); + } catch (Throwable t) { + SolrException.log(log, "Error canceling recovery for core", t); + } + } + } + + // we must cancel without holding the cores sync + if (coreStates != null) { + for (SolrCoreState coreState : coreStates) { + coreState.cancelRecovery(); + } + } + } @Override protected void finalize() throws Throwable {