You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ct...@apache.org on 2021/01/15 21:45:29 UTC

[lucene-solr] 18/38: SOLR-14999: Option to set the advertised port for Solr. (#2089)

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

ctargett pushed a commit to branch jira/solr-13105-toMerge
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit fce98c1049aef67b109b05c031fb144cc8398a59
Author: Houston Putman <ho...@apache.org>
AuthorDate: Fri Jan 8 18:21:41 2021 -0500

    SOLR-14999: Option to set the advertised port for Solr. (#2089)
---
 solr/CHANGES.txt                                           |  2 ++
 solr/bin/solr                                              |  4 ++++
 solr/bin/solr.cmd                                          |  4 ++++
 solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java |  6 +++++-
 solr/server/solr/solr.xml                                  |  2 +-
 solr/solr-ref-guide/src/format-of-solr-xml.adoc            | 10 +++++++---
 6 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 0f4f217..79610ad 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -338,6 +338,8 @@ Other Changes
 
 * SOLR-15057: Avoid unnecessary object retention in FacetRangeProcessor. (Christine Poerschke)
 
+* SOLR-14999: New option for specifying the advertised Solr Port (hostPort). Still defaults to "jetty.port". (Houston Putman)
+
 ==================  8.7.0 ==================
 
 Consult the lucene/CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/bin/solr b/solr/bin/solr
index d430271..24b1a4f 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -1892,6 +1892,10 @@ if [ -z "$SOLR_PORT" ]; then
   SOLR_PORT=8983
 fi
 
+if [ -n "$SOLR_PORT_ADVERTISE" ]; then
+  SOLR_OPTS+=("-Dsolr.port.advertise=$SOLR_PORT_ADVERTISE")
+fi
+
 if [ -n "$SOLR_JETTY_HOST" ]; then
   SOLR_OPTS+=("-Dsolr.jetty.host=$SOLR_JETTY_HOST")
 fi
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index d003dab..f06b50f 100755
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -1088,6 +1088,10 @@ IF "!IS_RESTART!"=="1" set SCRIPT_CMD=start
 IF "%SOLR_PORT%"=="" set SOLR_PORT=8983
 IF "%STOP_PORT%"=="" set /A STOP_PORT=%SOLR_PORT% - 1000
 
+IF DEFINED SOLR_PORT_ADVERTISE (
+  set "SOLR_OPTS=%SOLR_OPTS% -Dsolr.port.advertise=%SOLR_PORT_ADVERTISE%"
+)
+
 IF DEFINED SOLR_JETTY_HOST (
   set "SOLR_OPTS=%SOLR_OPTS% -Dsolr.jetty.host=%SOLR_JETTY_HOST%"
 )
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 d68d16b..823aa28 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
@@ -434,8 +434,12 @@ public class SolrXmlConfig {
 
   private static CloudConfig fillSolrCloudSection(NamedList<Object> nl, XmlConfigFile config, String defaultZkHost) {
 
+    int hostPort = parseInt("hostPort", removeValue(nl, "hostPort"));
+    if (hostPort <= 0) {
+      // Default to the port that jetty is listening on, or 8983 if that is not provided.
+      hostPort = parseInt("jetty.port", System.getProperty("jetty.port", "8983"));
+    }
     String hostName = required("solrcloud", "host", removeValue(nl, "host"));
-    int hostPort = parseInt("hostPort", required("solrcloud", "hostPort", removeValue(nl, "hostPort")));
     String hostContext = required("solrcloud", "hostContext", removeValue(nl, "hostContext"));
 
     CloudConfig.CloudConfigBuilder builder = new CloudConfig.CloudConfigBuilder(hostName, hostPort, hostContext);
diff --git a/solr/server/solr/solr.xml b/solr/server/solr/solr.xml
index 6cb5c40..e34d0a23 100644
--- a/solr/server/solr/solr.xml
+++ b/solr/server/solr/solr.xml
@@ -35,7 +35,7 @@
   <solrcloud>
 
     <str name="host">${host:}</str>
-    <int name="hostPort">${jetty.port:8983}</int>
+    <int name="hostPort">${solr.port.advertise:0}</int>
     <str name="hostContext">${hostContext:solr}</str>
 
     <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
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 99bc2e2..3484dbb 100644
--- a/solr/solr-ref-guide/src/format-of-solr-xml.adoc
+++ b/solr/solr-ref-guide/src/format-of-solr-xml.adoc
@@ -34,7 +34,7 @@ You can find `solr.xml` in your `$SOLR_HOME` directory (usually `server/solr` or
 
   <solrcloud>
     <str name="host">${host:}</str>
-    <int name="hostPort">${jetty.port:8983}</int>
+    <int name="hostPort">${solr.port.advertise:0}</int>
     <str name="hostContext">${hostContext:solr}</str>
     <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
     <int name="zkClientTimeout">${zkClientTimeout:30000}</int>
@@ -134,9 +134,13 @@ The hostname Solr uses to access cores.
 The url context path.
 
 `hostPort`::
-The port Solr uses to access cores.
+The port Solr uses to access cores, and advertise Solr node locations through liveNodes.
+This option is only necessary if a Solr instance is listening on a different port than it wants other nodes to contact it at.
+For example, if the Solr node is running behind a proxy or in a cloud environment that allows for port mapping, such as Kubernetes.
+`hostPort` is the port that the Solr instance wants other nodes to contact it at.
 +
-In the default `solr.xml` file, this is set to `${jetty.port:8983}`, which will use the Solr port defined in Jetty, and otherwise fall back to 8983.
+In the default `solr.xml` file, this is set to `${solr.port.advertise:0}`.
+If no port is passed via the `solr.xml` (i.e. `0`), then Solr will default to the port that jetty is listening on, defined by `${jetty.port}`.
 
 `leaderVoteWait`::
 When SolrCloud is starting up, how long each Solr node will wait for all known replicas for that shard to be found before assuming that any nodes that haven't reported are down.