Apache Lucene open-source search software
SOLR-179 -- Initalization collects any errors and displays them rather then continuing. this feature is configurable in solrconfig.xml
Ryan McKinley615e30f16ea4
diff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xmlindex d89bdbdb3c6..fce6270a0a0 100755--- a/example/solr/conf/solrconfig.xml+++ b/example/solr/conf/solrconfig.xml@@ -17,6 +17,14 @@--><config>+ <!-- Set this to 'false' if you want solr to continue working after it has+ encountered an severe configuration error. In a production environment,+ you may want solr to keep working even if one handler is mis-configured.++ You may also set this to false using by setting the system property:+ -Dsolr.abortOnConfigurationError=false+ -->+ <abortOnConfigurationError>${solr.abortOnConfigurationError:true}</abortOnConfigurationError><!-- Used to specify an alternate directory to hold all index dataother than the default ./data under the Solr home.diff --git a/src/java/org/apache/solr/core/RequestHandlers.java b/src/java/org/apache/solr/core/RequestHandlers.javaindex bd540b5e5f1..efa3a34fda1 100644--- a/src/java/org/apache/solr/core/RequestHandlers.java+++ b/src/java/org/apache/solr/core/RequestHandlers.java@@ -18,7 +18,6 @@package org.apache.solr.core;import java.net.URL;-import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.LinkedHashMap;@@ -145,7 +144,7 @@ final class RequestHandlers {names.put( name, args );}catch (Exception e) {- // TODO: SOLR-179+ SolrConfig.severeErrors.add( e );SolrException.logOnce(log,null,e);}}@@ -156,7 +155,7 @@ final class RequestHandlers {handlers.get( reg.getKey() ).init( reg.getValue() );}catch( Exception e ) {- // TODO: SOLR-179+ SolrConfig.severeErrors.add( e );SolrException.logOnce(log,null,e);}}@@ -307,3 +306,4 @@ final class RequestHandlers {+diff --git a/src/java/org/apache/solr/core/SolrConfig.java b/src/java/org/apache/solr/core/SolrConfig.javaindex 9f689b87cc6..936416e1f63 100644--- a/src/java/org/apache/solr/core/SolrConfig.java+++ b/src/java/org/apache/solr/core/SolrConfig.java@@ -25,6 +25,8 @@ import org.xml.sax.SAXException;import javax.xml.parsers.ParserConfigurationException;+import java.util.Collection;+import java.util.HashSet;import java.util.StringTokenizer;import java.io.IOException;import java.io.InputStream;@@ -47,6 +49,11 @@ public class SolrConfig {*/public static Config config;+ /**+ * Singleton keeping track of configuration errors+ */+ public static final Collection<Throwable> severeErrors = new HashSet<Throwable>();+/*** (Re)loads the static configation information from the specified file.*@@ -79,6 +86,7 @@ public class SolrConfig {try {initConfig(DEFAULT_CONF_FILE);} catch (Exception ee) {+ severeErrors.add( ee );throw new RuntimeException("Error in " + DEFAULT_CONF_FILE, ee);}}diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.javaindex 50168858d21..8918b6d073c 100644--- a/src/java/org/apache/solr/core/SolrCore.java+++ b/src/java/org/apache/solr/core/SolrCore.java@@ -728,6 +728,7 @@ public final class SolrCore {writer.init(DOMUtil.childNodesToNamedList(elm));responseWriters.put(name, writer);} catch (Exception ex) {+ SolrConfig.severeErrors.add( ex );SolrException.logOnce(log,null, ex);// if a writer can't be created, skip it and continue}@@ -773,3 +774,4 @@ public final class SolrCore {}}+diff --git a/src/java/org/apache/solr/schema/IndexSchema.java b/src/java/org/apache/solr/schema/IndexSchema.javaindex 89067742305..e142edec962 100644--- a/src/java/org/apache/solr/schema/IndexSchema.java+++ b/src/java/org/apache/solr/schema/IndexSchema.java@@ -24,6 +24,7 @@ import org.apache.lucene.document.Fieldable;import org.apache.lucene.search.DefaultSimilarity;import org.apache.lucene.search.Similarity;import org.apache.lucene.queryParser.QueryParser;+import org.apache.solr.core.SolrConfig;import org.apache.solr.core.SolrException;import org.apache.solr.core.Config;import org.apache.solr.analysis.TokenFilterFactory;@@ -467,9 +468,11 @@ public final class IndexSchema {dynamicCopyFields = (DynamicCopy[])dCopies.toArray(new DynamicCopy[dCopies.size()]);} catch (SolrException e) {+ SolrConfig.severeErrors.add( e );throw e;} catch(Exception e) {// unexpected exception...+ SolrConfig.severeErrors.add( e );throw new SolrException(1,"Schema Parsing Failed",e,false);}@@ -820,3 +823,4 @@ public final class IndexSchema {}+diff --git a/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java b/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.javaindex fdebcd8749f..77574f9c46c 100644--- a/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java+++ b/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java@@ -51,18 +51,52 @@ public class SolrDispatchFilter implements Filterprotected SolrRequestParsers parsers;protected boolean handleSelect = false;protected String pathPrefix = null; // strip this from the begging of a path+ protected String abortErrorMessage = null;public void init(FilterConfig config) throws ServletException{log.info("SolrDispatchFilter.init()");-- // web.xml configuration- this.pathPrefix = config.getInitParameter( "path-prefix" );- this.handleSelect = "true".equals( config.getInitParameter( "handle-select" ) );- log.info("user.dir=" + System.getProperty("user.dir"));- core = SolrCore.getSolrCore();- parsers = new SolrRequestParsers( core, SolrConfig.config );+ try {+ // web.xml configuration+ this.pathPrefix = config.getInitParameter( "path-prefix" );+ this.handleSelect = "true".equals( config.getInitParameter( "handle-select" ) );++ log.info("user.dir=" + System.getProperty("user.dir"));+ core = SolrCore.getSolrCore();+ parsers = new SolrRequestParsers( core, SolrConfig.config );+ }+ catch( Throwable t ) {+ // catch this so our filter still works+ SolrConfig.severeErrors.add( t );+ SolrCore.log( t );+ }++ // Optionally abort if we found a sever error+ boolean abortOnConfigurationError = SolrConfig.config.getBool("abortOnConfigurationError",true);+ if( abortOnConfigurationError && SolrConfig.severeErrors.size() > 0 ) {+ StringWriter sw = new StringWriter();+ PrintWriter out = new PrintWriter( sw );+ out.println( "Severe errors in solr configuration.\n" );+ out.println( "Check your log files for more detailed infomation on what may be wrong.\n" );+ out.println( "If you want solr to continue after configuration errors, change: \n");+ out.println( " <abortOnConfigurationError>false</abortOnConfigurationError>\n" );+ out.println( "in solrconfig.xml\n" );++ for( Throwable t : SolrConfig.severeErrors ) {+ out.println( "-------------------------------------------------------------" );+ t.printStackTrace( out );+ }+ out.flush();++ // Servlet containers behave slightly differntly if you throw an exception durring+ // initalization. Resin will display that error for every page, jetty prints it in+ // the logs, but continues normally. (We will see a 404 rather then the real error)+ // rather then leave the behavior undefined, lets cache the error and spit it out+ // for every request.+ abortErrorMessage = sw.toString();+ //throw new ServletException( abortErrorMessage );+ }log.info("SolrDispatchFilter.init() done");}@@ -73,6 +107,11 @@ public class SolrDispatchFilter implements Filterpublic void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException{+ if( abortErrorMessage != null ) {+ ((HttpServletResponse)response).sendError( 500, abortErrorMessage );+ return;+ }+if( request instanceof HttpServletRequest) {SolrQueryRequest solrReq = null;HttpServletRequest req = (HttpServletRequest)request;