mirror of https://github.com/apache/lucene.git
SOLR-638 -- add a reference to CoreDescriptor within SolrCore and give that access to MultiCore. This will inable inter-core communiction from anywhere that has access to a core.
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@677941 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d86a9b8a20
commit
d0664e7856
|
@ -17,6 +17,11 @@
|
|||
|
||||
package org.apache.solr.core;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A Solr core descriptor
|
||||
* @since solr 1.3
|
||||
|
@ -27,9 +32,12 @@ public class CoreDescriptor implements Cloneable {
|
|||
protected String configName;
|
||||
protected String schemaName;
|
||||
protected SolrCore core = null;
|
||||
private final MultiCore multiCore;
|
||||
|
||||
public CoreDescriptor(MultiCore multiCore) {
|
||||
this.multiCore = multiCore;
|
||||
}
|
||||
|
||||
public CoreDescriptor() {}
|
||||
|
||||
/** Initialize defaults from instance directory. */
|
||||
public void init(String name, String instanceDir) {
|
||||
if (name == null) {
|
||||
|
@ -50,6 +58,7 @@ public class CoreDescriptor implements Cloneable {
|
|||
this.instanceDir = descr.instanceDir;
|
||||
this.configName = descr.configName;
|
||||
this.schemaName = descr.schemaName;
|
||||
multiCore = descr.multiCore;
|
||||
}
|
||||
|
||||
/**@return the default config name. */
|
||||
|
@ -92,13 +101,13 @@ public class CoreDescriptor implements Cloneable {
|
|||
/**@return the core configuration resource name. */
|
||||
public String getConfigName() {
|
||||
return this.configName;
|
||||
}
|
||||
}
|
||||
|
||||
/**Sets the core schema resource name. */
|
||||
public void setSchemaName(String name) {
|
||||
if (name == null || name.length() == 0)
|
||||
throw new IllegalArgumentException("name can not be null or empty");
|
||||
this.schemaName = name;
|
||||
this.schemaName = name;
|
||||
}
|
||||
|
||||
/**@return the core schema resource name. */
|
||||
|
@ -113,4 +122,19 @@ public class CoreDescriptor implements Cloneable {
|
|||
public void setCore(SolrCore core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public void reloadCore() throws IOException, ParserConfigurationException, SAXException {
|
||||
SolrCore old = core;
|
||||
if (multiCore != null) {
|
||||
multiCore.create(this);
|
||||
} else {
|
||||
SolrConfig cfg = new SolrConfig(old.getConfigResource());
|
||||
core = new SolrCore(null, null, cfg, null, this);
|
||||
}
|
||||
old.close();
|
||||
}
|
||||
|
||||
public MultiCore getMultiCore() {
|
||||
return multiCore;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ public class MultiCore
|
|||
for (int i=0; i<nodes.getLength(); i++) {
|
||||
Node node = nodes.item(i);
|
||||
try {
|
||||
CoreDescriptor p = new CoreDescriptor();
|
||||
CoreDescriptor p = new CoreDescriptor(this);
|
||||
p.init(DOMUtil.getAttr(node, "name", null), DOMUtil.getAttr(node, "instanceDir", null));
|
||||
// deal with optional settings
|
||||
String opt = DOMUtil.getAttr(node, "config", null);
|
||||
|
@ -252,7 +252,7 @@ public class MultiCore
|
|||
SolrResourceLoader solrLoader = new SolrResourceLoader(instanceDir, libLoader);
|
||||
SolrConfig config = new SolrConfig(solrLoader, dcore.getConfigName(), null);
|
||||
IndexSchema schema = new IndexSchema(config, dcore.getSchemaName(), null);
|
||||
SolrCore core = new SolrCore(dcore.getName(), null, config, schema);
|
||||
SolrCore core = new SolrCore(dcore.getName(), null, config, schema, dcore);
|
||||
dcore.setCore(core);
|
||||
|
||||
// Register the new core
|
||||
|
|
|
@ -69,6 +69,7 @@ public final class SolrCore {
|
|||
|
||||
private String name;
|
||||
private String logid; // used to show what name is set
|
||||
private final CoreDescriptor coreDescriptor;
|
||||
|
||||
private final SolrConfig solrConfig;
|
||||
private final IndexSchema schema;
|
||||
|
@ -336,7 +337,7 @@ public final class SolrCore {
|
|||
if( instance == null ) {
|
||||
try {
|
||||
// sets 'instance' to the latest solr core
|
||||
instance = new SolrCore( null, null, new SolrConfig(), null);
|
||||
instance = new SolrCore( null, null, new SolrConfig(), null, null);
|
||||
} catch(Exception xany) {
|
||||
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
|
||||
"error creating core", xany );
|
||||
|
@ -346,8 +347,18 @@ public final class SolrCore {
|
|||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dataDir
|
||||
* @param schema
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @throws ParserConfigurationException
|
||||
*
|
||||
* @since solr 1.0
|
||||
*/
|
||||
public SolrCore(String dataDir, IndexSchema schema) throws ParserConfigurationException, IOException, SAXException {
|
||||
this( null, dataDir, new SolrConfig(), schema );
|
||||
this( null, dataDir, new SolrConfig(), schema, null );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -356,9 +367,12 @@ public final class SolrCore {
|
|||
*@param dataDir the index directory
|
||||
*@param config a solr config instance
|
||||
*@param schema a solr schema instance
|
||||
*
|
||||
*@since solr 1.3
|
||||
*/
|
||||
public SolrCore(String name, String dataDir, SolrConfig config, IndexSchema schema) {
|
||||
public SolrCore(String name, String dataDir, SolrConfig config, IndexSchema schema, CoreDescriptor cd) {
|
||||
synchronized (SolrCore.class) {
|
||||
coreDescriptor = cd;
|
||||
// this is for backward compatibility (and also the reason
|
||||
// the sync block is needed)
|
||||
instance = this; // set singleton
|
||||
|
@ -1200,7 +1214,11 @@ public final class SolrCore {
|
|||
public ValueSourceParser getValueSourceParser(String parserName) {
|
||||
return valueSourceParsers.get(parserName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public CoreDescriptor getCoreDescriptor() {
|
||||
return coreDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ public abstract class MultiCoreHandler extends RequestHandlerBase
|
|||
// Handle a core creation
|
||||
//---------------------------------------------------------
|
||||
if (action == MultiCoreAction.CREATE) {
|
||||
CoreDescriptor dcore = new CoreDescriptor();
|
||||
CoreDescriptor dcore = new CoreDescriptor(manager);
|
||||
dcore.init(params.get(MultiCoreParams.NAME),
|
||||
params.get(MultiCoreParams.INSTANCE_DIR));
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ public class TestHarness {
|
|||
SolrConfig solrConfig,
|
||||
IndexSchema indexSchema) {
|
||||
try {
|
||||
core = new SolrCore( null, dataDirectory, solrConfig, indexSchema);
|
||||
core = new SolrCore( null, dataDirectory, solrConfig, indexSchema, null);
|
||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
|
||||
updater = new XmlUpdateRequestHandler();
|
||||
|
|
|
@ -106,7 +106,7 @@ public class DirectSolrConnection
|
|||
|
||||
// If the Data directory is specified, initialize SolrCore directly
|
||||
IndexSchema schema = new IndexSchema(config, instanceDir+"/conf/schema.xml", null);
|
||||
core = new SolrCore( null, dataDir, config, schema );
|
||||
core = new SolrCore( null, dataDir, config, schema, null );
|
||||
parser = new SolrRequestParsers( config );
|
||||
}
|
||||
catch (Exception ee) {
|
||||
|
|
|
@ -35,12 +35,8 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.common.params.CommonParams;
|
||||
import org.apache.solr.core.MultiCore;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
import org.apache.solr.core.*;
|
||||
import org.apache.solr.request.*;
|
||||
import org.apache.solr.servlet.cache.HttpCacheHeaderUtil;
|
||||
import org.apache.solr.servlet.cache.Method;
|
||||
|
@ -54,7 +50,8 @@ public class SolrDispatchFilter implements Filter
|
|||
{
|
||||
final Logger log = Logger.getLogger(SolrDispatchFilter.class.getName());
|
||||
|
||||
protected SolrCore singlecore;
|
||||
protected CoreDescriptor singleCoreDescriptor;
|
||||
|
||||
protected MultiCore multicore;
|
||||
protected String pathPrefix = null; // strip this from the beginning of a path
|
||||
protected String abortErrorMessage = null;
|
||||
|
@ -76,7 +73,7 @@ public class SolrDispatchFilter implements Filter
|
|||
|
||||
if(multicore != null && multicore.isEnabled() ) {
|
||||
abortOnConfigurationError = false;
|
||||
singlecore = null;
|
||||
singleCoreDescriptor = null;
|
||||
// if any core aborts on startup, then abort
|
||||
for( SolrCore c : multicore.getCores() ) {
|
||||
if( c.getSolrConfig().getBool( "abortOnConfigurationError",false) ) {
|
||||
|
@ -87,7 +84,10 @@ public class SolrDispatchFilter implements Filter
|
|||
}
|
||||
else {
|
||||
SolrConfig cfg = this.solrConfigFilename == null? new SolrConfig() : new SolrConfig(this.solrConfigFilename);
|
||||
singlecore = new SolrCore( null, null, cfg, null );
|
||||
singleCoreDescriptor = new CoreDescriptor((MultiCore)null);
|
||||
singleCoreDescriptor.init("",cfg.getResourceLoader().getInstanceDir());
|
||||
SolrCore singlecore = new SolrCore( null, null, cfg, null, singleCoreDescriptor);
|
||||
singleCoreDescriptor.setCore(singlecore);
|
||||
abortOnConfigurationError = cfg.getBool(
|
||||
"abortOnConfigurationError", abortOnConfigurationError);
|
||||
}
|
||||
|
@ -155,9 +155,9 @@ public class SolrDispatchFilter implements Filter
|
|||
multicore.shutdown();
|
||||
multicore = null;
|
||||
}
|
||||
if( singlecore != null ) {
|
||||
singlecore.close();
|
||||
singlecore = null;
|
||||
if( singleCoreDescriptor != null ) {
|
||||
singleCoreDescriptor.getCore().close();
|
||||
singleCoreDescriptor = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ public class SolrDispatchFilter implements Filter
|
|||
}
|
||||
}
|
||||
else {
|
||||
core = singlecore;
|
||||
core = singleCoreDescriptor.getCore();
|
||||
}
|
||||
|
||||
// With a valid core...
|
||||
|
@ -309,7 +309,7 @@ public class SolrDispatchFilter implements Filter
|
|||
else {
|
||||
req.setAttribute("org.apache.solr.SolrCore", core);
|
||||
// Modify the request so each core gets its own /admin
|
||||
if( singlecore == null && path.startsWith( "/admin" ) ) {
|
||||
if( singleCoreDescriptor == null && path.startsWith( "/admin" ) ) {
|
||||
req.getRequestDispatcher( pathPrefix == null ? path : pathPrefix + path ).forward( request, response );
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue