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/09/09 07:59:57 UTC

svn commit: r573950 - in /lucene/solr/trunk: client/java/solrj/test/org/apache/solr/client/solrj/embedded/ src/java/org/apache/solr/core/ src/java/org/apache/solr/util/ src/test/org/apache/solr/core/ src/webapp/src/org/apache/solr/servlet/

Author: ryan
Date: Sat Sep  8 22:59:56 2007
New Revision: 573950

URL: http://svn.apache.org/viewvc?rev=573950&view=rev
Log:
SOLR-215 -- removing the core name and 'cores' registry stuff.  this should be part of SOLR-350, not SolrCore

Modified:
    lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.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/util/AbstractSolrTestCase.java
    lucene/solr/trunk/src/java/org/apache/solr/util/TestHarness.java
    lucene/solr/trunk/src/test/org/apache/solr/core/TestBadConfig.java
    lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java

Modified: lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java?rev=573950&r1=573949&r2=573950&view=diff
==============================================================================
--- lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java (original)
+++ lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java Sat Sep  8 22:59:56 2007
@@ -33,11 +33,6 @@
 
   SolrServer server;
   JettySolrRunner jetty;
-
-  @Override
-  public String getCoreName() {
-    return null;
-  }
   
   @Override public void setUp() throws Exception 
   {

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?rev=573950&r1=573949&r2=573950&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java Sat Sep  8 22:59:56 2007
@@ -129,6 +129,9 @@
     
     pingQueryParams = readPingQueryParams(this);
     Config.log.info("Loaded SolrConfig: " + file);
+    
+    // TODO -- at solr 2.0. this should go away
+    config = this;
   }
 
   /* The set of materialized parameters: */

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?rev=573950&r1=573949&r2=573950&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java Sat Sep  8 22:59:56 2007
@@ -19,7 +19,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Collections;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -69,23 +68,24 @@
 /**
  * @version $Id$
  */
-
 public final class SolrCore {
   public static final String version="1.0";  
 
   public static Logger log = Logger.getLogger(SolrCore.class.getName());
-  private final String name;
+  
   private final IndexSchema schema;
   private final String dataDir;
   private final String index_path;
   private final UpdateHandler updateHandler;
-  private static final long startTime = System.currentTimeMillis();
+  private final long startTime = System.currentTimeMillis();
   private final RequestHandlers reqHandlers;
   private final SolrHighlighter highlighter;
   private final Map<String,UpdateRequestProcessorFactory> updateProcessors;
   
   public long getStartTime() { return startTime; }
 
+  @Deprecated
+  private static SolrCore instance;
 
   static int boolean_query_max_clause_count = Integer.MIN_VALUE;
   // only change the BooleanQuery maxClauseCount once for ALL cores...
@@ -147,7 +147,6 @@
     newSearcherListeners = parseListener("//listener[@event=\"newSearcher\"]");
   }
 
-  public String getName() { return name; }
   public IndexSchema getSchema() { return schema; }
   public String getDataDir() { return dataDir; }
   public String getIndexDir() { return index_path; }
@@ -198,7 +197,7 @@
    *@return the desired instance
    *@throws SolrException if the object could not be instantiated
    */
