Skip to content

Commit c3ed5a8

Browse files
epughCopilot
andauthored
SOLR-17875: Rationalize bootstrap_conf, bootstrap_confdir, and -Dcollection.configName in start up scripts (#3512)
* Add BATS test for bootstrap_confdir and collection.configName system properties Co-authored-by: epugh <[email protected]> * Complete BATS test for bootstrap_confdir system property with techproducts configset * Remove unused code, left over from old demo in early Solrcloud days related to "collection1" * Drop bootstrap_conf parameter * rename bootstrap_confdir to modern name * Add support for relative solr bootstrap path * assume Solr.install.dir is set. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: epugh <[email protected]>
1 parent 53ff6b2 commit c3ed5a8

File tree

7 files changed

+54
-80
lines changed

7 files changed

+54
-80
lines changed

solr/bin/solr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,11 +1091,6 @@ 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-
10991094
if [ "${SOLR_SOLRXML_REQUIRED:-false}" == "true" ]; then
11001095
CLOUD_MODE_OPTS+=("-Dsolr.solrxml.required=true")
11011096
fi

solr/bin/solr.cmd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,6 @@ 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="
943939
IF NOT EXIST "%SOLR_HOME%\solr.xml" (
944940
IF "%SOLR_SOLRXML_REQUIRED%"=="true" (
945941
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: 1 addition & 4 deletions
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("bootstrap_confdir") != null) {
686+
} else if (System.getProperty("solr.configset.bootstrap.confdir") != null) {
687687
String defaultConfigName =
688688
System.getProperty(
689689
ZkController.COLLECTION_PARAM_PREFIX + ZkController.CONFIGNAME_PROP,
@@ -706,9 +706,6 @@ 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);
712709
} else {
713710
getConfName(
714711
stateManager, collection, collectionPath, collectionProps, configSetService);

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

Lines changed: 40 additions & 42 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;
3435
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,22 +85,17 @@ private static ConfigSetService instantiate(CoreContainer coreContainer) {
8585
}
8686

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

93-
// bootstrap_confdir
94-
String confDir = System.getProperty("bootstrap_confdir");
93+
// solr.configset.bootstrap.confdir
94+
String confDir = EnvUtils.getProperty("solr.configset.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-
}
10499
} catch (IOException e) {
105100
throw new SolrException(
106101
SolrException.ErrorCode.SERVER_ERROR, "Config couldn't be uploaded ", e);
@@ -114,23 +109,27 @@ private void bootstrapDefaultConf() throws IOException {
114109
log.warn(
115110
"The _default configset could not be uploaded. Please provide 'solr.configset.default.confdir' parameter that points to a configset {} {}",
116111
"intended to be the default. Current 'solr.configset.default.confdir' value:",
117-
System.getProperty(SolrDispatchFilter.SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE));
112+
EnvUtils.getProperty(SolrDispatchFilter.SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE));
118113
} else {
119114
this.uploadConfig(ConfigSetsHandler.DEFAULT_CONFIGSET_NAME, configDirPath);
120115
}
121116
}
122117
}
123118

124119
private void bootstrapConfDir(String confDir) throws IOException {
125-
Path configPath = Path.of(confDir);
120+
if (!confDir.endsWith("conf")) {
121+
throw new IllegalArgumentException(
122+
"solr.configset.bootstrap.confdir must point to 'conf' directory, confDir: " + confDir);
123+
}
124+
125+
Path configPath = resolvePathWithSolrInstallDir(confDir);
126+
126127
if (!Files.isDirectory(configPath)) {
127128
throw new IllegalArgumentException(
128-
"bootstrap_confdir must be a directory of configuration files, configPath: "
129+
"solr.configset.bootstrap.confdir must be a directory of configuration files, configPath: "
129130
+ configPath);
130131
}
131-
String confName =
132-
System.getProperty(
133-
ZkController.COLLECTION_PARAM_PREFIX + ZkController.CONFIGNAME_PROP, "configuration1");
132+
String confName = EnvUtils.getProperty("solr.collection.config.name", "configuration1");
134133
this.uploadConfig(confName, configPath);
135134
}
136135

@@ -139,23 +138,23 @@ private void bootstrapConfDir(String confDir) throws IOException {
139138
* sysprop "solr.configset.default.confdir". If not found, tries to find the _default dir relative
140139
* to the sysprop "solr.install.dir". Returns null if not found anywhere.
141140
*
142-
* @lucene.internal
143141
* @see SolrDispatchFilter#SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE
144142
*/
145143
public static Path getDefaultConfigDirPath() {
146144
String confDir =
147-
System.getProperty(SolrDispatchFilter.SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE);
145+
EnvUtils.getProperty(SolrDispatchFilter.SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE);
148146
if (confDir != null) {
149-
Path path = Path.of(confDir);
147+
Path path = resolvePathWithSolrInstallDir(confDir);
150148
if (Files.exists(path)) {
151149
return path;
152150
}
153151
}
154152

155-
String installDir = System.getProperty(SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE);
153+
String installDir = EnvUtils.getProperty(SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE);
156154
if (installDir != null) {
155+
Path installPath = resolvePathWithSolrInstallDir(installDir);
157156
Path subPath = Path.of("server", "solr", "configsets", "_default", "conf");
158-
Path path = Path.of(installDir).resolve(subPath);
157+
Path path = installPath.resolve(subPath);
159158
if (Files.exists(path)) {
160159
return path;
161160
}
@@ -164,6 +163,27 @@ public static Path getDefaultConfigDirPath() {
164163
return null;
165164
}
166165

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

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-
223221
/**
224222
* Load the ConfigSet for a core
225223
*

solr/packaging/test/test_start_solr.bats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,14 @@ 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: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@
2323
import java.security.NoSuchAlgorithmException;
2424
import java.util.Arrays;
2525
import java.util.List;
26-
import java.util.Properties;
2726
import java.util.concurrent.TimeUnit;
2827
import org.apache.curator.framework.AuthInfo;
2928
import org.apache.curator.framework.api.ACLProvider;
3029
import org.apache.solr.SolrTestCaseJ4;
31-
import org.apache.solr.cloud.AbstractZkTestCase;
3230
import org.apache.solr.cloud.ZkConfigSetService;
3331
import org.apache.solr.cloud.ZkTestServer;
3432
import org.apache.solr.common.SolrException;
3533
import org.apache.solr.core.ConfigSetService;
36-
import org.apache.solr.core.CoreContainer;
3734
import org.apache.solr.util.LogLevel;
3835
import org.apache.zookeeper.KeeperException;
3936
import org.apache.zookeeper.ZooDefs;
@@ -228,28 +225,6 @@ public void testUploadWithACL() throws IOException, NoSuchAlgorithmException {
228225
}
229226
}
230227

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-
253228
static SolrZkClient buildZkClient(
254229
String zkAddress,
255230
final ACLProvider aclProvider,

solr/solrj/src/resources/DeprecatedSystemPropertyMappings.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ 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)