SOLR-10184: Fix bin/solr so it can run properly on java9

This commit is contained in:
Chris Hostetter 2017-03-14 10:23:49 -07:00
parent 9417367b1a
commit 09bd8612ce
3 changed files with 47 additions and 23 deletions

View File

@ -249,6 +249,8 @@ Bug Fixes
legacyCloud=false and will also fail on a state check when taking over a core registration with a new legacyCloud=false and will also fail on a state check when taking over a core registration with a new
core. (Mark Miller, Hrishikesh Gadre, Patrick Dvorack) core. (Mark Miller, Hrishikesh Gadre, Patrick Dvorack)
* SOLR-10184: Fix bin/solr so it can run properly on java9 (hossman, Uwe Schindler)
Optimizations Optimizations
---------------------- ----------------------

View File

@ -50,7 +50,7 @@ verbose=false
THIS_OS=`uname -s` THIS_OS=`uname -s`
# What version of Java is required to run this version of Solr. # What version of Java is required to run this version of Solr.
JAVA_VER_REQ="8" # For printing in echo JAVA_VER_REQ="1.8"
stop_all=false stop_all=false
@ -130,27 +130,34 @@ if [[ $? -ne 0 ]] ; then
echo >&2 "Please install latest version of Java $JAVA_VER_REQ or set JAVA_HOME properly." echo >&2 "Please install latest version of Java $JAVA_VER_REQ or set JAVA_HOME properly."
echo >&2 "Command that we tried: '${JAVA} -version', with response:" echo >&2 "Command that we tried: '${JAVA} -version', with response:"
echo >&2 "${JAVA_VER}" echo >&2 "${JAVA_VER}"
echo echo >&2
echo >&2 "Debug information:" echo >&2 "Debug information:"
echo >&2 "JAVA_HOME: ${JAVA_HOME:-N/A}" echo >&2 "JAVA_HOME: ${JAVA_HOME:-N/A}"
echo >&2 "Active Path:" echo >&2 "Active Path:"
echo >&2 "${PATH}" echo >&2 "${PATH}"
exit 1 exit 1
else else
JAVA_VER=$(echo $JAVA_VER | awk -F '"' '/version/ {print $2}') JAVA_VER_NUM=$(echo $JAVA_VER | head -1 | awk -F '"' '/version/ {print $2}')
if [[ "$JAVA_VER" < "1.$JAVA_VER_REQ" ]] ; then if [[ "$JAVA_VER_NUM" < "$JAVA_VER_REQ" ]] ; then
echo >&2 "Your current version of Java is too old to run this version of Solr" echo >&2 "Your current version of Java is too old to run this version of Solr"
echo >&2 "We found version $JAVA_VER, using command '${JAVA}'" echo >&2 "We found version $JAVA_VER_NUM, using command '${JAVA} -version', with response:"
echo >&2 "${JAVA_VER}"
echo >&2
echo >&2 "Please install latest version of Java $JAVA_VER_REQ or set JAVA_HOME properly." echo >&2 "Please install latest version of Java $JAVA_VER_REQ or set JAVA_HOME properly."
echo echo >&2
echo >&2 "Debug information:" echo >&2 "Debug information:"
echo >&2 "JAVA_HOME: ${JAVA_HOME:-N/A}" echo >&2 "JAVA_HOME: ${JAVA_HOME:-N/A}"
echo >&2 "Active Path:" echo >&2 "Active Path:"
echo >&2 "${PATH}" echo >&2 "${PATH}"
exit 1 exit 1
fi fi
JAVA_VENDOR="Oracle"
if [ "`echo $JAVA_VER | grep -i "IBM J9"`" != "" ]; then
JAVA_VENDOR="IBM J9"
fi
fi fi
# Select HTTP OR HTTPS related configurations # Select HTTP OR HTTPS related configurations
SOLR_URL_SCHEME=http SOLR_URL_SCHEME=http
SOLR_JETTY_CONFIG=() SOLR_JETTY_CONFIG=()
@ -1519,29 +1526,37 @@ if [ "${SOLR_LOG_PRESTART_ROTATION:=true}" == "true" ]; then
run_tool utils -s "$DEFAULT_SERVER_DIR" -l "$SOLR_LOGS_DIR" $q -rotate_solr_logs 9 || echo "Failed rotating old solr logs" run_tool utils -s "$DEFAULT_SERVER_DIR" -l "$SOLR_LOGS_DIR" $q -rotate_solr_logs 9 || echo "Failed rotating old solr logs"
fi fi
java_ver_out=`echo "$("$JAVA" -version 2>&1)"` # Establish default GC logging opts if no env var set (otherwise init to sensible default)
JAVA_VERSION=`echo $java_ver_out | grep "java version" | awk '{ print substr($3, 2, length($3)-2); }'`
JAVA_VENDOR="Oracle"
if [ "`echo $java_ver_out | grep -i "IBM J9"`" != "" ]; then
JAVA_VENDOR="IBM J9"
fi
# Establish default opts no env var set (otherwise init to empty)
if [ -z ${GC_LOG_OPTS+x} ]; then if [ -z ${GC_LOG_OPTS+x} ]; then
GC_LOG_OPTS=('-verbose:gc' '-XX:+PrintHeapAtGC' '-XX:+PrintGCDetails' \ if [[ "$JAVA_VER_NUM" < "9" ]] ; then
'-XX:+PrintGCDateStamps' '-XX:+PrintGCTimeStamps' '-XX:+PrintTenuringDistribution' \ GC_LOG_OPTS=('-verbose:gc' '-XX:+PrintHeapAtGC' '-XX:+PrintGCDetails' \
'-XX:+PrintGCApplicationStoppedTime') '-XX:+PrintGCDateStamps' '-XX:+PrintGCTimeStamps' '-XX:+PrintTenuringDistribution' \
'-XX:+PrintGCApplicationStoppedTime')
else
GC_LOG_OPTS=('-Xlog:gc*')
fi
else else
GC_LOG_OPTS=($GC_LOG_OPTS) GC_LOG_OPTS=($GC_LOG_OPTS)
fi fi
# if verbose gc logging enabled, setup the location of the log file and rotation # if verbose gc logging enabled, setup the location of the log file and rotation
if [ "$GC_LOG_OPTS" != "" ]; then if [ "$GC_LOG_OPTS" != "" ]; then
gc_log_flag="-Xloggc" if [[ "$JAVA_VER_NUM" < "9" ]] ; then
if [ "$JAVA_VENDOR" == "IBM J9" ]; then gc_log_flag="-Xloggc"
gc_log_flag="-Xverbosegclog" if [ "$JAVA_VENDOR" == "IBM J9" ]; then
gc_log_flag="-Xverbosegclog"
fi
GC_LOG_OPTS+=("$gc_log_flag:$SOLR_LOGS_DIR/solr_gc.log" '-XX:+UseGCLogFileRotation' '-XX:NumberOfGCLogFiles=9' '-XX:GCLogFileSize=20M')
else
# http://openjdk.java.net/jeps/158
for i in "${!GC_LOG_OPTS[@]}";
do
# for simplicity, we only look at the prefix '-Xlog:gc'
# (if 'all' or multiple tags are used starting with anything other then 'gc' the user is on their own)
# if a single additional ':' exists in param, then there is already an explicit output specifier
GC_LOG_OPTS[$i]=$(echo ${GC_LOG_OPTS[$i]} | sed "s|^\(-Xlog:gc[^:]*$\)|\1:file=$SOLR_LOGS_DIR/solr_gc.log:time,uptime:filecount=9,filesize=20000|")
done
fi fi
GC_LOG_OPTS+=("$gc_log_flag:$SOLR_LOGS_DIR/solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M)
fi fi
# If ZK_HOST is defined, the assume SolrCloud mode # If ZK_HOST is defined, the assume SolrCloud mode

View File

@ -34,9 +34,16 @@
# Comment out SOLR_HEAP if you are using this though, that takes precedence # Comment out SOLR_HEAP if you are using this though, that takes precedence
#SOLR_JAVA_MEM="-Xms512m -Xmx512m" #SOLR_JAVA_MEM="-Xms512m -Xmx512m"
# Enable verbose GC logging # 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.
#
#GC_LOG_OPTS='-Xlog:gc*' # (java9)
#GC_LOG_OPTS="-verbose:gc -XX:+PrintHeapAtGC -XX:+PrintGCDetails \ #GC_LOG_OPTS="-verbose:gc -XX:+PrintHeapAtGC -XX:+PrintGCDetails \
#-XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime" # -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime"
# These GC settings have shown to work well for a number of common Solr workloads # These GC settings have shown to work well for a number of common Solr workloads
#GC_TUNE="-XX:NewRatio=3 -XX:SurvivorRatio=4 etc. #GC_TUNE="-XX:NewRatio=3 -XX:SurvivorRatio=4 etc.