-  public <T extends Object> T createInstance(String className, Class<T> cast, String msg) {
+  private <T extends Object> T createInstance(String className, Class<T> cast, String msg) {
     Class clazz = null;
     if (msg == null) msg = "SolrCore Object";
     try {
@@ -232,146 +231,74 @@
   }
 
   
-  // The registry of known cores
-  private static Map<String, SolrCore> cores = new HashMap<String, SolrCore>();
-  
-  /** Alias for SolrCore.getSolrCore(null). */
+  /** 
+   * @return the last core initalized.  If you are using multiple cores, 
+   * this is not a function to use.
+   */
   @Deprecated
   public static SolrCore getSolrCore() {
-    return getSolrCore(null);
+    return instance;
   }
   
   /**
-   * Retrieves a core instance by name.
-   *@param name the core name
-   *@return the core instance or null if none exist with that name.
-   */
-  public static SolrCore getSolrCore(String name) {
-    if (name != null && name.length() == 0)
-      name = null;
-    synchronized (cores) {
-      SolrCore core = cores.get(name);
-      if (core==null && name==null)
-        try {
-          core = new SolrCore(null, new SolrConfig(), null);
-        } catch(Exception xany) {
-          log.throwing("SolrCore", "getSolrCore", xany);
-          return null;
-        }
-      return core;
-    }
-  }
-
-  /**
-   * Returns an unmodifieable Map containing the registered cores
-   */
-  public Map<String,SolrCore> getSolrCores() {
-    return Collections.unmodifiableMap( cores );
-  }
-
-  /** The array of known core names. */
-  public String[] getSolrCoreNames() {
-    synchronized(cores) {
-      String[] names = new String[cores.size()];
-      int count = 0;
-      java.util.Iterator<String> itnames = cores.keySet().iterator();
-      while(itnames.hasNext()) {
-        names[count++] = itnames.next();
-      }
-      return names;
-    }
-  }
-
-  public String toString() {
-    return name!=null? "core{" + name + "}" : super.toString();
-      }
-
-  /** The single-core mode compatibility constructor; the core is named 'null'. */
-  public SolrCore(String dataDir, SolrConfig config, IndexSchema schema) {
-    this(null, dataDir, config, schema);
-  }
-
-  /** Ensures that a name does not contain a '/' or a '\' to avoid any potential
-   *  issues with file pathes.
-   *@param name the core name to check
-   *@return the name
-   *@throws SolrException if the name is not valid
-   */
-  private static String checkName(String name) {
-    if (name != null) for(int i = 0, length = name.length(); i < length; ++i) {
-      char c = name.charAt(i);
-      if (c == '/' || c == '\\' || Character.isSpaceChar(c))
-        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Invalid core name '"+name+"'");
-      }
-    return name;
-      }
-
-  /**
    * Creates a new core and register it in the list of cores.
    * If a core with the same name already exists, it will be stopped and replaced by this one.
-   *@param name the unique name of the core (null is accepted)
    *@param dataDir the index directory
    *@param config a solr config instance
    *@param schema a solr schema instance
    */
-  public SolrCore(String name, String dataDir, SolrConfig config, IndexSchema schema) {
-    this.name = checkName(name);
-    this.solrConfig = config;
-    // compatibility code with pre-solr215-patch in case some custom code relies on SolrConfig.config existence.
-    if (this.name == null) SolrConfig.config = config;
-    if (dataDir ==null)
-      dataDir = solrConfig.get("dataDir",solrConfig.getInstanceDir()+"data");
-
-    if (schema==null)
-      this.schema = new IndexSchema(config, "schema.xml");
-    else
-      this.schema = schema;
-    
-    this.dataDir = dataDir;
-    if (name == null)
-      this.index_path = dataDir + "/index";
-    else
-      this.index_path = dataDir  + "/index-" + name;
-
-    log.info("Opening new SolrCore at " + solrConfig.getInstanceDir() + ", dataDir="+dataDir + ", indexPath=" + index_path);
+  public SolrCore(String dataDir, SolrConfig config, IndexSchema schema) {
+    synchronized (SolrCore.class) {
+      // this is for backward compatibility (and also the reason
+      // the sync block is needed)
+      instance = this;   // set singleton
     
-    booleanQueryMaxClauseCount();
-    this.maxWarmingSearchers = solrConfig.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);
+      if (dataDir ==null) {
+        dataDir = config.get("dataDir",config.getInstanceDir()+"data");
+      }
 
-    parseListeners();
+      log.info("Opening new SolrCore at " + config.getInstanceDir() + ", dataDir="+dataDir);
 
-    initIndex();
-    
-    initWriters();
-    
-    // Processors initialized before the handlers
-    updateProcessors = loadUpdateProcessors();
-    reqHandlers = new RequestHandlers(this);
-    reqHandlers.initHandlersFromConfig( solrConfig );
-
-    // TODO? could select the highlighter implementation
-    highlighter = new SolrHighlighter();
-    highlighter.initalize( solrConfig );
-    
-    try {
-      // Open the searcher *before* the handler so we don't end up opening
-      // one in the middle.
-      getSearcher(false,false,null);
-
-      updateHandler = createUpdateHandler(
-            solrConfig.get("updateHandler/@class", DirectUpdateHandler.class.getName())
-      );
+      if (schema==null) {
+        schema = new IndexSchema(config, "schema.xml");
+      }
 
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-    // register this core
-    synchronized(cores) {
-      SolrCore previous = cores.get(name);
-      if (previous != null) {
-        previous.close();
+      this.schema = schema;
+      this.dataDir = dataDir;
+      this.index_path = dataDir + "/" + "index";
+      this.solrConfig = config;
+
+      this.maxWarmingSearchers = config.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);
+
+      booleanQueryMaxClauseCount();
+  
+      parseListeners();
+  
+      initIndex();
+      
+      initWriters();
+      
+      // Processors initialized before the handlers
+      updateProcessors = loadUpdateProcessors();
+      reqHandlers = new RequestHandlers(this);
+      reqHandlers.initHandlersFromConfig( solrConfig );
+  
+      // TODO? could select the highlighter implementation
+      highlighter = new SolrHighlighter();
+      highlighter.initalize( solrConfig );
+      
+      try {
+        // Open the searcher *before* the handler so we don't end up opening
+        // one in the middle.
+        getSearcher(false,false,null);
+  
+        updateHandler = createUpdateHandler(
+          solrConfig.get("updateHandler/@class", DirectUpdateHandler.class.getName())
+        );
+      } 
+      catch (IOException e) {
+        throw new RuntimeException(e);
       }
-      cores.put(name, this);
     }
   }
 
@@ -422,21 +349,7 @@
   }
 
   public void close() {
-    close(true);
-  }
-  
-  private void close(boolean remove) {
-    if (name == null)
-      log.info("CLOSING default SolrCore!");
-    else
-      log.info("CLOSING SolrCore "+ name);
-    if (remove) synchronized(cores) {
-      SolrCore core = cores.remove(name);
-      if (core == null) {
-        log.info("Core " + core + " already closed");
-        return;
-      }
-    }
+    log.info("CLOSING SolrCore!");
     try {
       closeSearcher();
     } catch (Exception e) {
@@ -454,18 +367,6 @@
     }
   }
 
-  /** Stops all cores. */
-  public static void shutdown() {
-    synchronized(cores) {
-      java.util.Iterator< java.util.Map.Entry<String,SolrCore> > it = cores.entrySet().iterator();
-      while(it.hasNext()) {
-        SolrCore core = it.next().getValue();
-        core.close(false);
-      }
-      cores.clear();
-    }
-  }
-  
   @Override
   protected void finalize() { close(); }
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/util/AbstractSolrTestCase.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/util/AbstractSolrTestCase.java?rev=573950&r1=573949&r2=573950&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/util/AbstractSolrTestCase.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/util/AbstractSolrTestCase.java Sat Sep  8 22:59:56 2007
@@ -63,14 +63,7 @@
    * </p>
    */
   protected TestHarness.LocalRequestFactory lrf;
-    /**
-     * Subclasses may define this method to return the name of the
-     * Solr core they wish to use.
-     */
-    public String getCoreName() {
-      return this.getClass().getPackage().getName();
-    }
-
+    
   /**
    * Subclasses must define this method to return the name of the
    * schema.xml they wish to use.
@@ -99,27 +92,17 @@
    *
    */
   public void setUp() throws Exception {
-        String coreName = getCoreName();
-        if (coreName != null) {
     dataDir = new File(System.getProperty("java.io.tmpdir")
-                       + System.getProperty("file.separator")
-                       + System.currentTimeMillis());
-        } else {
-            dataDir = new File(System.getProperty("java.io.tmpdir")
-            + System.getProperty("file.separator")
-            + getClass().getName() + "-" + System.currentTimeMillis());
-            
-        }
+        + System.getProperty("file.separator")
+        + getClass().getName() + "-" + System.currentTimeMillis());
     dataDir.mkdirs();
         
-        solrConfig = h.createConfig(getSolrConfigFile());
-        h = new TestHarness(coreName,
-                dataDir.getAbsolutePath(),
-                        solrConfig,
-                        getSchemaFile());
+    solrConfig = h.createConfig(getSolrConfigFile());
+    h = new TestHarness( dataDir.getAbsolutePath(),
+                    solrConfig,
+                    getSchemaFile());
     lrf = h.getRequestFactory
       ("standard",0,20,"version","2.2");
-
   }
     
   /**

Modified: lucene/solr/trunk/src/java/org/apache/solr/util/TestHarness.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/util/TestHarness.java?rev=573950&r1=573949&r2=573950&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/util/TestHarness.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/util/TestHarness.java Sat Sep  8 22:59:56 2007
@@ -84,17 +84,18 @@
    *
    * @param dataDirectory path for index data, will not be cleaned up
    */
-  public TestHarness(String name, String dataDirectory) {
-    this(name, dataDirectory, "schema.xml");
+  public TestHarness( String dataDirectory) {
+    this( dataDirectory, "schema.xml");
   }
+  
   /**
    * Assumes "solrconfig.xml" is the config file to use.
    *
    * @param dataDirectory path for index data, will not be cleaned up
    * @param schemaFile path of schema file
    */
-  public TestHarness(String name, String dataDirectory, String schemaFile) {
-    this(name, dataDirectory, "solrconfig.xml", schemaFile);
+  public TestHarness( String dataDirectory, String schemaFile) {
+    this( dataDirectory, "solrconfig.xml", schemaFile);
   }
   /**
     * @param name the core name
@@ -102,8 +103,8 @@
     * @param configFile solrconfig filename
    * @param schemaFile schema filename
    */
-   public TestHarness(String name, String dataDirectory, String configFile, String schemaFile) {
-     this(name, dataDirectory, createConfig(configFile), schemaFile);
+   public TestHarness( String dataDirectory, String configFile, String schemaFile) {
+     this( dataDirectory, createConfig(configFile), schemaFile);
    }
    /**
     * @param name the core name
@@ -111,11 +112,10 @@
     * @param solrConfig solronfig instance
     * @param schemaFile schema filename
     */
-      public TestHarness(String name,
-                      String dataDirectory,
-                      SolrConfig solrConfig,
-                     String schemaFile) {
-     this(name, dataDirectory, solrConfig, new IndexSchema(solrConfig, schemaFile));
+      public TestHarness( String dataDirectory,
+                          SolrConfig solrConfig,
+                          String schemaFile) {
+     this( dataDirectory, solrConfig, new IndexSchema(solrConfig, schemaFile));
    }
    /**
     * @param name the core name
@@ -123,12 +123,11 @@
     * @param solrConfig solrconfig instance
     * @param schema schema instance
     */
-  public TestHarness(String name,
-                      String dataDirectory,
+  public TestHarness( String dataDirectory,
                       SolrConfig solrConfig,
                       IndexSchema indexSchema) {
     try {
-      core = new SolrCore(name, dataDirectory, solrConfig, indexSchema);
+      core = new SolrCore( dataDirectory, solrConfig, indexSchema);
       builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
       
       updater = new XmlUpdateRequestHandler();

Modified: lucene/solr/trunk/src/test/org/apache/solr/core/TestBadConfig.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/core/TestBadConfig.java?rev=573950&r1=573949&r2=573950&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/core/TestBadConfig.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/core/TestBadConfig.java Sat Sep  8 22:59:56 2007
@@ -34,10 +34,9 @@
     dataDir.mkdirs();
     try {
       solrConfig = new SolrConfig(getSolrConfigFile());
-      h = new TestHarness(getName() + "-" + System.currentTimeMillis(),
-                        dataDir.getAbsolutePath(),
-                        solrConfig,
-                          getSchemaFile());
+      h = new TestHarness( dataDir.getAbsolutePath(),
+                           solrConfig,
+                           getSchemaFile());
       fail("Exception should have been thrown");
     } catch (Exception e) {
       assertTrue(e.getMessage().contains("unset.sys.property"));

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?rev=573950&r1=573949&r2=573950&view=diff
==============================================================================
--- 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 Sat Sep  8 22:59:56 2007
@@ -68,7 +68,7 @@
 
       // Let this filter take care of /select?xxx format
       this.handleSelect = 
-        SolrConfig.config.getBool( "requestDispatcher/@handleSelect", false ); 
+        core.getSolrConfig().getBool( "requestDispatcher/@handleSelect", false ); 
     }
     catch( Throwable t ) {
       // catch this so our filter still works
@@ -78,7 +78,7 @@
     }
     
     // Optionally abort if we found a sever error
-    boolean abortOnConfigurationError = SolrConfig.config.getBool("abortOnConfigurationError",true);
+    boolean abortOnConfigurationError = core.getSolrConfig().getBool("abortOnConfigurationError",true);
     if( abortOnConfigurationError && SolrConfig.severeErrors.size() > 0 ) {
       StringWriter sw = new StringWriter();
       PrintWriter out = new PrintWriter( sw );