SOLR-179 -- Initalization collects any errors and displays them rather then continuing. this feature is configurable in solrconfig.xml

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@532912 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2007-04-26 23:37:44 +00:00
parent 1efad83104
commit 615e30f16e
6 changed files with 71 additions and 10 deletions

View File

@ -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 data
other than the default ./data under the Solr home.

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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 {
}
}

View File

@ -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 {
}

View File

@ -51,18 +51,52 @@ public class SolrDispatchFilter implements Filter
protected 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 Filter
public 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;