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;
|
SolrServer server;
|
||||||
JettySolrRunner jetty;
|
JettySolrRunner jetty;
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getCoreName() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void setUp() throws Exception
|
@Override public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
|
@ -129,6 +129,9 @@ public class SolrConfig extends Config {
|
||||||
|
|
||||||
pingQueryParams = readPingQueryParams(this);
|
pingQueryParams = readPingQueryParams(this);
|
||||||
Config.log.info("Loaded SolrConfig: " + file);
|
Config.log.info("Loaded SolrConfig: " + file);
|
||||||
|
|
||||||
|
// TODO -- at solr 2.0. this should go away
|
||||||
|
config = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The set of materialized parameters: */
|
/* The set of materialized parameters: */
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.solr.core;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -69,23 +68,24 @@ import org.w3c.dom.NodeList;
|
||||||
/**
|
/**
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class SolrCore {
|
public final class SolrCore {
|
||||||
public static final String version="1.0";
|
public static final String version="1.0";
|
||||||
|
|
||||||
public static Logger log = Logger.getLogger(SolrCore.class.getName());
|
public static Logger log = Logger.getLogger(SolrCore.class.getName());
|
||||||
private final String name;
|
|
||||||
private final IndexSchema schema;
|
private final IndexSchema schema;
|
||||||
private final String dataDir;
|
private final String dataDir;
|
||||||
private final String index_path;
|
private final String index_path;
|
||||||
private final UpdateHandler updateHandler;
|
private final UpdateHandler updateHandler;
|
||||||
private static final long startTime = System.currentTimeMillis();
|
private final long startTime = System.currentTimeMillis();
|
||||||
private final RequestHandlers reqHandlers;
|
private final RequestHandlers reqHandlers;
|
||||||
private final SolrHighlighter highlighter;
|
private final SolrHighlighter highlighter;
|
||||||
private final Map<String,UpdateRequestProcessorFactory> updateProcessors;
|
private final Map<String,UpdateRequestProcessorFactory> updateProcessors;
|
||||||
|
|
||||||
public long getStartTime() { return startTime; }
|
public long getStartTime() { return startTime; }
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private static SolrCore instance;
|
||||||
|
|
||||||
static int boolean_query_max_clause_count = Integer.MIN_VALUE;
|
static int boolean_query_max_clause_count = Integer.MIN_VALUE;
|
||||||
// only change the BooleanQuery maxClauseCount once for ALL cores...
|
// only change the BooleanQuery maxClauseCount once for ALL cores...
|
||||||
|
@ -147,7 +147,6 @@ public final class SolrCore {
|
||||||
newSearcherListeners = parseListener("//listener[@event=\"newSearcher\"]");
|
newSearcherListeners = parseListener("//listener[@event=\"newSearcher\"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() { return name; }
|
|
||||||
public IndexSchema getSchema() { return schema; }
|
public IndexSchema getSchema() { return schema; }
|
||||||
public String getDataDir() { return dataDir; }
|
public String getDataDir() { return dataDir; }
|
||||||
public String getIndexDir() { return index_path; }
|
public String getIndexDir() { return index_path; }
|
||||||
|
@ -198,7 +197,7 @@ public final class SolrCore {
|
||||||
*@return the desired instance
|
*@return the desired instance
|
||||||
*@throws SolrException if the object could not be instantiated
|
*@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;
|
Class clazz = null;
|
||||||
if (msg == null) msg = "SolrCore Object";
|
if (msg == null) msg = "SolrCore Object";
|
||||||
try {
|
try {
|
||||||
|
@ -232,111 +231,46 @@ public final class SolrCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// The registry of known cores
|
/**
|
||||||
private static Map<String, SolrCore> cores = new HashMap<String, SolrCore>();
|
* @return the last core initalized. If you are using multiple cores,
|
||||||
|
* this is not a function to use.
|
||||||
/** Alias for SolrCore.getSolrCore(null). */
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static SolrCore getSolrCore() {
|
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.
|
* 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.
|
* 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 dataDir the index directory
|
||||||
*@param config a solr config instance
|
*@param config a solr config instance
|
||||||
*@param schema a solr schema instance
|
*@param schema a solr schema instance
|
||||||
*/
|
*/
|
||||||
public SolrCore(String name, String dataDir, SolrConfig config, IndexSchema schema) {
|
public SolrCore(String dataDir, SolrConfig config, IndexSchema schema) {
|
||||||
this.name = checkName(name);
|
synchronized (SolrCore.class) {
|
||||||
this.solrConfig = config;
|
// this is for backward compatibility (and also the reason
|
||||||
// compatibility code with pre-solr215-patch in case some custom code relies on SolrConfig.config existence.
|
// the sync block is needed)
|
||||||
if (this.name == null) SolrConfig.config = config;
|
instance = this; // set singleton
|
||||||
if (dataDir ==null)
|
|
||||||
dataDir = solrConfig.get("dataDir",solrConfig.getInstanceDir()+"data");
|
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.schema = schema;
|
||||||
|
|
||||||
this.dataDir = dataDir;
|
this.dataDir = dataDir;
|
||||||
if (name == null)
|
this.index_path = dataDir + "/" + "index";
|
||||||
this.index_path = dataDir + "/index";
|
this.solrConfig = config;
|
||||||
else
|
|
||||||
this.index_path = dataDir + "/index-" + name;
|
|
||||||
|
|
||||||
log.info("Opening new SolrCore at " + solrConfig.getInstanceDir() + ", dataDir="+dataDir + ", indexPath=" + index_path);
|
this.maxWarmingSearchers = config.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);
|
||||||
|
|
||||||
booleanQueryMaxClauseCount();
|
booleanQueryMaxClauseCount();
|
||||||
this.maxWarmingSearchers = solrConfig.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);
|
|
||||||
|
|
||||||
parseListeners();
|
parseListeners();
|
||||||
|
|
||||||
|
@ -361,17 +295,10 @@ public final class SolrCore {
|
||||||
updateHandler = createUpdateHandler(
|
updateHandler = createUpdateHandler(
|
||||||
solrConfig.get("updateHandler/@class", DirectUpdateHandler.class.getName())
|
solrConfig.get("updateHandler/@class", DirectUpdateHandler.class.getName())
|
||||||
);
|
);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new RuntimeException(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() {
|
public void close() {
|
||||||
close(true);
|
log.info("CLOSING SolrCore!");
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
closeSearcher();
|
closeSearcher();
|
||||||
} catch (Exception e) {
|
} 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
|
@Override
|
||||||
protected void finalize() { close(); }
|
protected void finalize() { close(); }
|
||||||
|
|
||||||
|
|
|
@ -63,13 +63,6 @@ public abstract class AbstractSolrTestCase extends TestCase {
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
protected TestHarness.LocalRequestFactory lrf;
|
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
|
* 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 {
|
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")
|
dataDir = new File(System.getProperty("java.io.tmpdir")
|
||||||
+ System.getProperty("file.separator")
|
+ System.getProperty("file.separator")
|
||||||
+ getClass().getName() + "-" + System.currentTimeMillis());
|
+ getClass().getName() + "-" + System.currentTimeMillis());
|
||||||
|
|
||||||
}
|
|
||||||
dataDir.mkdirs();
|
dataDir.mkdirs();
|
||||||
|
|
||||||
solrConfig = h.createConfig(getSolrConfigFile());
|
solrConfig = h.createConfig(getSolrConfigFile());
|
||||||
h = new TestHarness(coreName,
|
h = new TestHarness( dataDir.getAbsolutePath(),
|
||||||
dataDir.getAbsolutePath(),
|
|
||||||
solrConfig,
|
solrConfig,
|
||||||
getSchemaFile());
|
getSchemaFile());
|
||||||
lrf = h.getRequestFactory
|
lrf = h.getRequestFactory
|
||||||
("standard",0,20,"version","2.2");
|
("standard",0,20,"version","2.2");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -84,17 +84,18 @@ public class TestHarness {
|
||||||
*
|
*
|
||||||
* @param dataDirectory path for index data, will not be cleaned up
|
* @param dataDirectory path for index data, will not be cleaned up
|
||||||
*/
|
*/
|
||||||
public TestHarness(String name, String dataDirectory) {
|
public TestHarness( String dataDirectory) {
|
||||||
this(name, dataDirectory, "schema.xml");
|
this( dataDirectory, "schema.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assumes "solrconfig.xml" is the config file to use.
|
* Assumes "solrconfig.xml" is the config file to use.
|
||||||
*
|
*
|
||||||
* @param dataDirectory path for index data, will not be cleaned up
|
* @param dataDirectory path for index data, will not be cleaned up
|
||||||
* @param schemaFile path of schema file
|
* @param schemaFile path of schema file
|
||||||
*/
|
*/
|
||||||
public TestHarness(String name, String dataDirectory, String schemaFile) {
|
public TestHarness( String dataDirectory, String schemaFile) {
|
||||||
this(name, dataDirectory, "solrconfig.xml", schemaFile);
|
this( dataDirectory, "solrconfig.xml", schemaFile);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param name the core name
|
* @param name the core name
|
||||||
|
@ -102,8 +103,8 @@ public class TestHarness {
|
||||||
* @param configFile solrconfig filename
|
* @param configFile solrconfig filename
|
||||||
* @param schemaFile schema filename
|
* @param schemaFile schema filename
|
||||||
*/
|
*/
|
||||||
public TestHarness(String name, String dataDirectory, String configFile, String schemaFile) {
|
public TestHarness( String dataDirectory, String configFile, String schemaFile) {
|
||||||
this(name, dataDirectory, createConfig(configFile), schemaFile);
|
this( dataDirectory, createConfig(configFile), schemaFile);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param name the core name
|
* @param name the core name
|
||||||
|
@ -111,11 +112,10 @@ public class TestHarness {
|
||||||
* @param solrConfig solronfig instance
|
* @param solrConfig solronfig instance
|
||||||
* @param schemaFile schema filename
|
* @param schemaFile schema filename
|
||||||
*/
|
*/
|
||||||
public TestHarness(String name,
|
public TestHarness( String dataDirectory,
|
||||||
String dataDirectory,
|
|
||||||
SolrConfig solrConfig,
|
SolrConfig solrConfig,
|
||||||
String schemaFile) {
|
String schemaFile) {
|
||||||
this(name, dataDirectory, solrConfig, new IndexSchema(solrConfig, schemaFile));
|
this( dataDirectory, solrConfig, new IndexSchema(solrConfig, schemaFile));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param name the core name
|
* @param name the core name
|
||||||
|
@ -123,12 +123,11 @@ public class TestHarness {
|
||||||
* @param solrConfig solrconfig instance
|
* @param solrConfig solrconfig instance
|
||||||
* @param schema schema instance
|
* @param schema schema instance
|
||||||
*/
|
*/
|
||||||
public TestHarness(String name,
|
public TestHarness( String dataDirectory,
|
||||||
String dataDirectory,
|
|
||||||
SolrConfig solrConfig,
|
SolrConfig solrConfig,
|
||||||
IndexSchema indexSchema) {
|
IndexSchema indexSchema) {
|
||||||
try {
|
try {
|
||||||
core = new SolrCore(name, dataDirectory, solrConfig, indexSchema);
|
core = new SolrCore( dataDirectory, solrConfig, indexSchema);
|
||||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
|
|
||||||
updater = new XmlUpdateRequestHandler();
|
updater = new XmlUpdateRequestHandler();
|
||||||
|
|
|
@ -34,8 +34,7 @@ public class TestBadConfig extends AbstractSolrTestCase {
|
||||||
dataDir.mkdirs();
|
dataDir.mkdirs();
|
||||||
try {
|
try {
|
||||||
solrConfig = new SolrConfig(getSolrConfigFile());
|
solrConfig = new SolrConfig(getSolrConfigFile());
|
||||||
h = new TestHarness(getName() + "-" + System.currentTimeMillis(),
|
h = new TestHarness( dataDir.getAbsolutePath(),
|
||||||
dataDir.getAbsolutePath(),
|
|
||||||
solrConfig,
|
solrConfig,
|
||||||
getSchemaFile());
|
getSchemaFile());
|
||||||
fail("Exception should have been thrown");
|
fail("Exception should have been thrown");
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class SolrDispatchFilter implements Filter
|
||||||
|
|
||||||
// Let this filter take care of /select?xxx format
|
// Let this filter take care of /select?xxx format
|
||||||
this.handleSelect =
|
this.handleSelect =
|
||||||
SolrConfig.config.getBool( "requestDispatcher/@handleSelect", false );
|
core.getSolrConfig().getBool( "requestDispatcher/@handleSelect", false );
|
||||||
}
|
}
|
||||||
catch( Throwable t ) {
|
catch( Throwable t ) {
|
||||||
// catch this so our filter still works
|
// catch this so our filter still works
|
||||||
|
@ -78,7 +78,7 @@ public class SolrDispatchFilter implements Filter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally abort if we found a sever error
|
// 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 ) {
|
if( abortOnConfigurationError && SolrConfig.severeErrors.size() > 0 ) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter out = new PrintWriter( sw );
|
PrintWriter out = new PrintWriter( sw );
|
||||||
|
|
Loading…
Reference in New Issue