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 763c2a4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
63 changes: 61 additions & 2 deletions bin/hbase
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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}" != "" ]; 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 +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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions bin/hbase-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 763c2a4

Please sign in to comment.