From 97b40049d03edc018e358bc0b2e6c9073cddc7dd Mon Sep 17 00:00:00 2001 From: Grant Ingersoll Date: Thu, 8 Dec 2011 11:09:47 +0000 Subject: [PATCH] SOLR-1730: Hook in handling of bad cores, failure of QEC to load, add in test git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1211827 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/core/CoreContainer.java | 4 +- .../java/org/apache/solr/core/SolrCore.java | 9 ++-- .../component/QueryElevationComponent.java | 8 ++-- .../solr/servlet/SolrDispatchFilter.java | 2 +- .../solr/conf/solrconfig-elevate.xml | 30 ++++++++++++- .../handler/component/BadComponentTest.java | 43 +++++++++++++++++++ .../QueryElevationComponentTest.java | 9 +++- 7 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 solr/core/src/test/org/apache/solr/handler/component/BadComponentTest.java 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 c383b0b8801..a1ee272a7fc 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -215,7 +215,6 @@ public class CoreContainer } /** - * @exception generates an error if you attempt to set this value to false * @deprecated all cores now abort on configuration error regardless of configuration */ @Deprecated @@ -246,6 +245,9 @@ public class CoreContainer } solrConfigFilename = cores.getConfigFile().getName(); + if (cores.cores.isEmpty()){ + throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "No cores were created, please check the logs for errors"); + } return cores; } diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java index 3effc622d01..35f17491e1d 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -617,11 +617,14 @@ public final class SolrCore implements SolrInfoMBean { // Finally tell anyone who wants to know resourceLoader.inform( resourceLoader ); resourceLoader.inform( this ); // last call before the latch is released. - } catch (IOException e) { - log.error("", e); + } catch (Throwable e) { + log.error("Error in constructing the core", e); + latch.countDown();//release the latch, otherwise we block trying to do the close. This should be fine, since counting down on a latch of 0 is still fine + //close down the searcher and any other resources, if it exists, as this is not recoverable + close(); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, null, e, false); } finally { - // allow firstSearcher events to fire + // allow firstSearcher events to fire and make sure it is released latch.countDown(); } diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java index 0fee7ad6176..e0e66d0127e 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java @@ -199,7 +199,7 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore elevationCache.put(null, loadElevationMap( cfg )); } } - + //in other words, we think this is in the data dir, not the conf dir if (!exists){ // preload the first data RefCounted searchHolder = null; @@ -215,10 +215,10 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore } catch( Exception ex ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, - "Error initializing QueryElevationComponent.", ex ); + "Error initializing QueryElevationComponent.", ex, false ); } } - + //get the elevation map from the data dir Map getElevationMap( IndexReader reader, SolrCore core ) throws Exception { synchronized( elevationCache ) { @@ -242,7 +242,7 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore return map; } } - + //load up the elevation map private Map loadElevationMap( Config cfg ) throws IOException { XPath xpath = XPathFactory.newInstance().newXPath(); diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java index bf002811937..e4c0ff6c93c 100644 --- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java +++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java @@ -96,7 +96,7 @@ public class SolrDispatchFilter implements Filter } catch( Throwable t ) { // catch this so our filter still works - log.error( "Could not start Solr. Check solr/home property", t); + log.error( "Could not start Solr. Check solr/home property and the logs", t); SolrConfig.severeErrors.add( t ); SolrCore.log( t ); } diff --git a/solr/core/src/test-files/solr/conf/solrconfig-elevate.xml b/solr/core/src/test-files/solr/conf/solrconfig-elevate.xml index 63e0b0f2881..669cdd2f949 100644 --- a/solr/core/src/test-files/solr/conf/solrconfig-elevate.xml +++ b/solr/core/src/test-files/solr/conf/solrconfig-elevate.xml @@ -185,7 +185,17 @@ string - elevate.xml + ${elevate.file:elevate.xml} + + + + + + string + ${elevate.data.file:elevate-data.xml} @@ -197,6 +207,24 @@ + + + explicit + + + dataElevate + + + + + diff --git a/solr/core/src/test/org/apache/solr/handler/component/BadComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/BadComponentTest.java new file mode 100644 index 00000000000..9471162ebf1 --- /dev/null +++ b/solr/core/src/test/org/apache/solr/handler/component/BadComponentTest.java @@ -0,0 +1,43 @@ +package org.apache.solr.handler.component; + + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.common.SolrException; +import org.junit.Test; + +/** + * SOLR-1730, tests what happens when a component fails to initialize properly + * + **/ +public class BadComponentTest extends SolrTestCaseJ4{ + @Test + public void testBadElevate() throws Exception { + try { + System.setProperty("elevate.file", "foo.xml"); + initCore("solrconfig-elevate.xml", "schema12.xml"); + assertTrue(false); + } catch (Throwable e) { + log.error("Exception", e); + assertTrue(true); + } finally { + System.clearProperty("elevate.file"); + } + } +} diff --git a/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java index d1170c6e8e4..ffc8b12a2d3 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java @@ -30,6 +30,7 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.MapSolrParams; import org.apache.solr.common.params.QueryElevationParams; +import org.apache.solr.common.util.FileUtils; import org.apache.solr.common.util.NamedList; import org.apache.solr.core.SolrCore; import org.apache.solr.handler.component.QueryElevationComponent.ElevationObj; @@ -45,7 +46,13 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 { @BeforeClass public static void beforeClass() throws Exception { - initCore("solrconfig-elevate.xml","schema12.xml"); + //write out elevate-data.xml to the Data dir first by copying it from conf, which we know exists, this way we can test both conf and data configurations + createTempDir(); + File parent = new File(TEST_HOME(), "conf"); + File elevateFile = new File(parent, "elevate.xml"); + File elevateDataFile = new File(dataDir, "elevate-data.xml"); + FileUtils.copyFile(elevateFile, elevateDataFile); + initCore("solrconfig-elevate.xml", "schema12.xml"); } @Before