Skip to content

Commit

Permalink
HBASE-28252 Update JDK11 and add JDK17 options to hbase script
Browse files Browse the repository at this point in the history
Change-Id: I0ade930b2f92a0dfd015697a9c4de20e7de65ba5
  • Loading branch information
stoty committed Dec 8, 2023
1 parent 6e421e9 commit cf0d5f2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
63 changes: 61 additions & 2 deletions bin/hbase
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ if [ -f "$HBASE_HOME/conf/hbase-env-$COMMAND.sh" ]; then
. "$HBASE_HOME/conf/hbase-env-$COMMAND.sh"
fi


# establish a default value for HBASE_OPTS if it's not already set. For now,
# all we set is the garbage collector.
if [ -z "${HBASE_OPTS}" ] ; then
Expand Down Expand Up @@ -496,7 +497,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() {
Expand Down Expand Up @@ -786,11 +791,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}" != "" ]; then
# JDK17 needs everything JDK11 needs
HBASE_JDK11="${HBASE_JDK17}"
if [ "${DEBUG}" = "true" ]; then
echo "HBASE_JDK17 is set. 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
Expand Down Expand Up @@ -838,6 +851,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"
Expand Down
7 changes: 5 additions & 2 deletions bin/hbase-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ 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/'
if [ -z "$read_java_version_properties" ]; then
# Avoid calling java repeatedly
read_java_version_properties="$("${JAVA_HOME}/bin/java" -XshowSettings:properties -version 2>&1)"
fi
echo "${read_java_version_properties}" | "${GREP}" java.runtime.version | head -1 | "${SED}" -e 's/.* = \([^ ]*\)/\1/'
}

# Inspect the system properties exposed by this JVM to identify the major
Expand Down

0 comments on commit cf0d5f2

Please sign in to comment.