Apache Lucene open-source search software
SOLR-1730: Hook in handling of bad cores, failure of QEC to load, add in test
Grant Ingersoll97b40049d03e
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.javaindex 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.javaindex 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 knowresourceLoader.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 releasedlatch.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.javaindex 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 SolrCoreelevationCache.put(null, loadElevationMap( cfg ));}}-+ //in other words, we think this is in the data dir, not the conf dirif (!exists){// preload the first dataRefCounted<SolrIndexSearcher> 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 dirMap<String, ElevationObj> getElevationMap( IndexReader reader, SolrCore core ) throws Exception{synchronized( elevationCache ) {@@ -242,7 +242,7 @@ public class QueryElevationComponent extends SearchComponent implements SolrCorereturn map;}}-+ //load up the elevation mapprivate Map<String, ElevationObj> 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.javaindex 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.xmlindex 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 @@<!-- test elevation --><searchComponent name="elevate" class="org.apache.solr.handler.component.QueryElevationComponent" ><str name="queryFieldType">string</str>- <str name="config-file">elevate.xml</str>+ <str name="config-file">${elevate.file:elevate.xml}</str>+ </searchComponent>++ <!-- SOLR-1730 -->+ <!--<searchComponent name="badElevate" class="org.apache.solr.handler.component.QueryElevationComponent" >+ <str name="queryFieldType">string</str>+ <str name="config-file">foo.xml</str>+ </searchComponent>-->+ <searchComponent name="dataElevate" class="org.apache.solr.handler.component.QueryElevationComponent" >+ <str name="queryFieldType">string</str>+ <str name="config-file">${elevate.data.file:elevate-data.xml}</str></searchComponent><requestHandler name="/elevate" class="org.apache.solr.handler.component.SearchHandler">@@ -197,6 +207,24 @@</arr></requestHandler>+ <requestHandler name="/dataElevate" class="org.apache.solr.handler.component.SearchHandler">+ <lst name="defaults">+ <str name="echoParams">explicit</str>+ </lst>+ <arr name="last-components">+ <str>dataElevate</str>+ </arr>+ </requestHandler>++ <!--<requestHandler name="/badElevate" class="org.apache.solr.handler.component.SearchHandler">+ <lst name="defaults">+ <str name="echoParams">explicit</str>+ </lst>+ <arr name="last-components">+ <str>badElevate</str>+ </arr>+ </requestHandler>-->+<!-- enable streaming for testing... --><requestDispatcher handleSelect="true" ><requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048" />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.javanew file mode 100644index 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.javaindex 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 {@BeforeClasspublic 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