You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ry...@apache.org on 2007/04/27 01:37:45 UTC

svn commit: r532912 - in /lucene/solr/trunk: example/solr/conf/ src/java/org/apache/solr/core/ src/java/org/apache/solr/schema/ src/webapp/src/org/apache/solr/servlet/

Author: ryan
Date: Thu Apr 26 16:37:44 2007
New Revision: 532912

URL: http://svn.apache.org/viewvc?view=rev&rev=532912
Log:
SOLR-179 -- Initalization collects any errors and displays them rather then continuing.  this feature is configurable in solrconfig.xml

Modified:
    lucene/solr/trunk/example/solr/conf/solrconfig.xml
    lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java
    lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java
    lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java
    lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java

Modified: lucene/solr/trunk/example/solr/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/example/solr/conf/solrconfig.xml?view=diff&rev=532912&r1=532911&r2=532912
==============================================================================
--- lucene/solr/trunk/example/solr/conf/solrconfig.xml (original)
+++ lucene/solr/trunk/example/solr/conf/solrconfig.xml Thu Apr 26 16:37:44 2007
@@ -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.

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java?view=diff&rev=532912&r1=532911&r2=532912
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java Thu Apr 26 16:37:44 2007
@@ -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 @@
           names.put( name, args );
         } 
         catch (Exception e) {
-          // TODO: SOLR-179
+          SolrConfig.severeErrors.add( e );
           SolrException.logOnce(log,null,e);
         }
       }
@@ -156,7 +155,7 @@
           handlers.get( reg.getKey() ).init( reg.getValue() );
         }
         catch( Exception e ) {
-          // TODO: SOLR-179
+          SolrConfig.severeErrors.add( e );
           SolrException.logOnce(log,null,e);
         }
       }
@@ -304,6 +303,7 @@
     }
   }
 }
+
 
 
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java?view=diff&rev=532912&r1=532911&r2=532912
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java Thu Apr 26 16:37:44 2007
@@ -25,6 +25,8 @@
 
 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;
@@ -48,6 +50,11 @@
   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.
    *
    * <p>
@@ -79,6 +86,7 @@
     try {
       initConfig(DEFAULT_CONF_FILE);
     } catch (Exception ee) {
+      severeErrors.add( ee );
       throw new RuntimeException("Error in " + DEFAULT_CONF_FILE, ee);
     }
   }

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java?view=diff&rev=532912&r1=532911&r2=532912
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java Thu Apr 26 16:37:44 2007
@@ -728,6 +728,7 @@
         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
       }
@@ -772,4 +773,5 @@
     return getQueryResponseWriter(request.getParam("wt")); 
   }
 }
+
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java?view=diff&rev=532912&r1=532911&r2=532912
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java Thu Apr 26 16:37:44 2007
@@ -24,6 +24,7 @@
 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 @@
       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);
     }
 
@@ -819,4 +822,5 @@
   }
 
 }
+
 

Modified: lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java?view=diff&rev=532912&r1=532911&r2=532912
==============================================================================
--- lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java (original)
+++ lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java Thu Apr 26 16:37:44 2007
@@ -51,18 +51,52 @@
   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 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;