Skip to content

Commit 6fc60dd

Browse files
committed
Revert "SOLR-17875: Rationalize bootstrap_conf, bootstrap_confdir, and -Dcollection.configName in start up scripts (#3512)"
This reverts commit c3ed5a8
1 parent 3ceae64 commit 6fc60dd

File tree

7 files changed

+80
-49
lines changed

7 files changed

+80
-49
lines changed

solr/bin/solr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,11 @@ if [ "${SOLR_MODE:-}" == 'solrcloud' ]; then
10911091
CLOUD_MODE_OPTS+=("-DcreateZkChroot=$ZK_CREATE_CHROOT")
10921092
fi
10931093

1094+
# and if collection1 needs to be bootstrapped
1095+
if [ -e "$SOLR_HOME/collection1/core.properties" ]; then
1096+
CLOUD_MODE_OPTS+=('-Dbootstrap_confdir=./solr/collection1/conf' '-Dcollection.configName=myconf' '-DnumShards=1')
1097+
fi
1098+
10941099
if [ "${SOLR_SOLRXML_REQUIRED:-false}" == "true" ]; then
10951100
CLOUD_MODE_OPTS+=("-Dsolr.solrxml.required=true")
10961101
fi

solr/bin/solr.cmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,10 @@ IF "%SOLR_MODE%"=="solrcloud" (
936936
set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -Dsolr.solrxml.required=true"
937937
)
938938

