From 1b69a125308ca59118222e08288b8ccb53f94441 Mon Sep 17 00:00:00 2001 From: Istvan Toth Date: Fri, 8 Dec 2023 14:34:51 +0100 Subject: [PATCH] HBASE-28252 Update JDK11 options and add JDK17 options to hbase script Change-Id: I5a845ffc6df133a1c1a6c12a7fc0871a448c42e8 --- bin/hbase | 63 +++++++++++++++++++++++++++++++++++++++++++-- bin/hbase-config.sh | 8 ++++-- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/bin/hbase b/bin/hbase index 60cfb8afef9a..285048bb7190 100755 --- a/bin/hbase +++ b/bin/hbase @@ -496,7 +496,11 @@ add_jdk11_deps_to_classpath() { } add_jdk11_jvm_flags() { - HBASE_OPTS="$HBASE_OPTS -Dorg.apache.hbase.thirdparty.io.netty.tryReflectionSetAccessible=true --add-modules jdk.unsupported --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-exports java.base/jdk.internal.misc=ALL-UNNAMED --add-exports java.security.jgss/sun.security.krb5=ALL-UNNAMED" + HBASE_OPTS="$HBASE_OPTS -Dorg.apache.hbase.thirdparty.io.netty.tryReflectionSetAccessible=true --add-modules jdk.unsupported --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-exports java.base/jdk.internal.misc=ALL-UNNAMED --add-exports java.security.jgss/sun.security.krb5=ALL-UNNAMED --add-exports java.base/sun.net.dns=ALL-UNNAMED --add-exports java.base/sun.net.util=ALL-UNNAMED" +} + +add_jdk17_jvm_flags() { + HBASE_OPTS="$HBASE_OPTS --add-opens java.base/jdk.internal.util.random=ALL-UNNAMED" } add_opentelemetry_agent() { @@ -786,11 +790,19 @@ fi # Add lib/jdk11 jars to the classpath if [ "${DEBUG}" = "true" ]; then - echo "Deciding on addition of lib/jdk11 jars to the classpath" + echo "Deciding on addition of JVM module flags and lib/jdk11 jars to the classpath" fi addJDK11Jars=false +if [ "${HBASE_JDK17}" = "include" ]; then + # JDK17 needs everything JDK11 needs + HBASE_JDK11="${HBASE_JDK17}" + if [ "${DEBUG}" = "true" ]; then + echo "HBASE_JDK17 is set to include. Overriding HBASE_JDK11 to the same value." + fi +fi + if [ "${HBASE_JDK11}" != "" ]; then # Use the passed Environment Variable HBASE_JDK11 if [ "${HBASE_JDK11}" = "include" ]; then @@ -838,6 +850,52 @@ elif [ "${DEBUG}" = "true" ]; then echo "Skipped adding JDK11 JVM flags." fi +addJDK17Options=false + +if [ "${HBASE_JDK17}" != "" ]; then + # Use the passed Environment Variable HBASE_JDK17 + if [ "${HBASE_JDK17}" = "include" ]; then + addJDK17Options=true + if [ "${DEBUG}" = "true" ]; then + echo "HBASE_JDK17 set as 'include' hence adding JDK17 options to command line." + fi + elif [ "${HBASE_JDK17}" = "exclude" ]; then + if [ "${DEBUG}" = "true" ]; then + echo "HBASE_JDK17 set as 'exclude' hence skipping adding JDK17 to command line." + fi + else + echo "[HBASE_JDK17] contains unsupported value(s) - ${HBASE_JDK17}. Ignoring passed value." + echo "[HBASE_JDK17] supported values: [include, exclude]." + fi +else + # Use JDK detection + version="$(read_java_version)" + major_version_number="$(parse_java_major_version "$version")" + + if [ "${DEBUG}" = "true" ]; then + echo "HBASE_JDK17 not set hence using JDK detection." + echo "Extracted JDK version - ${version}, major_version_number - ${major_version_number}" + fi + + if [[ "$major_version_number" -ge "17" ]]; then + if [ "${DEBUG}" = "true" ]; then + echo "Version ${version} is greater-than/equal to 17 hence adding JDK17 options to command line." + fi + addJDK17Options=true + elif [ "${DEBUG}" = "true" ]; then + echo "Version ${version} is less than 17 hence skipping adding JDK17 options to command line." + fi +fi + +if [ "${addJDK17Options}" = "true" ]; then + add_jdk17_jvm_flags + if [ "${DEBUG}" = "true" ]; then + echo "Added JDK17 JVM flags." + fi +elif [ "${DEBUG}" = "true" ]; then + echo "Skipped adding JDK17 JVM flags." +fi + if [[ "${HBASE_OTEL_TRACING_ENABLED:-false}" = "true" ]] ; then if [ "${DEBUG}" = "true" ]; then echo "Attaching opentelemetry agent" @@ -879,6 +937,7 @@ export CLASSPATH if [ "${DEBUG}" = "true" ]; then echo "classpath=${CLASSPATH}" >&2 HBASE_OPTS="${HBASE_OPTS} -Xdiag" + echo "HBASE_OPTS=${HBASE_OPTS}" fi # resolve the command arguments diff --git a/bin/hbase-config.sh b/bin/hbase-config.sh index 104e9a0b67c3..0e8b3feed213 100644 --- a/bin/hbase-config.sh +++ b/bin/hbase-config.sh @@ -178,8 +178,12 @@ EOF fi function read_java_version() { - properties="$("${JAVA_HOME}/bin/java" -XshowSettings:properties -version 2>&1)" - echo "${properties}" | "${GREP}" java.runtime.version | head -1 | "${SED}" -e 's/.* = \([^ ]*\)/\1/' + # Avoid calling java repeatedly + if [ -z "$read_java_version_cached" ]; then + properties="$("${JAVA_HOME}/bin/java" -XshowSettings:properties -version 2>&1)" + read_java_version_cached="$(echo "${properties}" | "${GREP}" java.runtime.version | head -1 | "${SED}" -e 's/.* = \([^ ]*\)/\1/')" + fi + echo "$read_java_version_cached" } # Inspect the system properties exposed by this JVM to identify the major