Apache Solr open-source search software
SOLR-215 -- removing the core name and 'cores' registry stuff. this should be part of SOLR-350, not SolrCore
Ryan McKinleye3dacf01c782
diff --git a/client/java/solrj/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java b/client/java/solrj/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.javaindex fc266b2889a..c3c5787059c 100644--- a/client/java/solrj/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java+++ b/client/java/solrj/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java@@ -33,11 +33,6 @@ public class TestJettySolrRunner extends SolrExampleTestBase {SolrServer server;JettySolrRunner jetty;-- @Override- public String getCoreName() {- return null;- }@Override public void setUp() throws Exception{diff --git a/src/java/org/apache/solr/core/SolrConfig.java b/src/java/org/apache/solr/core/SolrConfig.javaindex 5eff7ec373a..5064a595ed0 100644--- a/src/java/org/apache/solr/core/SolrConfig.java+++ b/src/java/org/apache/solr/core/SolrConfig.java@@ -129,6 +129,9 @@ public class SolrConfig extends Config {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: */diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.javaindex e5311792c13..7b0378f6dc8 100644--- a/src/java/org/apache/solr/core/SolrCore.java+++ b/src/java/org/apache/solr/core/SolrCore.java@@ -19,7 +19,6 @@ package org.apache.solr.core;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 @@ import org.w3c.dom.NodeList;/*** @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 @@ public final class SolrCore {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 @@ public final class SolrCore {*@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 @@ public final class SolrCore {}- // 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.+ */@Deprecatedpublic 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;+ 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- this.dataDir = dataDir;- if (name == null)- this.index_path = dataDir + "/index";- else- this.index_path = dataDir + "/index-" + name;+ if (dataDir ==null) {+ dataDir = config.get("dataDir",config.getInstanceDir()+"data");+ }- log.info("Opening new SolrCore at " + solrConfig.getInstanceDir() + ", dataDir="+dataDir + ", indexPath=" + index_path);-- booleanQueryMaxClauseCount();- this.maxWarmingSearchers = solrConfig.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);+ log.info("Opening new SolrCore at " + config.getInstanceDir() + ", dataDir="+dataDir);- parseListeners();+ if (schema==null) {+ schema = new IndexSchema(config, "schema.xml");+ }- 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);+ this.schema = schema;+ this.dataDir = dataDir;+ this.index_path = dataDir + "/" + "index";+ this.solrConfig = config;- updateHandler = createUpdateHandler(- solrConfig.get("updateHandler/@class", DirectUpdateHandler.class.getName())- );+ this.maxWarmingSearchers = config.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);- } catch (IOException e) {- throw new RuntimeException(e);- }- // register this core- synchronized(cores) {- SolrCore previous = cores.get(name);- if (previous != null) {- previous.close();+ 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 final class SolrCore {}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 @@ public final class SolrCore {}}- /** 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();- }- }-@Overrideprotected void finalize() { close(); }diff --git a/src/java/org/apache/solr/util/AbstractSolrTestCase.java b/src/java/org/apache/solr/util/AbstractSolrTestCase.javaindex 5e40e4ce9d0..08d1ba4a6f2 100644--- a/src/java/org/apache/solr/util/AbstractSolrTestCase.java+++ b/src/java/org/apache/solr/util/AbstractSolrTestCase.java@@ -63,14 +63,7 @@ public abstract class AbstractSolrTestCase extends TestCase {* </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 abstract class AbstractSolrTestCase extends TestCase {**/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");-}/**diff --git a/src/java/org/apache/solr/util/TestHarness.java b/src/java/org/apache/solr/util/TestHarness.javaindex 2f0ae19ce73..7a68967c84a 100644--- a/src/java/org/apache/solr/util/TestHarness.java+++ b/src/java/org/apache/solr/util/TestHarness.java@@ -84,17 +84,18 @@ public class TestHarness {** @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 @@ public class TestHarness {* @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 @@ public class TestHarness {* @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 @@ public class TestHarness {* @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();diff --git a/src/test/org/apache/solr/core/TestBadConfig.java b/src/test/org/apache/solr/core/TestBadConfig.javaindex 9cc6039185c..4eb5e328f3b 100644--- a/src/test/org/apache/solr/core/TestBadConfig.java+++ b/src/test/org/apache/solr/core/TestBadConfig.java@@ -34,10 +34,9 @@ public class TestBadConfig extends AbstractSolrTestCase {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"));diff --git a/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java b/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.javaindex 57f4af44024..44234e5ab57 100644--- a/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java+++ b/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java@@ -68,7 +68,7 @@ public class SolrDispatchFilter implements Filter// Let this filter take care of /select?xxx formatthis.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 @@ public class SolrDispatchFilter implements Filter}// 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 );