You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2021/10/15 16:34:48 UTC

[lucene-solr] branch branch_8x updated: SOLR-7642: add opt-in support to create ZK chroot on startup (#298)

This is an automated email from the ASF dual-hosted git repository.

houston pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new c684d75  SOLR-7642: add opt-in support to create ZK chroot on startup (#298)
c684d75 is described below

commit c684d75562ab081fabc06fd748e63e5ccf681270
Author: Christine Poerschke <cp...@apache.org>
AuthorDate: Thu Sep 30 14:07:58 2021 +0100

    SOLR-7642: add opt-in support to create ZK chroot on startup (#298)
    
    Co-authored-by: igiguere <ig...@opentext.com>
---
 solr/CHANGES.txt                                                 | 5 ++++-
 solr/bin/solr                                                    | 5 +++++
 solr/bin/solr.cmd                                                | 6 ++++++
 solr/bin/solr.in.cmd                                             | 3 +++
 solr/bin/solr.in.sh                                              | 3 +++
 solr/core/src/java/org/apache/solr/cloud/ZkController.java       | 1 +
 solr/core/src/java/org/apache/solr/core/ZkContainer.java         | 5 +++--
 .../src/setting-up-an-external-zookeeper-ensemble.adoc           | 9 +++++++++
 8 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4cbf286..4c077e5 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -10,7 +10,10 @@ Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this r
 
 New Features
 ---------------------
-(No changes)
+
+* 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
 ---------------------
diff --git a/solr/bin/solr b/solr/bin/solr
index 23f9094..1d11fad 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -377,6 +377,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"
@@ -2069,6 +2070,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 aa28910..4274100 100755
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -353,6 +353,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
@@ -1163,6 +1164,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 e971587..a5eee5c 100755
--- a/solr/bin/solr.in.cmd
+++ b/solr/bin/solr.in.cmd
@@ -54,6 +54,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 489d0e3..30b658e 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 1698565..a6a346d 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -1133,6 +1133,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 8230948..823ea60 100644
--- a/solr/core/src/java/org/apache/solr/core/ZkContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/ZkContainer.java
@@ -123,9 +123,10 @@ 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");
 
-        if(!ZkController.checkChrootPath(zookeeperHost, (confDir!=null) || boostrapConf || zkRunOnly)) {
+        if(!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/setting-up-an-external-zookeeper-ensemble.adoc b/solr/solr-ref-guide/src/setting-up-an-external-zookeeper-ensemble.adoc
index 4a32209..c371234 100644
--- a/solr/solr-ref-guide/src/setting-up-an-external-zookeeper-ensemble.adoc
+++ b/solr/solr-ref-guide/src/setting-up-an-external-zookeeper-ensemble.adoc
@@ -286,6 +286,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.
@@ -297,6 +299,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.