939+
IF EXIST "%SOLR_HOME%\collection1\core.properties" set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -Dbootstrap_confdir=./solr/collection1/conf -Dcollection.configName=myconf -DnumShards=1"
940+
) ELSE (
941+
REM change Cloud mode to User Managed mode with flag
942+
set "CLOUD_MODE_OPTS="
939943
IF NOT EXIST "%SOLR_HOME%\solr.xml" (
940944
IF "%SOLR_SOLRXML_REQUIRED%"=="true" (
941945
set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% must contain solr.xml!"

solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ public static void createCollectionZkNode(
683683
stateManager, collection, collectionPath, collectionProps, configSetService);
684684
}
685685

686-
} else if (System.getProperty("solr.configset.bootstrap.confdir") != null) {
686+
} else if (System.getProperty("bootstrap_confdir") != null) {
687687
String defaultConfigName =
688688
System.getProperty(
689689
ZkController.COLLECTION_PARAM_PREFIX + ZkController.CONFIGNAME_PROP,
@@ -706,6 +706,9 @@ public static void createCollectionZkNode(
706706
if (!collectionProps.containsKey(ZkController.CONFIGNAME_PROP))
707707
collectionProps.put(ZkController.CONFIGNAME_PROP, defaultConfigName);
708708

709+
} else if (Boolean.getBoolean("bootstrap_conf")) {
710+
// the conf name should should be the collection name of this core
711+
collectionProps.put(ZkController.CONFIGNAME_PROP, collection);
709712
} else {
710713
getConfName(
711714
stateManager, collection, collectionPath, collectionProps, configSetService);

solr/core/src/java/org/apache/solr/core/ConfigSetService.java

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import org.apache.solr.cloud.ZkController;
3232
import org.apache.solr.common.ConfigNode;
3333
import org.apache.solr.common.SolrException;
34-
import org.apache.solr.common.util.EnvUtils;
3534
import org.apache.solr.common.util.NamedList;
35+
import org.apache.solr.common.util.StrUtils;
3636
import org.apache.solr.handler.admin.ConfigSetsHandler;
3737
import org.apache.solr.schema.IndexSchema;
3838
import org.apache.solr.schema.IndexSchemaFactory;
@@ -85,17 +85,22 @@ private static ConfigSetService instantiate(CoreContainer coreContainer) {
8585
}
8686

8787
private void bootstrapConfigSet(CoreContainer coreContainer) {
88-
// bootstrap _default conf and solr.configset.bootstrap.confdir if specified.
88+
// bootstrap _default conf, bootstrap_confdir and bootstrap_conf if provided via system property
8989
try {
9090
// _default conf
9191
bootstrapDefaultConf();
9292

93-
// solr.configset.bootstrap.confdir
94-
String confDir = EnvUtils.getProperty("solr.configset.bootstrap.confdir");
93+
// bootstrap_confdir
94+
String confDir = System.getProperty("bootstrap_confdir");
9595
if (confDir != null) {
9696
bootstrapConfDir(confDir);
9797
}
9898

99+
// bootstrap_conf
100+
boolean boostrapConf = Boolean.getBoolean("bootstrap_conf");
101+
if (boostrapConf == true) {
102+
bootstrapConf(coreContainer);
103+
}
99104
} catch (IOException e) {
100105
throw new SolrException(
101106
SolrException.ErrorCode.SERVER_ERROR, "Config couldn't be uploaded ", e);
@@ -109,22 +114,23 @@ private void bootstrapDefaultConf() throws IOException {
109114
log.warn(
110115
"The _default configset could not be uploaded. Please provide 'solr.configset.default.confdir' parameter that points to a configset {} {}",
111116
"intended to be the default. Current 'solr.configset.default.confdir' value:",
112-
EnvUtils.getProperty(SolrDispatchFilter.SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE));
117+
System.getProperty(SolrDispatchFilter.SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE));
113118
} else {
114119
this.uploadConfig(ConfigSetsHandler.DEFAULT_CONFIGSET_NAME, configDirPath);
115120
}
116121
}
117122
}
118123

119124
private void bootstrapConfDir(String confDir) throws IOException {
120-
Path configPath = resolvePathWithSolrInstallDir(confDir);
121-
125+
Path configPath = Path.of(confDir);
122126
if (!Files.isDirectory(configPath)) {
123127
throw new IllegalArgumentException(
124-
"solr.configset.bootstrap.confdir must be a directory of configuration files, configPath: "
128+
"bootstrap_confdir must be a directory of configuration files, configPath: "
125129
+ configPath);
126130
}
127-
String confName = EnvUtils.getProperty("solr.collection.config.name", "configuration1");
131+
String confName =
132+
System.getProperty(
133+
ZkController.COLLECTION_PARAM_PREFIX + ZkController.CONFIGNAME_PROP, "configuration1");
128134
this.uploadConfig(confName, configPath);
129135
}
130136

@@ -133,23 +139,23 @@ private void bootstrapConfDir(String confDir) throws IOException {
133139
* sysprop "solr.configset.default.confdir". If not found, tries to find the _default dir relative
134140
* to the sysprop "solr.install.dir". Returns null if not found anywhere.
135141
*
142+
* @lucene.internal
136143
* @see SolrDispatchFilter#SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE
137144
*/
138145
public static Path getDefaultConfigDirPath() {
139146
String confDir =
140-
EnvUtils.getProperty(SolrDispatchFilter.SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE);
147+
System.getProperty(SolrDispatchFilter.SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE);
141148
if (confDir != null) {
142-
Path path = resolvePathWithSolrInstallDir(confDir);
149+
Path path = Path.of(confDir);
143150
if (Files.exists(path)) {
144151
return path;
145152
}
146153
}
147154

148-
String installDir = EnvUtils.getProperty(SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE);
155+
String installDir = System.getProperty(SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE);
149156
if (installDir != null) {
150-
Path installPath = resolvePathWithSolrInstallDir(installDir);
151157
Path subPath = Path.of("server", "solr", "configsets", "_default", "conf");
152-
Path path = installPath.resolve(subPath);
158+
Path path = Path.of(installDir).resolve(subPath);
153159
if (Files.exists(path)) {
154160
return path;
155161
}
@@ -158,27 +164,6 @@ public static Path getDefaultConfigDirPath() {
158164
return null;
159165
}
160166

161-
/**
162-
* Resolves a path string into a Path object, handling both absolute and relative paths. If the
163-
* path is relative then it resolves it against Solr installation directory by looking up the
164-
* solr.install.dir system property.
165-
*
166-
* @param pathStr The path of the directory to resolve
167-
* @return The resolved Path object
168-
* @see SolrDispatchFilter#SOLR_INSTALL_DIR_ATTRIBUTE
169-
*/
170-
public static Path resolvePathWithSolrInstallDir(String pathStr) {
171-
Path path = Path.of(pathStr);
172-
173-
// Convert to absolute path if it's relative
174-
if (!path.isAbsolute()) {
175-
String installDir = EnvUtils.getProperty(SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE);
176-
path = Path.of(installDir).resolve(path).normalize();
177-
}
178-
179-
return path;
180-
}
181-
182167
// Order is important here since "confDir" may be
183168
// 1> a full path to the parent of a solrconfig.xml or parent of /conf/solrconfig.xml
184169
// 2> one of the canned config sets only, e.g. _default
@@ -213,6 +198,28 @@ public static Path getConfigsetPath(String confDir, String configSetDir) {
213198
Path.of(configSetDir, confDir, "conf", "solrconfig.xml").normalize().toAbsolutePath()));
214199
}
215200

201+
/** If in SolrCloud mode, upload configSets for each SolrCore in solr.xml. */
202+
public static void bootstrapConf(CoreContainer cc) throws IOException {
203+
// List<String> allCoreNames = cfg.getAllCoreNames();
204+
List<CoreDescriptor> cds = cc.getCoresLocator().discover(cc);
205+
206+
if (log.isInfoEnabled()) {
207+
log.info(
208+
"bootstrapping config for {} cores into ZooKeeper using solr.xml from {}",
209+
cds.size(),
210+
cc.getSolrHome());
211+
}
212+
213+
for (CoreDescriptor cd : cds) {
214+
String coreName = cd.getName();
215+
String confName = cd.getCollectionName();
216+
if (StrUtils.isNullOrEmpty(confName)) confName = coreName;
217+
Path udir = cd.getInstanceDir().resolve("conf");
218+
log.info("Uploading directory {} with name {} for solrCore {}", udir, confName, coreName);
219+
cc.getConfigSetService().uploadConfig(confName, udir);
220+
}
221+
}
222+
216223
/**
217224
* Load the ConfigSet for a core
218225
*

solr/packaging/test/test_start_solr.bats

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,3 @@ teardown() {
9393
solr start --jettyconfig "--module=server"
9494
solr assert --started http://localhost:${SOLR_PORT} --timeout 5000
9595
}
96-
97-
@test "bootstrap configset using bootstrap_confdir and collection.configName" {
98-
local confdir_path="${SOLR_TIP}/server/solr/configsets/sample_techproducts_configs/conf"
99-
test -d "${confdir_path}"
100-
101-
# This uploads the sample_techproducts_configs/conf directory as "techproducts_bootstrapped" configset
102-
solr start -Dsolr.configset.bootstrap.confdir="${confdir_path}" -Dsolr.collection.config.name=techproducts_bootstrapped
103-
104-
solr assert --started http://localhost:${SOLR_PORT} --timeout 5000
105-
config_exists "techproducts_bootstrapped"
106-
}

solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
import java.security.NoSuchAlgorithmException;
2424
import java.util.Arrays;
2525
import java.util.List;
26+
import java.util.Properties;
2627
import java.util.concurrent.TimeUnit;
2728
import org.apache.curator.framework.AuthInfo;
2829
import org.apache.curator.framework.api.ACLProvider;
2930
import org.apache.solr.SolrTestCaseJ4;
31+
import org.apache.solr.cloud.AbstractZkTestCase;
3032
import org.apache.solr.cloud.ZkConfigSetService;
3133
import org.apache.solr.cloud.ZkTestServer;
3234
import org.apache.solr.common.SolrException;
3335
import org.apache.solr.core.ConfigSetService;
36+
import org.apache.solr.core.CoreContainer;
3437
import org.apache.solr.util.LogLevel;
3538
import org.apache.zookeeper.KeeperException;
3639
import org.apache.zookeeper.ZooDefs;
@@ -225,6 +228,28 @@ public void testUploadWithACL() throws IOException, NoSuchAlgorithmException {
225228
}
226229
}
227230

231+
@Test
232+
public void testBootstrapConf() throws IOException, KeeperException, InterruptedException {
233+
234+
Path solrHome = legacyExampleCollection1SolrHome();
235+
236+
CoreContainer cc = new CoreContainer(solrHome, new Properties());
237+
System.setProperty("zkHost", zkServer.getZkAddress());
238+
239+
SolrZkClient zkClient =
240+
new SolrZkClient.Builder()
241+
.withUrl(zkServer.getZkHost())
242+
.withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS)
243+
.build();
244+
zkClient.makePath("/solr", false, true);
245+
cc.setCoreConfigService(new ZkConfigSetService(zkClient));
246+
assertFalse(cc.getConfigSetService().checkConfigExists("collection1"));
247+
ConfigSetService.bootstrapConf(cc);
248+
assertTrue(cc.getConfigSetService().checkConfigExists("collection1"));
249+
250+
zkClient.close();
251+
}
252+
228253
static SolrZkClient buildZkClient(
229254
String zkAddress,
230255
final ACLProvider aclProvider,

solr/solrj/src/resources/DeprecatedSystemPropertyMappings.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,3 @@ basicauth=solr.security.auth.basicauth.credentials
2828
cloud.solr.client.max.stale.retries=solr.solrj.cloud.max.stale.retries
2929
configset.upload.enabled=solr.configset.upload.enabled
3030
solr.hidden.sys.props=solr.responses.hidden.sys.props
31-
bootstrap_confdir=solr.configset.bootstrap.confdir
32-
collection.config.name=solr.collection.config.name

0 commit comments

Comments
 (0)