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 2017/03/14 17:35:01 UTC

[2/2] lucene-solr:branch_6x: SOLR-10184: Fix bin/solr so it can run properly on java9

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

(cherry picked from commit 09bd8612ce82c2852542127eb24b887c7b332a0d)


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/90fa23ca
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/90fa23ca
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/90fa23ca

Branch: refs/heads/branch_6x
Commit: 90fa23cad82a29a5553a350f70be358830acb74c
Parents: 5d7b83a
Author: Chris Hostetter <ho...@apache.org>
Authored: Tue Mar 14 10:23:49 2017 -0700
Committer: Chris Hostetter <ho...@apache.org>
Committed: Tue Mar 14 10:31:48 2017 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt    |  2 ++
 solr/bin/solr       | 57 ++++++++++++++++++++++++++++++------------------
 solr/bin/solr.in.sh | 11 ++++++++--
 3 files changed, 47 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/90fa23ca/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index ff7fb2f..cb4169d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -178,6 +178,8 @@ Bug Fixes
   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)
 
+* SOLR-10184: Fix bin/solr so it can run properly on java9 (hossman, Uwe Schindler)
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/90fa23ca/solr/bin/solr
----------------------------------------------------------------------
diff --git a/solr/bin/solr b/solr/bin/solr
index ffbd5db..8a36987 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -50,7 +50,7 @@ verbose=false
 THIS_OS=`uname -s`
 
 # 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
 
@@ -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 "Command that we tried: '${JAVA} -version', with response:"
   echo >&2 "${JAVA_VER}"
-  echo
+  echo >&2
   echo >&2 "Debug information:"
   echo >&2 "JAVA_HOME: ${JAVA_HOME:-N/A}"
   echo >&2 "Active Path:"
   echo >&2 "${PATH}"
   exit 1
 else
-  JAVA_VER=$(echo $JAVA_VER | awk -F '"' '/version/ {print $2}')
-  if [[ "$JAVA_VER" < "1.$JAVA_VER_REQ" ]] ; then
+  JAVA_VER_NUM=$(echo $JAVA_VER | head -1 | awk -F '"' '/version/ {print $2}')
+  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 "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
+    echo >&2
     echo >&2 "Debug information:"
     echo >&2 "JAVA_HOME: ${JAVA_HOME:-N/A}"
     echo >&2 "Active Path:"
     echo >&2 "${PATH}"
     exit 1
   fi
+  JAVA_VENDOR="Oracle"
+  if [ "`echo $JAVA_VER | grep -i "IBM J9"`" != "" ]; then
+      JAVA_VENDOR="IBM J9"
+  fi
 fi
 
+
 # Select HTTP OR HTTPS related configurations
 SOLR_URL_SCHEME=http
 SOLR_JETTY_CONFIG=()
@@ -1515,29 +1522,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"
 fi
 
-java_ver_out=`echo "$("$JAVA" -version 2>&1)"`
-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)
+# Establish default GC logging opts if no env var set (otherwise init to sensible default)
 if [ -z ${GC_LOG_OPTS+x} ]; then
-  GC_LOG_OPTS=('-verbose:gc' '-XX:+PrintHeapAtGC' '-XX:+PrintGCDetails' \
-    '-XX:+PrintGCDateStamps' '-XX:+PrintGCTimeStamps' '-XX:+PrintTenuringDistribution' \
-    '-XX:+PrintGCApplicationStoppedTime')
+  if [[ "$JAVA_VER_NUM" < "9" ]] ; then
+    GC_LOG_OPTS=('-verbose:gc' '-XX:+PrintHeapAtGC' '-XX:+PrintGCDetails' \
+                 '-XX:+PrintGCDateStamps' '-XX:+PrintGCTimeStamps' '-XX:+PrintTenuringDistribution' \
+                 '-XX:+PrintGCApplicationStoppedTime')
+  else
+    GC_LOG_OPTS=('-Xlog:gc*')
+  fi
 else
   GC_LOG_OPTS=($GC_LOG_OPTS)
 fi
 
 # if verbose gc logging enabled, setup the location of the log file and rotation
 if [ "$GC_LOG_OPTS" != "" ]; then
-  gc_log_flag="-Xloggc"
-  if [ "$JAVA_VENDOR" == "IBM J9" ]; then
-    gc_log_flag="-Xverbosegclog"
+  if [[ "$JAVA_VER_NUM" < "9" ]] ; then
+    gc_log_flag="-Xloggc"
+    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
-  GC_LOG_OPTS+=("$gc_log_flag:$SOLR_LOGS_DIR/solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M)
 fi
 
 # If ZK_HOST is defined, the assume SolrCloud mode

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/90fa23ca/solr/bin/solr.in.sh
----------------------------------------------------------------------
diff --git a/solr/bin/solr.in.sh b/solr/bin/solr.in.sh
index 7b4d21c..620cf3f 100644
--- a/solr/bin/solr.in.sh
+++ b/solr/bin/solr.in.sh
@@ -34,9 +34,16 @@
 # Comment out SOLR_HEAP if you are using this though, that takes precedence
 #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 \
-#-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
 #GC_TUNE="-XX:NewRatio=3 -XX:SurvivorRatio=4    etc.