Apache Solr open-source search software
SOLR-14999: Option to set the advertised port for Solr. (#2089)
Houston Putman4be49cbdf540
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 0f4f21723a4..79610ad3b28 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/solrindex d430271d58e..24b1a4f5312 100755--- a/solr/bin/solr+++ b/solr/bin/solr@@ -1892,6 +1892,10 @@ if [ -z "$SOLR_PORT" ]; thenSOLR_PORT=8983fi+if [ -n "$SOLR_PORT_ADVERTISE" ]; then+ SOLR_OPTS+=("-Dsolr.port.advertise=$SOLR_PORT_ADVERTISE")+fi+if [ -n "$SOLR_JETTY_HOST" ]; thenSOLR_OPTS+=("-Dsolr.jetty.host=$SOLR_JETTY_HOST")fidiff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmdindex d003dab1ba2..f06b50f2716 100755--- a/solr/bin/solr.cmd+++ b/solr/bin/solr.cmd@@ -1088,6 +1088,10 @@ IF "!IS_RESTART!"=="1" set SCRIPT_CMD=startIF "%SOLR_PORT%"=="" set SOLR_PORT=8983IF "%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.javaindex d68d16b0b5e..823aa28b336 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.xmlindex 6cb5c40639c..e34d0a23241 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.adocindex 99bc2e202e2..3484dbb66d1 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.