You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ed...@apache.org on 2024/01/19 14:08:50 UTC
(cassandra) branch trunk updated: Limit cassandra startup to supported JDKs
This is an automated email from the ASF dual-hosted git repository.
edimitrova pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new 89e33a16ea Limit cassandra startup to supported JDKs
89e33a16ea is described below
commit 89e33a16eae20f6956127c78466b6626f41449c2
Author: shyla226 <sh...@intel.com>
AuthorDate: Wed Aug 9 14:45:01 2023 -0700
Limit cassandra startup to supported JDKs
Set CASSANDRA_JDK_UNSUPPORTED to use a newer JDK
patch by Shylaja Kokoori; reviewed by Berenguer Blasi, Ekaterina Dimitrova, Michael Semb Wever and Stefan Miklosovic for CASSANDRA-18688
---
CHANGES.txt | 1 +
bin/cassandra.in.sh | 27 ++++++++++++----
debian/patches/cassandra_in.sh_dirs.diff | 54 +++++++++++++++++++++++++++++++-
redhat/cassandra.in.sh | 25 ++++++++++++---
tools/bin/cassandra.in.sh | 29 +++++++++++++----
5 files changed, 118 insertions(+), 18 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 152f63056f..d1ed33baee 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
5.1
+ * Limit cassandra startup to supported JDKs, allow higher JDKs by setting CASSANDRA_JDK_UNSUPPORTED (CASSANDRA-18688)
* Standardize nodetool tablestats formatting of data units (CASSANDRA-19104)
* Make nodetool tablestats use number of significant digits for time and average values consistently (CASSANDRA-19015)
* Upgrade jackson to 2.15.3 and snakeyaml to 2.1 (CASSANDRA-18875)
diff --git a/bin/cassandra.in.sh b/bin/cassandra.in.sh
index dfa17643fd..6b347da7a8 100644
--- a/bin/cassandra.in.sh
+++ b/bin/cassandra.in.sh
@@ -48,7 +48,7 @@ fi
cassandra_storagedir="$CASSANDRA_HOME/data"
# JAVA_HOME can optionally be set here
-#JAVA_HOME=/usr/local/jdk6
+# JAVA_HOME=/usr/local/jdk11
for jar in "$CASSANDRA_HOME"/lib/*.jar; do
CLASSPATH="$CLASSPATH:$jar"
@@ -116,19 +116,34 @@ if [ -z $JAVA ] ; then
exit 1;
fi
+# Matches variable 'java.supported' in build.xml
+java_versions_supported=11,17
+
# Determine the sort of JVM we'll be running on.
java_ver_output=`"${JAVA:-java}" -version 2>&1`
jvmver=`echo "$java_ver_output" | grep '[openjdk|java] version' | awk -F'"' 'NR==1 {print $2}' | cut -d\- -f1`
JVM_VERSION=${jvmver%_*}
short=$(echo "${jvmver}" | cut -c1-2)
-JAVA_VERSION=17
-if [ "$short" = "11" ] ; then
- JAVA_VERSION=11
-elif [ "$JVM_VERSION" \< "17" ] ; then
- echo "Cassandra 5.0 requires Java 11 or Java 17."
+# Unsupported JDKs below the upper supported version are not allowed
+if [ "$short" != "$(echo "$java_versions_supported" | cut -d, -f1)" ] && [ "$JVM_VERSION" \< "$(echo "$java_versions_supported" | cut -d, -f2)" ] ; then
+ echo "Unsupported Java $JVM_VERSION. Supported are $java_versions_supported"
exit 1;
fi
+# Allow execution of supported Java versions, and newer if CASSANDRA_JDK_UNSUPPORTED is set
+is_supported_version=$(echo "$java_versions_supported" | tr "," '\n' | grep -F -x "$short")
+if [ -z "$is_supported_version" ] ; then
+ if [ -z "$CASSANDRA_JDK_UNSUPPORTED" ] ; then
+ echo "Unsupported Java $JVM_VERSION. Supported are $java_versions_supported"
+ echo "If you would like to test with newer Java versions set CASSANDRA_JDK_UNSUPPORTED to any value (for example, CASSANDRA_JDK_UNSUPPORTED=true). Unset the parameter for default behavior"
+ exit 1;
+ else
+ echo "######################################################################"
+ echo "Warning! You are using JDK$short. This Cassandra version only supports $java_versions_supported."
+ echo "######################################################################"
+ fi
+fi
+JAVA_VERSION=$short
jvm=`echo "$java_ver_output" | grep -A 1 '[openjdk|java] version' | awk 'NR==2 {print $1}'`
case "$jvm" in
diff --git a/debian/patches/cassandra_in.sh_dirs.diff b/debian/patches/cassandra_in.sh_dirs.diff
index 6642165beb..2926966c42 100644
--- a/debian/patches/cassandra_in.sh_dirs.diff
+++ b/debian/patches/cassandra_in.sh_dirs.diff
@@ -33,7 +33,7 @@
+cassandra_storagedir=/var/lib/cassandra
# JAVA_HOME can optionally be set here
- #JAVA_HOME=/usr/local/jdk6
+ #JAVA_HOME=/usr/local/jdk11
@@ -47,6 +47,10 @@ for jar in "$CASSANDRA_HOME"/lib/*.jar; do
CLASSPATH="$CLASSPATH:$jar"
done
@@ -45,3 +45,55 @@
CLASSPATH="$CLASSPATH:$EXTRA_CLASSPATH"
# JSR223 - collect all JSR223 engines' jars
+ #
+ # Java executable and per-Java version JVM settings
+ #
+
+ # Use JAVA_HOME if set, otherwise look for java in PATH
+ if [ -n "$JAVA_HOME" ]; then
+ # Why we can't have nice things: Solaris combines x86 and x86_64
+ # installations in the same tree, using an unconventional path for the
+ # 64bit JVM. Since we prefer 64bit, search the alternate path first,
+ # (see https://issues.apache.org/jira/browse/CASSANDRA-4638).
+ for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
+ if [ -x "$java" ]; then
+ JAVA="$java"
+ break
+ fi
+ done
+ else
+ JAVA=`command -v java 2> /dev/null`
+ fi
+
+ if [ -z $JAVA ] ; then
+ echo Unable to find java executable. Check JAVA_HOME and PATH environment variables. >&2
+ exit 1;
+ fi
+
+ # Matches variable 'java.supported' in build.xml
++java_versions_supported=11,17
+ # Determine the sort of JVM we'll be running on.
+ java_ver_output=`"${JAVA:-java}" -version 2>&1`
+ jvmver=`echo "$java_ver_output" | grep '[openjdk|java] version' | awk -F'"' 'NR==1 {print $2}' | cut -d\- -f1`
+ JVM_VERSION=${jvmver%_*}
+ short=$(echo "${jvmver}" | cut -c1-2)
+
+# Unsupported JDKs below the upper supported version are not allowed
++if [ "$short" != "$(echo "$java_versions_supported" | cut -d, -f1)" ] && [ "$JVM_VERSION" \< "$(echo "$java_versions_supported" | cut -d, -f2)" ] ; then
++ echo "Unsupported Java $JVM_VERSION. Supported are $java_versions_supported"
+ exit 1;
+ fi
+# Allow execution of supported Java versions, and newer if CASSANDRA_JDK_UNSUPPORTED is set
++is_supported_version=$(echo "$java_versions_supported" | tr "," '\n' | grep -F -x "$short")
++if [ -z "$is_supported_version" ] ; then
++ if [ -z "$CASSANDRA_JDK_UNSUPPORTED" ] ; then
++ echo "Unsupported Java $JVM_VERSION. Supported are $java_versions_supported"
++ echo "If you would like to test with newer Java versions set CASSANDRA_JDK_UNSUPPORTED to any value (for example, CASSANDRA_JDK_UNSUPPORTED=true). Unset the parameter for default behavior"
++ exit 1;
++ else
++ echo "######################################################################"
++ echo "Warning! You are using JDK$short. This Cassandra version only supports $java_versions_supported."
++ echo "######################################################################"
++ fi
++fi
++JAVA_VERSION=$short
diff --git a/redhat/cassandra.in.sh b/redhat/cassandra.in.sh
index 7f5a374514..9a89bc3564 100644
--- a/redhat/cassandra.in.sh
+++ b/redhat/cassandra.in.sh
@@ -74,19 +74,34 @@ if [ -z $JAVA ] ; then
exit 1;
fi
+# Matches variable 'java.supported' in build.xml
+java_versions_supported=11,17
+
# Determine the sort of JVM we'll be running on.
java_ver_output=`"${JAVA:-java}" -version 2>&1`
jvmver=`echo "$java_ver_output" | grep '[openjdk|java] version' | awk -F'"' 'NR==1 {print $2}' | cut -d\- -f1`
JVM_VERSION=${jvmver%_*}
short=$(echo "${jvmver}" | cut -c1-2)
-JAVA_VERSION=17
-if [ "$short" = "11" ] ; then
- JAVA_VERSION=11
-elif [ "$JVM_VERSION" \< "17" ] ; then
- echo "Cassandra 5.0 requires Java 11 or Java 17."
+# Unsupported JDKs below the upper supported version are not allowed
+if [ "$short" != "$(echo "$java_versions_supported" | cut -d, -f1)" ] && [ "$JVM_VERSION" \< "$(echo "$java_versions_supported" | cut -d, -f2)" ] ; then
+ echo "Unsupported Java $JVM_VERSION. Supported are $java_versions_supported"
exit 1;
fi
+# Allow execution of supported Java versions, and newer if CASSANDRA_JDK_UNSUPPORTED is set
+is_supported_version=$(echo "$java_versions_supported" | tr "," '\n' | grep -F -x "$short")
+if [ -z "$is_supported_version" ] ; then
+ if [ -z "$CASSANDRA_JDK_UNSUPPORTED" ] ; then
+ echo "Unsupported Java $JVM_VERSION. Supported are $java_versions_supported"
+ echo "If you would like to test with newer Java versions set CASSANDRA_JDK_UNSUPPORTED to any value (for example, CASSANDRA_JDK_UNSUPPORTED=true). Unset the parameter for default behavior"
+ exit 1;
+ else
+ echo "######################################################################"
+ echo "Warning! You are using JDK$short. This Cassandra version only supports $java_versions_supported."
+ echo "######################################################################"
+ fi
+fi
+JAVA_VERSION=$short
jvm=`echo "$java_ver_output" | grep -A 1 '[openjdk|java] version' | awk 'NR==2 {print $1}'`
case "$jvm" in
diff --git a/tools/bin/cassandra.in.sh b/tools/bin/cassandra.in.sh
index 632fc06a54..50b9a54e61 100644
--- a/tools/bin/cassandra.in.sh
+++ b/tools/bin/cassandra.in.sh
@@ -41,7 +41,7 @@ fi
cassandra_storagedir="$CASSANDRA_HOME/data"
# JAVA_HOME can optionally be set here
-#JAVA_HOME=/usr/local/jdk6
+#JAVA_HOME=/usr/local/jdk11
for jar in "$CASSANDRA_HOME"/tools/lib/*.jar; do
CLASSPATH="$CLASSPATH:$jar"
@@ -76,18 +76,35 @@ if [ -z $JAVA ] ; then
exit 1;
fi
+# Matches variable 'java.supported' in build.xml
+java_versions_supported=11,17
+
# Determine the sort of JVM we'll be running on.
java_ver_output=`"${JAVA:-java}" -version 2>&1`
jvmver=`echo "$java_ver_output" | grep '[openjdk|java] version' | awk -F'"' 'NR==1 {print $2}' | cut -d\- -f1`
JVM_VERSION=${jvmver%_*}
short=$(echo "${jvmver}" | cut -c1-2)
-JAVA_VERSION=17
-if [ "$short" = "11" ] ; then
- JAVA_VERSION=11
-elif [ "$JVM_VERSION" \< "17" ] ; then
- echo "Cassandra 5.0 requires Java 11 or Java 17(or newer)."
+# Unsupported JDKs below the upper supported version are not allowed
+if [ "$short" != "$(echo "$java_versions_supported" | cut -d, -f1)" ] && [ "$JVM_VERSION" \< "$(echo "$java_versions_supported" | cut -d, -f2)" ] ; then
+ echo "Unsupported Java $JVM_VERSION. Supported are $java_versions_supported"
+ exit 1;
+fi
+
+# Allow execution of supported Java versions, and newer if CASSANDRA_JDK_UNSUPPORTED is set
+is_supported_version=$(echo "$java_versions_supported" | tr "," '\n' | grep -F -x "$short")
+if [ -z "$is_supported_version" ] ; then
+ if [ -z "$CASSANDRA_JDK_UNSUPPORTED" ] ; then
+ echo "Unsupported Java $JVM_VERSION. Supported are $java_versions_supported"
+ echo "If you would like to test with newer Java versions set CASSANDRA_JDK_UNSUPPORTED to any value (for example, CASSANDRA_JDK_UNSUPPORTED=true). Unset the parameter for default behavior"
+ exit 1;
+ else
+ echo "######################################################################"
+ echo "Warning! You are using JDK$short. This Cassandra version only supports $java_versions_supported."
+ echo "######################################################################"
+ fi
fi
+JAVA_VERSION=$short
jvm=`echo "$java_ver_output" | grep -A 1 '[openjdk|java] version' | awk 'NR==2 {print $1}'`
case "$jvm" in
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org