Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-7642: add opt-in support to create ZK chroot on startup (#298)

Christine Poerschke9d8f3c27e1c9
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f048534c047..74980ec2889 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -41,6 +41,9 @@ New Features
* SOLR-15423: JWTAuthPlugin now supports separate config for what SSL certs to trust when talking to IdPs (janhoy)
+* SOLR-7642: opt-in support to create ZK chroot on startup (Timothy Potter, Shawn Heisey, Mark Miller, Tomas Eduardo Fernandez Lobbe,
+ Jan Høydahl, Steve Molloy, Isabelle Giguere, David Eric Pugh, Gus Heck, Christine Poerschke, Houston Putman)
+
Improvements
----------------------
* LUCENE-8984: MoreLikeThis MLT is biased for uncommon fields (Andy Hind via Anshum Gupta)
diff --git a/solr/bin/solr b/solr/bin/solr
index f312617bc04..2cd12a55041 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -370,6 +370,7 @@ function print_usage() {
echo " -z <zkHost> Zookeeper connection string; only used when running in SolrCloud mode using -c"
echo " If neither ZK_HOST is defined in solr.in.sh nor the -z parameter is specified,"
echo " an embedded ZooKeeper instance will be launched."
+ echo " Set the ZK_CREATE_CHROOT environment variable to true if your ZK host has a chroot path, and you want to create it automatically."
echo ""
echo " -m <memory> Sets the min (-Xms) and max (-Xmx) heap size for the JVM, such as: -m 4g"
echo " results in: -Xms4g -Xmx4g; by default, this script sets the heap size to 512m"
@@ -2063,6 +2064,10 @@ if [ "$SOLR_MODE" == 'solrcloud' ]; then
CLOUD_MODE_OPTS+=('-DzkRun')
fi
+ if [ -n "$ZK_CREATE_CHROOT" ]; then
+ CLOUD_MODE_OPTS+=("-DcreateZkChroot=$ZK_CREATE_CHROOT")
+ fi
+
# and if collection1 needs to be bootstrapped
if [ -e "$SOLR_HOME/collection1/core.properties" ]; then
CLOUD_MODE_OPTS+=('-Dbootstrap_confdir=./solr/collection1/conf' '-Dcollection.configName=myconf' '-DnumShards=1')
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index f19eea919c3..e4f623da4e7 100755
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -347,6 +347,7 @@ goto done
@echo -z zkHost Zookeeper connection string; only used when running in SolrCloud mode using -c
@echo If neither ZK_HOST is defined in solr.in.cmd nor the -z parameter is specified,
@echo an embedded ZooKeeper instance will be launched.
+@echo Set the ZK_CREATE_CHROOT environment variable to true if your ZK host has a chroot path, and you want to create it automatically."
@echo.
@echo -m memory Sets the min (-Xms) and max (-Xmx) heap size for the JVM, such as: -m 4g
@echo results in: -Xms4g -Xmx4g; by default, this script sets the heap size to 512m
@@ -1164,6 +1165,11 @@ IF "%SOLR_MODE%"=="solrcloud" (
IF "%verbose%"=="1" echo Configuring SolrCloud to launch an embedded Zookeeper using -DzkRun
set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -DzkRun"
)
+
+ IF NOT "%ZK_CREATE_CHROOT%"=="" (
+ set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -DcreateZkChroot=%ZK_CREATE_CHROOT%"
+ )
+
IF EXIST "%SOLR_HOME%\collection1\core.properties" set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -Dbootstrap_confdir=./solr/collection1/conf -Dcollection.configName=myconf -DnumShards=1"
) ELSE (
set CLOUD_MODE_OPTS=
diff --git a/solr/bin/solr.in.cmd b/solr/bin/solr.in.cmd
index 914880bcaa3..28d1bfe141b 100755
--- a/solr/bin/solr.in.cmd
+++ b/solr/bin/solr.in.cmd
@@ -55,6 +55,9 @@ REM e.g. host1:2181,host2:2181/chroot
REM Leave empty if not using SolrCloud
REM set ZK_HOST=
+REM Set to true if your ZK host has a chroot path, and you want to create it automatically.
+REM set ZK_CREATE_CHROOT=true
+
REM Set the ZooKeeper client timeout (for SolrCloud mode)
REM set ZK_CLIENT_TIMEOUT=30000
diff --git a/solr/bin/solr.in.sh b/solr/bin/solr.in.sh
index 29760424aa0..2d22ce5a65f 100644
--- a/solr/bin/solr.in.sh
+++ b/solr/bin/solr.in.sh
@@ -70,6 +70,9 @@
# Leave empty if not using SolrCloud
#ZK_HOST=""
+# Set to true if your ZK host has a chroot path, and you want to create it automatically.
+#ZK_CREATE_CHROOT=true
+
# Set the ZooKeeper client timeout (for SolrCloud mode)
#ZK_CLIENT_TIMEOUT="30000"
diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
index caff9cc78eb..75a4e8382ac 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -1063,6 +1063,7 @@ public class ZkController implements Closeable {
zkHost.indexOf("/")), 60000, 30000, null, null, null);
boolean exists = tmpClient.exists(chrootPath, true);
if (!exists && create) {
+ log.info("creating chroot {}", chrootPath);
tmpClient.makePath(chrootPath, false, true);
exists = true;
}
diff --git a/solr/core/src/java/org/apache/solr/core/ZkContainer.java b/solr/core/src/java/org/apache/solr/core/ZkContainer.java
index f3f80828b24..cb268c30a22 100644
--- a/solr/core/src/java/org/apache/solr/core/ZkContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/ZkContainer.java
@@ -121,12 +121,13 @@ public class ZkContainer {
log.info("Zookeeper client={}", zookeeperHost);
}
String confDir = System.getProperty("bootstrap_confdir");
- boolean boostrapConf = Boolean.getBoolean("bootstrap_conf");
+ boolean boostrapConf = Boolean.getBoolean("bootstrap_conf");
+ boolean createRoot = Boolean.getBoolean("createZkChroot");
// We may have already loaded NodeConfig from zookeeper with same connect string, so no need to recheck chroot
boolean alreadyUsedChroot = (cc.getConfig().isFromZookeeper()
&& zookeeperHost.equals(cc.getConfig().getDefaultZkHost()));
- if(!alreadyUsedChroot && !ZkController.checkChrootPath(zookeeperHost, (confDir!=null) || boostrapConf || zkRunOnly)) {
+ if(!alreadyUsedChroot && !ZkController.checkChrootPath(zookeeperHost, (confDir!=null) || boostrapConf || zkRunOnly || createRoot)) {
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"A chroot was specified in ZkHost but the znode doesn't exist. " + zookeeperHost);
}
diff --git a/solr/solr-ref-guide/src/zookeeper-ensemble.adoc b/solr/solr-ref-guide/src/zookeeper-ensemble.adoc
index 63b668d3c21..26d3e483cd6 100644
--- a/solr/solr-ref-guide/src/zookeeper-ensemble.adoc
+++ b/solr/solr-ref-guide/src/zookeeper-ensemble.adoc
@@ -387,6 +387,8 @@ See the section <<solr-control-script-reference.adoc#create-a-znode-supports-chr
Once the znode is created, it behaves in a similar way to a directory on a filesystem: the data stored by Solr in ZooKeeper is nested beneath the main data directory and won't be mixed with data from another system or process that uses the same ZooKeeper ensemble.
+Alternatively, Solr can create the znode automatically as part of the first Solr instance's startup, read below for an example.
+
=== Using the -z Parameter with bin/solr
Pointing Solr at the ZooKeeper ensemble you've created is a simple matter of using the `-z` parameter when using the `bin/solr` script.
@@ -398,6 +400,13 @@ For example, to point the Solr instance to the ZooKeeper you've started on port
bin/solr start -e cloud -z zk1:2181,zk2:2181,zk3:2181/solr
----
+If the znode does not exist, you can set the ZK_CREATE_CHROOT environment variable to true to create it automatically on start-up:
+
+[source,bash]
+----
+ZK_CREATE_CHROOT=true bin/solr start -e cloud -z zk1:2181,zk2:2181,zk3:2181/solr
+----
+
=== Updating Solr Include Files
If you update Solr include files (`solr.in.sh` or `solr.in.cmd`), which overrides defaults used with `bin/solr`, you will not have to use the `-z` parameter with `bin/solr` commands.