SOLR-8689: Fix bin/solr.cmd so it can run properly on Java 9
(cherry picked from commit 86f7d67)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f676279..6a4c28c 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -68,6 +68,8 @@
* SOLR-10983: Fix DOWNNODE -> queue-work explosion (Scott Blum, Joshua Humphries)
+* SOLR-8689: Fix bin/solr.cmd so it can run properly on Java 9 (Uwe Schindler, hossman)
+
================== 6.6.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index 727350b..865649c 100644
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -1081,14 +1081,28 @@
-XX:-OmitStackTraceInFastThrow
)
-IF "%GC_LOG_OPTS%"=="" (
- set GC_LOG_OPTS=-verbose:gc ^
- -XX:+PrintHeapAtGC ^
- -XX:+PrintGCDetails ^
- -XX:+PrintGCDateStamps ^
- -XX:+PrintGCTimeStamps ^
- -XX:+PrintTenuringDistribution ^
- -XX:+PrintGCApplicationStoppedTime
+if !JAVA_MAJOR_VERSION! GEQ 9 (
+ IF NOT "%GC_LOG_OPTS%"=="" (
+ echo ERROR: On Java 9 you cannot set GC_LOG_OPTS, only default GC logging is available. Exiting
+ GOTO :eof
+ )
+ set GC_LOG_OPTS="-Xlog:gc*:file=\"!SOLR_LOGS_DIR!\solr_gc.log\":time,uptime:filecount=9,filesize=20000"
+) else (
+ IF "%GC_LOG_OPTS%"=="" (
+ rem Set defaults for Java 8
+ set GC_LOG_OPTS=-verbose:gc ^
+ -XX:+PrintHeapAtGC ^
+ -XX:+PrintGCDetails ^
+ -XX:+PrintGCDateStamps ^
+ -XX:+PrintGCTimeStamps ^
+ -XX:+PrintTenuringDistribution ^
+ -XX:+PrintGCApplicationStoppedTime
+ )
+ if "%JAVA_VENDOR%" == "IBM J9" (
+ set GC_LOG_OPTS=!GC_LOG_OPTS! "-Xverbosegclog:!SOLR_LOGS_DIR!\solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M
+ ) else (
+ set GC_LOG_OPTS=!GC_LOG_OPTS! "-Xloggc:!SOLR_LOGS_DIR!\solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M
+ )
)
IF "%verbose%"=="1" (
@@ -1166,24 +1180,18 @@
mkdir "%SOLR_SERVER_DIR%\tmp"
)
-IF "%JAVA_VENDOR%" == "IBM J9" (
- set GCLOG_OPT="-Xverbosegclog:!SOLR_LOGS_DIR!\solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M
-) else (
- set GCLOG_OPT="-Xloggc:!SOLR_LOGS_DIR!\solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M
-)
-
IF "%FG%"=="1" (
REM run solr in the foreground
title "Solr-%SOLR_PORT%"
echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
- "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT% ^
+ "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% ^
-Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
-Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" ^
-Djetty.host=%SOLR_JETTY_HOST% -Djetty.port=%SOLR_PORT% -Djetty.home="%SOLR_SERVER_DIR%" ^
-Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar "%SOLR_JETTY_CONFIG%"
) ELSE (
START /B "Solr-%SOLR_PORT%" /D "%SOLR_SERVER_DIR%" ^
- "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT% ^
+ "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% ^
-Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
-Dsolr.log.muteconsole ^
-Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" ^
@@ -1225,7 +1233,7 @@
@echo.
set has_info=1
echo Found Solr process %%k running on port !SOME_SOLR_PORT!
- "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
+ "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
-Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.util.SolrCLI status -solr !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!SOME_SOLR_PORT!/solr
@@ -1793,8 +1801,12 @@
set JAVA_VERSION_INFO=!JAVA_VERSION_INFO:"=!
REM Extract the major Java version, e.g. 7, 8, 9, 10 ...
- for /f "tokens=2 delims=." %%a in ("!JAVA_VERSION_INFO!") do (
- set JAVA_MAJOR_VERSION=%%a
+ for /f "tokens=1,2 delims=." %%a in ("!JAVA_VERSION_INFO!") do (
+ if "%%a" GEQ "9" (
+ set JAVA_MAJOR_VERSION=%%a
+ ) else (
+ set JAVA_MAJOR_VERSION=%%b
+ )
)
REM Don't look for "_{build}" if we're on IBM J9.
diff --git a/solr/bin/solr.in.cmd b/solr/bin/solr.in.cmd
index 59dee18..4e22742 100644
--- a/solr/bin/solr.in.cmd
+++ b/solr/bin/solr.in.cmd
@@ -27,7 +27,9 @@
REM Increase Java Min/Max Heap as needed to support your indexing / query needs
REM set SOLR_JAVA_MEM=-Xms512m -Xmx512m
-REM Enable verbose GC logging
+REM Configure verbose GC logging:
+REM For Java 8: if this is set, additional params will be added to specify the log file & rotation
+REM For Java 9 or higher: GC_LOG_OPTS is currently not supported. If you set it, the startup script will exit with failure.
REM set GC_LOG_OPTS=-verbose:gc -XX:+PrintHeapAtGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime
REM Various GC settings have shown to work well for a number of common Solr workloads.
diff --git a/solr/bin/solr.in.sh b/solr/bin/solr.in.sh
index 620cf3f..1d090f5 100644
--- a/solr/bin/solr.in.sh
+++ b/solr/bin/solr.in.sh
@@ -36,12 +36,12 @@
# Enable verbose GC logging...
# * If this is unset, various default options will be selected depending on which JVM version is in use
-# * For java8 or lower: if this is set, additional params will be added to specify the log file & rotation
-# * For java9 or higher: each included opt param that starts with '-Xlog:gc', but does not include an output
-# specifier, will have a 'file' output specifier (as well as formatting & rollover options) appended,
-# using the effective value of the SOLR_LOGS_DIR.
+# * For Java 8: if this is set, additional params will be added to specify the log file & rotation
+# * For Java 9 or higher: each included opt param that starts with '-Xlog:gc', but does not include an
+# output specifier, will have a 'file' output specifier (as well as formatting & rollover options)
+# appended, using the effective value of the SOLR_LOGS_DIR.
#
-#GC_LOG_OPTS='-Xlog:gc*' # (java9)
+#GC_LOG_OPTS='-Xlog:gc*' # (Java 9+)
#GC_LOG_OPTS="-verbose:gc -XX:+PrintHeapAtGC -XX:+PrintGCDetails \
# -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime"