mirror of https://github.com/apache/lucene.git
SOLR-15100: make ConfigSetService configurable in solr.xml (#2343)
This commit is contained in:
parent
9e8207a558
commit
8b443420b8
|
@ -85,6 +85,9 @@ when told to. The admin UI now tells it to. (Nazerke Seidan, David Smiley)
|
|||
* SOLR-15156: [child] doc transformer's childFilter param no longer applies query syntax
|
||||
escaping. It was inconsistent with other Solr options. (David Smiley)
|
||||
|
||||
* SOLR-15100: Make the ConfigSetService pluggable/configurable via <string name="configSetService" /> in solr.xml
|
||||
(baisui)
|
||||
|
||||
Other Changes
|
||||
----------------------
|
||||
* SOLR-14656: Autoscaling framework removed (Ishan Chattopadhyaya, noble, Ilan Ginzburg)
|
||||
|
|
|
@ -20,6 +20,8 @@ import java.io.FileNotFoundException;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -55,12 +57,28 @@ public abstract class ConfigSetService {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
public static ConfigSetService createConfigSetService(NodeConfig nodeConfig, SolrResourceLoader loader, ZkController zkController) {
|
||||
if (zkController == null) {
|
||||
public static ConfigSetService createConfigSetService(CoreContainer coreContainer) {
|
||||
|
||||
NodeConfig nodeConfig = coreContainer.getConfig();
|
||||
SolrResourceLoader loader = coreContainer.getResourceLoader();
|
||||
ZkController zkController = coreContainer.getZkController();
|
||||
|
||||
String configSetServiceClass = nodeConfig.getConfigSetServiceClass();
|
||||
|
||||
if(configSetServiceClass != null){
|
||||
try {
|
||||
Class<? extends ConfigSetService> clazz = loader.findClass(configSetServiceClass, ConfigSetService.class);
|
||||
Constructor<? extends ConfigSetService> constructor = clazz.getConstructor(CoreContainer.class);
|
||||
return constructor.newInstance(coreContainer);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("create configSetService instance faild,configSetServiceClass:" + configSetServiceClass, e);
|
||||
}
|
||||
}else if(zkController == null){
|
||||
return new Standalone(loader, nodeConfig.hasSchemaCache(), nodeConfig.getConfigSetBaseDirectory());
|
||||
} else {
|
||||
}else{
|
||||
return new CloudConfigSetService(loader, nodeConfig.hasSchemaCache(), zkController);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected final SolrResourceLoader parentLoader;
|
||||
|
|
|
@ -785,7 +785,7 @@ public class CoreContainer {
|
|||
metricManager.loadReporters(metricReporters, loader, this, null, null, SolrInfoBean.Group.jvm);
|
||||
metricManager.loadReporters(metricReporters, loader, this, null, null, SolrInfoBean.Group.jetty);
|
||||
|
||||
coreConfigService = ConfigSetService.createConfigSetService(cfg, loader, zkSys.zkController);
|
||||
coreConfigService = ConfigSetService.createConfigSetService(this);
|
||||
|
||||
containerProperties.putAll(cfg.getSolrProperties());
|
||||
|
||||
|
@ -2030,6 +2030,10 @@ public class CoreContainer {
|
|||
return configSetsHandler;
|
||||
}
|
||||
|
||||
public ConfigSetService getConfigSetService() {
|
||||
return this.coreConfigService;
|
||||
}
|
||||
|
||||
public String getHostName() {
|
||||
return this.hostName;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,8 @@ public class NodeConfig {
|
|||
|
||||
private final UpdateShardHandlerConfig updateShardHandlerConfig;
|
||||
|
||||
private final String configSetServiceClass;
|
||||
|
||||
private final String coreAdminHandlerClass;
|
||||
|
||||
private final String collectionsAdminHandlerClass;
|
||||
|
@ -89,6 +91,7 @@ public class NodeConfig {
|
|||
private final boolean fromZookeeper;
|
||||
private final String defaultZkHost;
|
||||
|
||||
|
||||
private NodeConfig(String nodeName, Path coreRootDirectory, Path solrDataHome, Integer booleanQueryMaxClauseCount,
|
||||
Path configSetBaseDirectory, String sharedLibDirectory,
|
||||
PluginInfo shardHandlerFactoryConfig, UpdateShardHandlerConfig updateShardHandlerConfig,
|
||||
|
@ -99,7 +102,7 @@ public class NodeConfig {
|
|||
Path solrHome, SolrResourceLoader loader,
|
||||
Properties solrProperties, PluginInfo[] backupRepositoryPlugins,
|
||||
MetricsConfig metricsConfig, PluginInfo transientCacheConfig, PluginInfo tracerConfig,
|
||||
boolean fromZookeeper, String defaultZkHost, Set<Path> allowPaths) {
|
||||
boolean fromZookeeper, String defaultZkHost, Set<Path> allowPaths,String configSetServiceClass) {
|
||||
// all Path params here are absolute and normalized.
|
||||
this.nodeName = nodeName;
|
||||
this.coreRootDirectory = coreRootDirectory;
|
||||
|
@ -131,6 +134,7 @@ public class NodeConfig {
|
|||
this.fromZookeeper = fromZookeeper;
|
||||
this.defaultZkHost = defaultZkHost;
|
||||
this.allowPaths = allowPaths;
|
||||
this.configSetServiceClass = configSetServiceClass;
|
||||
|
||||
if (this.cloudConfig != null && this.getCoreLoadThreadCount(false) < 2) {
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
||||
|
@ -140,6 +144,10 @@ public class NodeConfig {
|
|||
if (null == this.loader) throw new NullPointerException("loader");
|
||||
}
|
||||
|
||||
public String getConfigSetServiceClass() {
|
||||
return this.configSetServiceClass;
|
||||
}
|
||||
|
||||
public String getNodeName() {
|
||||
return nodeName;
|
||||
}
|
||||
|
@ -311,6 +319,7 @@ public class NodeConfig {
|
|||
private String sharedLibDirectory;
|
||||
private PluginInfo shardHandlerFactoryConfig;
|
||||
private UpdateShardHandlerConfig updateShardHandlerConfig = UpdateShardHandlerConfig.DEFAULT;
|
||||
private String configSetServiceClass;
|
||||
private String coreAdminHandlerClass = DEFAULT_ADMINHANDLERCLASS;
|
||||
private String collectionsAdminHandlerClass = DEFAULT_COLLECTIONSHANDLERCLASS;
|
||||
private String healthCheckHandlerClass = DEFAULT_HEALTHCHECKHANDLERCLASS;
|
||||
|
@ -507,6 +516,11 @@ public class NodeConfig {
|
|||
return this;
|
||||
}
|
||||
|
||||
public NodeConfigBuilder setConfigSetServiceClass(String configSetServiceClass){
|
||||
this.configSetServiceClass = configSetServiceClass;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeConfig build() {
|
||||
// if some things weren't set then set them now. Simple primitives are set on the field declaration
|
||||
if (loader == null) {
|
||||
|
@ -517,7 +531,7 @@ public class NodeConfig {
|
|||
updateShardHandlerConfig, coreAdminHandlerClass, collectionsAdminHandlerClass, healthCheckHandlerClass, infoHandlerClass, configSetsHandlerClass,
|
||||
logWatcherConfig, cloudConfig, coreLoadThreads, replayUpdatesThreads, transientCacheSize, useSchemaCache, managementPath,
|
||||
solrHome, loader, solrProperties,
|
||||
backupRepositoryPlugins, metricsConfig, transientCacheConfig, tracerConfig, fromZookeeper, defaultZkHost, allowPaths);
|
||||
backupRepositoryPlugins, metricsConfig, transientCacheConfig, tracerConfig, fromZookeeper, defaultZkHost, allowPaths, configSetServiceClass);
|
||||
}
|
||||
|
||||
public NodeConfigBuilder setSolrResourceLoader(SolrResourceLoader resourceLoader) {
|
||||
|
|
|
@ -308,6 +308,9 @@ public class SolrXmlConfig {
|
|||
case "configSetsHandler":
|
||||
builder.setConfigSetsHandlerClass(value);
|
||||
break;
|
||||
case "configSetService":
|
||||
builder.setConfigSetServiceClass(value);
|
||||
break;
|
||||
case "coreRootDirectory":
|
||||
builder.setCoreRootDirectory(value);
|
||||
break;
|
||||
|
|
|
@ -438,12 +438,38 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
|||
" <str name=\"configSetsHandler\">" + CustomConfigSetsHandler.class.getName() + "</str>" +
|
||||
"</solr>";
|
||||
|
||||
private static final String CUSTOM_CONFIG_SET_SERVICE_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
||||
"<solr>" +
|
||||
" <str name=\"configSetService\">" + CustomConfigSetService.class.getName() + "</str>" +
|
||||
"</solr>";
|
||||
|
||||
public static class CustomCollectionsHandler extends CollectionsHandler {
|
||||
public CustomCollectionsHandler(CoreContainer cc) {
|
||||
super(cc);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomConfigSetService extends ConfigSetService {
|
||||
public CustomConfigSetService(CoreContainer coreContainer) {
|
||||
super(coreContainer.getResourceLoader(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String configSetName(CoreDescriptor cd){
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SolrResourceLoader createCoreResourceLoader(CoreDescriptor cd){
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long getCurrentSchemaModificationVersion(String configSet, SolrConfig solrConfig, String schemaFileName) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomInfoHandler extends InfoHandler {
|
||||
public CustomInfoHandler(CoreContainer cc) {
|
||||
super(cc);
|
||||
|
@ -553,6 +579,17 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomConfigSetService() throws Exception {
|
||||
CoreContainer cc = init(CUSTOM_CONFIG_SET_SERVICE_SOLR_XML);
|
||||
try {
|
||||
assertThat(cc.getConfigSetService(), is(instanceOf(CustomConfigSetService.class)));
|
||||
}
|
||||
finally {
|
||||
cc.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private static class MockCoresLocator implements CoresLocator {
|
||||
|
||||
List<CoreDescriptor> cores = new ArrayList<>();
|
||||
|
|
|
@ -63,6 +63,13 @@ As you can see, the discovery Solr configuration is "SolrCloud friendly". Howeve
|
|||
|
||||
There are no attributes that you can specify in the `<solr>` tag, which is the root element of `solr.xml`. The tables below list the child nodes of each XML element in `solr.xml`.
|
||||
|
||||
`configSetService`::
|
||||
This attribute does not need to be set.
|
||||
+
|
||||
If used, this attribute should be set to the FQN (Fully qualified name) of a class that inherits from ConfigSetService , and you must provide a constructor with one param which the type is `org.apache.solr.core.CoreContainer` . For example, `<str name="configSetService">com.myorg.CustomConfigSetService</str>`.
|
||||
+
|
||||
If this attribute isn't set, Solr uses the default configSetService , with zookeeper aware of `org.apache.solr.cloud.CloudConfigSetService`, without zookeeper aware of `org.apache.solr.core.ConfigSetService.Standalone`.
|
||||
|
||||
`adminHandler`::
|
||||
This attribute does not need to be set.
|
||||
+
|
||||
|
|
Loading…
Reference in New Issue