You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2021/03/02 03:28:13 UTC
[lucene-solr] branch master updated: SOLR-15100: make
ConfigSetService configurable in solr.xml (#2343)
This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/master by this push:
new 8b44342 SOLR-15100: make ConfigSetService configurable in solr.xml (#2343)
8b44342 is described below
commit 8b443420b878f236c78973ec546d1988ac6b7bdb
Author: 百岁 <mo...@126.com>
AuthorDate: Tue Mar 2 11:27:37 2021 +0800
SOLR-15100: make ConfigSetService configurable in solr.xml (#2343)
---
solr/CHANGES.txt | 3 ++
.../org/apache/solr/core/ConfigSetService.java | 24 ++++++++++++--
.../java/org/apache/solr/core/CoreContainer.java | 6 +++-
.../src/java/org/apache/solr/core/NodeConfig.java | 18 +++++++++--
.../java/org/apache/solr/core/SolrXmlConfig.java | 3 ++
.../org/apache/solr/core/TestCoreContainer.java | 37 ++++++++++++++++++++++
solr/solr-ref-guide/src/format-of-solr-xml.adoc | 7 ++++
7 files changed, 92 insertions(+), 6 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 321f5b3..c7afbce 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -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)
diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSetService.java b/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
index cdea9d9..949d4ff0 100644
--- a/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
+++ b/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
@@ -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;
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index 15741c8..2018798 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -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;
}
diff --git a/solr/core/src/java/org/apache/solr/core/NodeConfig.java b/solr/core/src/java/org/apache/solr/core/NodeConfig.java
index bd2202f..a0daade 100644
--- a/solr/core/src/java/org/apache/solr/core/NodeConfig.java
+++ b/solr/core/src/java/org/apache/solr/core/NodeConfig.java
@@ -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) {
diff --git a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
index c922982..7c941ee 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
@@ -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;
diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
index fce70e3..26c517e 100644
--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
@@ -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<>();
diff --git a/solr/solr-ref-guide/src/format-of-solr-xml.adoc b/solr/solr-ref-guide/src/format-of-solr-xml.adoc
index bdae4e5..459e49a 100644
--- a/solr/solr-ref-guide/src/format-of-solr-xml.adoc
+++ b/solr/solr-ref-guide/src/format-of-solr-xml.adoc
@@ -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.
+