Apache Lucene open-source search software
SOLR-4657, core left open during stress tests
Erick Erickson42b081cd5c70
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.javaindex 743d6a695df..e16bbea3f22 100644--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java@@ -1434,61 +1434,75 @@ class CoreMaps {}}- // We are shutting down. We don't want to risk deadlock, so do this manipulation the expensive way. Note, I've- // already deadlocked with closing/opening cores while keeping locks here....+ // We are shutting down. You can't hold the lock on the various lists of cores while they shut down, so we need to+ // make a temporary copy of the names and shut them down outside the lock.protected void clearMaps(ConfigSolr cfg) {List<String> coreNames;List<String> transientNames;List<SolrCore> pendingToClose;- synchronized (locker) {- coreNames = new ArrayList(cores.keySet());- transientNames = new ArrayList(transientCores.keySet());- pendingToClose = new ArrayList(pendingCloses);- }- for (String coreName : coreNames) {- SolrCore core = cores.get(coreName);- if (core != null) {- try {- addPersistOneCore(cfg, core, container.loader);- core.close();- } catch (Throwable t) {- SolrException.log(CoreContainer.log, "Error shutting down core", t);- } finally {- synchronized (locker) {- cores.remove(coreName);+ // It might be possible for one of the cores to move from one list to another while we're closing them. So+ // loop through the lists until they're all empty. In particular, the core could have moved from the transient+ // list to the pendingCloses list.++ while (true) {+ synchronized (locker) {+ coreNames = new ArrayList(cores.keySet());+ transientNames = new ArrayList(transientCores.keySet());+ pendingToClose = new ArrayList(pendingCloses);+ }++ if (coreNames.size() == 0 && transientNames.size() == 0 && pendingToClose.size() == 0) break;++ for (String coreName : coreNames) {+ SolrCore core = cores.get(coreName);+ if (core == null) {+ CoreContainer.log.info("Core " + coreName + " moved from core container list before closing.");+ } else {+ try {+ addPersistOneCore(cfg, core, container.loader);++ core.close();+ } catch (Throwable t) {+ SolrException.log(CoreContainer.log, "Error shutting down core", t);+ } finally {+ synchronized (locker) {+ cores.remove(coreName);+ }}}}- }- for (String coreName : transientNames) {- SolrCore core = transientCores.get(coreName);- if (core != null) {+ for (String coreName : transientNames) {+ SolrCore core = transientCores.get(coreName);+ if (core == null) {+ CoreContainer.log.info("Core " + coreName + " moved from transient core container list before closing.");+ } else {+ try {+ core.close();+ } catch (Throwable t) {+ SolrException.log(CoreContainer.log, "Error shutting down core", t);+ } finally {+ synchronized (locker) {+ transientCores.remove(coreName);+ }+ }+ }+ }++ // We might have some cores that we were _thinking_ about shutting down, so take care of those too.+ for (SolrCore core : pendingToClose) {try {core.close();} catch (Throwable t) {SolrException.log(CoreContainer.log, "Error shutting down core", t);} finally {synchronized (locker) {- transientCores.remove(coreName);+ pendingCloses.remove(core);}}}}-- // We might have some cores that we were _thinking_ about shutting down, so take care of those too.- for (SolrCore core : pendingToClose) {- try {- core.close();- } catch (Throwable t) {- SolrException.log(CoreContainer.log, "Error shutting down core", t);- } finally {- synchronized (locker) {- pendingCloses.remove(core);- }- }- }}protected void addCoresToList(ArrayList<SolrCoreState> coreStates) {