mirror of https://github.com/apache/lucene.git
SOLR-215 -- removing the core name and 'cores' registry stuff. this should be part of SOLR-350, not SolrCore
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@573950 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fb9d1c34bb
commit
e3dacf01c7
|
@ -34,11 +34,6 @@ public class TestJettySolrRunner extends SolrExampleTestBase {
|
|||
SolrServer server;
|
||||
JettySolrRunner jetty;
|
||||
|
||||
@Override
|
||||
public String getCoreName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
|
|
@ -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: */
|
||||
|
|
|
@ -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,111 +231,46 @@ 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.
|
||||
*/
|
||||
@Deprecated
|
||||
public static SolrCore getSolrCore() {
|
||||
return getSolrCore(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
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
|
||||
|
||||
if (dataDir ==null) {
|
||||
dataDir = config.get("dataDir",config.getInstanceDir()+"data");
|
||||
}
|
||||
|
||||
log.info("Opening new SolrCore at " + config.getInstanceDir() + ", dataDir="+dataDir);
|
||||
|
||||
if (schema==null) {
|
||||
schema = new IndexSchema(config, "schema.xml");
|
||||
}
|
||||
|
||||
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;
|
||||
this.index_path = dataDir + "/" + "index";
|
||||
this.solrConfig = config;
|
||||
|
||||
log.info("Opening new SolrCore at " + solrConfig.getInstanceDir() + ", dataDir="+dataDir + ", indexPath=" + index_path);
|
||||
this.maxWarmingSearchers = config.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);
|
||||
|
||||
booleanQueryMaxClauseCount();
|
||||
this.maxWarmingSearchers = solrConfig.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);
|
||||
|
||||
parseListeners();
|
||||
|
||||
|
@ -361,17 +295,10 @@ public final class SolrCore {
|
|||
updateHandler = createUpdateHandler(
|
||||
solrConfig.get("updateHandler/@class", DirectUpdateHandler.class.getName())
|
||||
);
|
||||
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// register this core
|
||||
synchronized(cores) {
|
||||
SolrCore previous = cores.get(name);
|
||||
if (previous != null) {
|
||||
previous.close();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() { close(); }
|
||||
|
||||
|
|
|
@ -63,13 +63,6 @@ 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
|
||||
|
@ -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());
|
||||
|
||||
}
|
||||
dataDir.mkdirs();
|
||||
|
||||
solrConfig = h.createConfig(getSolrConfigFile());
|
||||
h = new TestHarness(coreName,
|
||||
dataDir.getAbsolutePath(),
|
||||
h = new TestHarness( dataDir.getAbsolutePath(),
|
||||
solrConfig,
|
||||
getSchemaFile());
|
||||
lrf = h.getRequestFactory
|
||||
("standard",0,20,"version","2.2");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,
|
||||
public TestHarness( String dataDirectory,
|
||||
SolrConfig solrConfig,
|
||||
String schemaFile) {
|
||||
this(name, dataDirectory, solrConfig, new IndexSchema(solrConfig, 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();
|
||||
|
|
|
@ -34,8 +34,7 @@ public class TestBadConfig extends AbstractSolrTestCase {
|
|||
dataDir.mkdirs();
|
||||
try {
|
||||
solrConfig = new SolrConfig(getSolrConfigFile());
|
||||
h = new TestHarness(getName() + "-" + System.currentTimeMillis(),
|
||||
dataDir.getAbsolutePath(),
|
||||
h = new TestHarness( dataDir.getAbsolutePath(),
|
||||
solrConfig,
|
||||
getSchemaFile());
|
||||
fail("Exception should have been thrown");
|
||||
|
|
|
@ -68,7 +68,7 @@ public class SolrDispatchFilter implements Filter
|
|||
|
||||
// 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 @@ 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 );
|
||||
|
|
Loading…
Reference in New Issue