Prepare for JDK17 experimental support

Removes the use of CASSANDRA_USE_JDK11 and introduces the build.xml properties `java.default` and `java.supported`.

 patch by Mick Semb Wever; reviewed by Ekaterina Dimitrova for CASSANDRA-18179
This commit is contained in:
Mick Semb Wever 2023-01-21 12:46:56 +01:00
parent a0ec0ae303
commit 86604f5038
No known key found for this signature in database
GPG Key ID: E91335D77E3E87CB
5 changed files with 84 additions and 197 deletions

View File

@ -1,4 +1,5 @@
4.2 4.2
* Prepare for JDK17 experimental support (CASSANDRA-18179)
* Remove Scripted UDFs internals; hooks to be added later in CASSANDRA-17281 (CASSANDRA-18252) * Remove Scripted UDFs internals; hooks to be added later in CASSANDRA-17281 (CASSANDRA-18252)
* Update JNA to 5.13.0 (CASSANDRA-18050) * Update JNA to 5.13.0 (CASSANDRA-18050)
* Make virtual tables decide if they implicitly enable ALLOW FILTERING (CASSANDRA-18238) * Make virtual tables decide if they implicitly enable ALLOW FILTERING (CASSANDRA-18238)

116
build.xml
View File

@ -37,6 +37,15 @@
<property name="scm.developerConnection" value="scm:https://gitbox.apache.org/repos/asf/cassandra.git"/> <property name="scm.developerConnection" value="scm:https://gitbox.apache.org/repos/asf/cassandra.git"/>
<property name="scm.url" value="https://gitbox.apache.org/repos/asf?p=cassandra.git;a=tree"/> <property name="scm.url" value="https://gitbox.apache.org/repos/asf?p=cassandra.git;a=tree"/>
<!-- JDKs supported.
All releases are built with the default JDK.
Builds with non-default JDKs are considered experimental and for development and testing purposes.
When building, javac's source and target flags are set to the jdk used, so lower JDKs are not supported at runtime.
The use of both CASSANDRA_USE_JDK11 and use-jdk11 is deprecated.
-->
<property name="java.default" value="1.8" />
<property name="java.supported" value="1.8,11,17" />
<!-- directory details --> <!-- directory details -->
<property name="basedir" value="."/> <property name="basedir" value="."/>
<property name="build.src" value="${basedir}/src"/> <property name="build.src" value="${basedir}/src"/>
@ -156,21 +165,16 @@
<javac srcdir="test/anttasks" destdir="${test.classes}" includeantruntime="true"/> <javac srcdir="test/anttasks" destdir="${test.classes}" includeantruntime="true"/>
<taskdef name="KeepBriefBrief" classname="org.apache.cassandra.anttasks.KeepBriefBrief" classpath="${test.classes}"/> <taskdef name="KeepBriefBrief" classname="org.apache.cassandra.anttasks.KeepBriefBrief" classpath="${test.classes}"/>
<KeepBriefBrief property="cassandra.keepBriefBrief"/> <KeepBriefBrief property="cassandra.keepBriefBrief"/>
<taskdef name="JdkProperties" classname="org.apache.cassandra.anttasks.JdkProperties" classpath="${test.classes}"/>
<JdkProperties/>
</sequential> </sequential>
</macrodef> </macrodef>
<condition property="java.version.8"> <fail message="Unsupported JDK version used: ${ant.java.version}">
<equals arg1="${ant.java.version}" arg2="1.8"/> <condition><not><contains string="${java.supported}" substring="${ant.java.version}"/></not></condition>
</condition> </fail>
<condition property="java.version.11"> <condition property="is.java.default"><equals arg1="${ant.java.version}" arg2="${java.default}"/></condition>
<!-- This includes every JDK other than 8; so JDK 9 is flagged as JDK 11, and JDK 17 is as well... at the moment this is desired behavior <echo unless:true="${is.java.default}" message="Non default JDK version used: ${ant.java.version}"/>
and may be relooked at once JDK 8 support is dropped -->
<not><isset property="java.version.8"/></not>
</condition>
<fail message="Unsupported JDK version used: ${ant.java.version}"><condition><not><or>
<isset property="java.version.8"/>
<isset property="java.version.11"/>
</or></not></condition></fail>
<condition property="arch_x86"> <condition property="arch_x86">
<equals arg1="${os.arch}" arg2="x86" /> <equals arg1="${os.arch}" arg2="x86" />
@ -262,17 +266,6 @@
</not> </not>
</condition> </condition>
<condition property="build.java.11">
<istrue value="${use.jdk11}"/>
</condition>
<condition property="source.version" value="8" else="11">
<equals arg1="${java.version.8}" arg2="true"/>
</condition>
<condition property="target.version" value="8" else="11">
<equals arg1="${java.version.8}" arg2="true"/>
</condition>
<!-- <!--
Add all the dependencies. Add all the dependencies.
--> -->
@ -314,57 +307,10 @@
</sequential> </sequential>
</macrodef> </macrodef>
<target name="validate-build-conf">
<condition property="use-jdk11">
<or>
<isset property="build.java.11"/>
<istrue value="${env.CASSANDRA_USE_JDK11}"/>
</or>
</condition>
<fail message="Inconsistent JDK11 options set">
<condition>
<and>
<istrue value="${env.CASSANDRA_USE_JDK11}"/>
<isset property="use.jdk11"/>
<not>
<istrue value="${use.jdk11}"/>
</not>
</and>
</condition>
</fail>
<fail message="Inconsistent JDK11 options set">
<condition>
<and>
<isset property="env.CASSANDRA_USE_JDK11"/>
<not>
<istrue value="${env.CASSANDRA_USE_JDK11}"/>
</not>
<istrue value="${use.jdk11}"/>
</and>
</condition>
</fail>
<fail message="-Duse.jdk11=true or $CASSANDRA_USE_JDK11=true cannot be set when building from java 8">
<condition>
<not><or>
<not><isset property="java.version.8"/></not>
<not><isset property="use-jdk11"/></not>
</or></not>
</condition>
</fail>
<fail message="-Duse.jdk11=true or $CASSANDRA_USE_JDK11=true must be set when building from java 11">
<condition>
<not><or>
<isset property="java.version.8"/>
<isset property="use-jdk11"/>
</or></not>
</condition>
</fail>
</target>
<!-- <!--
Setup the output directories. Setup the output directories.
--> -->
<target name="init" depends="validate-build-conf"> <target name="init" >
<fail unless="is.source.artifact" <fail unless="is.source.artifact"
message="Not a source artifact, stopping here." /> message="Not a source artifact, stopping here." />
<mkdir dir="${build.classes.main}"/> <mkdir dir="${build.classes.main}"/>
@ -492,11 +438,11 @@
<target name="_build_java"> <target name="_build_java">
<!-- Note: we cannot use javac's 'release' option, as that does not allow accessing sun.misc.Unsafe nor <!-- Note: we cannot use javac's 'release' option, as that does not allow accessing sun.misc.Unsafe nor
Nashorn's ClassFilter class as any javac modules option is invalid for relase 8. --> Nashorn's ClassFilter class as any javac modules option is invalid for release 8. -->
<echo message="Compiling for Java ${target.version}..."/> <echo message="Compiling for Java ${ant.java.version}..."/>
<javac <javac
debug="true" debuglevel="${debuglevel}" encoding="utf-8" debug="true" debuglevel="${debuglevel}" encoding="utf-8"
destdir="${build.classes.main}" includeantruntime="false" source="${source.version}" target="${target.version}"> destdir="${build.classes.main}" includeantruntime="false" source="${ant.java.version}" target="${ant.java.version}">
<src path="${build.src.java}"/> <src path="${build.src.java}"/>
<src path="${build.src.gen-java}"/> <src path="${build.src.gen-java}"/>
<compilerarg value="-XDignore.symbol.file"/> <compilerarg value="-XDignore.symbol.file"/>
@ -528,7 +474,7 @@
<target name="stress-build-test" depends="stress-build" description="Compile stress tests"> <target name="stress-build-test" depends="stress-build" description="Compile stress tests">
<javac debug="true" debuglevel="${debuglevel}" destdir="${stress.test.classes}" <javac debug="true" debuglevel="${debuglevel}" destdir="${stress.test.classes}"
source="${source.version}" target="${target.version}" source="${ant.java.version}" target="${ant.java.version}"
includeantruntime="false" encoding="utf-8"> includeantruntime="false" encoding="utf-8">
<classpath> <classpath>
<path refid="cassandra.classpath.test"/> <path refid="cassandra.classpath.test"/>
@ -545,7 +491,7 @@
<target name="_stress_build"> <target name="_stress_build">
<mkdir dir="${stress.build.classes}" /> <mkdir dir="${stress.build.classes}" />
<javac compiler="modern" debug="true" debuglevel="${debuglevel}" <javac compiler="modern" debug="true" debuglevel="${debuglevel}"
source="${source.version}" target="${target.version}" source="${ant.java.version}" target="${ant.java.version}"
encoding="utf-8" destdir="${stress.build.classes}" includeantruntime="true"> encoding="utf-8" destdir="${stress.build.classes}" includeantruntime="true">
<src path="${stress.build.src}" /> <src path="${stress.build.src}" />
<classpath> <classpath>
@ -586,7 +532,7 @@
<target name="fqltool-build-test" depends="fqltool-build" description="Compile fqltool tests"> <target name="fqltool-build-test" depends="fqltool-build" description="Compile fqltool tests">
<javac debug="true" debuglevel="${debuglevel}" destdir="${fqltool.test.classes}" <javac debug="true" debuglevel="${debuglevel}" destdir="${fqltool.test.classes}"
source="${source.version}" target="${target.version}" source="${ant.java.version}" target="${ant.java.version}"
includeantruntime="false" encoding="utf-8"> includeantruntime="false" encoding="utf-8">
<classpath> <classpath>
<path refid="cassandra.classpath.test"/> <path refid="cassandra.classpath.test"/>
@ -603,7 +549,7 @@
<target name="_fqltool_build"> <target name="_fqltool_build">
<mkdir dir="${fqltool.build.classes}" /> <mkdir dir="${fqltool.build.classes}" />
<javac compiler="modern" debug="true" debuglevel="${debuglevel}" <javac compiler="modern" debug="true" debuglevel="${debuglevel}"
source="${source.version}" target="${target.version}" source="${ant.java.version}" target="${ant.java.version}"
encoding="utf-8" destdir="${fqltool.build.classes}" includeantruntime="true"> encoding="utf-8" destdir="${fqltool.build.classes}" includeantruntime="true">
<src path="${fqltool.build.src}" /> <src path="${fqltool.build.src}" />
<classpath> <classpath>
@ -640,7 +586,7 @@
<target name="_simulator-asm_build"> <target name="_simulator-asm_build">
<mkdir dir="${simulator-asm.build.classes}" /> <mkdir dir="${simulator-asm.build.classes}" />
<javac compiler="modern" debug="true" debuglevel="${debuglevel}" <javac compiler="modern" debug="true" debuglevel="${debuglevel}"
source="${source.version}" target="${target.version}" source="${ant.java.version}" target="${ant.java.version}"
encoding="utf-8" destdir="${simulator-asm.build.classes}" includeantruntime="true"> encoding="utf-8" destdir="${simulator-asm.build.classes}" includeantruntime="true">
<src path="${simulator-asm.build.src}" /> <src path="${simulator-asm.build.src}" />
<classpath> <classpath>
@ -657,7 +603,7 @@
<target name="_simulator-bootstrap_build"> <target name="_simulator-bootstrap_build">
<mkdir dir="${simulator-bootstrap.build.classes}" /> <mkdir dir="${simulator-bootstrap.build.classes}" />
<javac compiler="modern" debug="true" debuglevel="${debuglevel}" <javac compiler="modern" debug="true" debuglevel="${debuglevel}"
source="${source.version}" target="${target.version}" source="${ant.java.version}" target="${ant.java.version}"
encoding="utf-8" destdir="${simulator-bootstrap.build.classes}" includeantruntime="true"> encoding="utf-8" destdir="${simulator-bootstrap.build.classes}" includeantruntime="true">
<src path="${simulator-bootstrap.build.src}" /> <src path="${simulator-bootstrap.build.src}" />
<classpath> <classpath>
@ -1011,8 +957,8 @@
debuglevel="${debuglevel}" debuglevel="${debuglevel}"
destdir="${test.classes}" destdir="${test.classes}"
includeantruntime="true" includeantruntime="true"
source="${source.version}" source="${ant.java.version}"
target="${target.version}" target="${ant.java.version}"
encoding="utf-8"> encoding="utf-8">
<classpath> <classpath>
<path refid="cassandra.classpath.test"/> <path refid="cassandra.classpath.test"/>
@ -1129,7 +1075,7 @@
<jvmarg value="-Dcassandra.test.sstableformatdevelopment=true"/> <jvmarg value="-Dcassandra.test.sstableformatdevelopment=true"/>
<!-- The first time SecureRandom initializes can be slow if it blocks on /dev/random --> <!-- The first time SecureRandom initializes can be slow if it blocks on /dev/random -->
<jvmarg value="-Djava.security.egd=file:/dev/urandom" /> <jvmarg value="-Djava.security.egd=file:/dev/urandom" />
<jvmarg value="-Dcassandra.testtag=@{testtag}"/> <jvmarg value="-Dcassandra.testtag=@{testtag}.jdk${ant.java.version}"/>
<jvmarg value="-Dcassandra.keepBriefBrief=${cassandra.keepBriefBrief}" /> <jvmarg value="-Dcassandra.keepBriefBrief=${cassandra.keepBriefBrief}" />
<jvmarg value="-Dcassandra.strict.runtime.checks=true" /> <jvmarg value="-Dcassandra.strict.runtime.checks=true" />
<jvmarg value="-Dcassandra.reads.thresholds.coordinator.defensive_checks_enabled=true" /> <!-- enable defensive checks --> <jvmarg value="-Dcassandra.reads.thresholds.coordinator.defensive_checks_enabled=true" /> <!-- enable defensive checks -->
@ -1923,9 +1869,9 @@
failonerror="true" failonerror="true"
maxmemory="512m"> maxmemory="512m">
<arg value="-source"/> <arg value="-source"/>
<arg value="${source.version}" /> <arg value="${java.default}" />
<arg value="-target"/> <arg value="-target"/>
<arg value="${target.version}" /> <arg value="${ant.java.version}" />
<arg value="-d" /> <arg value="-d" />
<arg value="none" /> <arg value="none" />
<arg value="-proc:none" /> <arg value="-proc:none" />

View File

@ -26,11 +26,15 @@ Table 1 : Support Matrix for Java
|=== |===
| |Java 8 (Run) |Java 11 (Run) | |Java 8 (Run) |Java 11 (Run)
|Java 8 (Build) |Supported |Supported |Java 8 (Build) |Supported |Supported
|Java 11(Build) |Not Supported |Supported |Java 11(Build) |Not Supported |Experimental
|=== |===
Essentially Apache 4.0 source code built with Java 11 cannot be run with Apache 4.0 source code built with Java 11 cannot be run with
Java 8. Next, we shall discuss using each of Java 8 and 11 to build and Java 8.
All binary releases are built with Java 8.
Next, we shall discuss using each of Java 8 and 11 to build and
run Apache Cassandra 4.0. run Apache Cassandra 4.0.
== Using Java 8 to Build == Using Java 8 to Build
@ -42,18 +46,10 @@ RedHat Linux the command is as follows:
$ sudo yum install java-1.8.0-openjdk-devel $ sudo yum install java-1.8.0-openjdk-devel
.... ....
Set `JAVA_HOME` and `JRE_HOME` environment variables in the shell bash Set the environment variables `JAVA_HOME` and `PATH`.
script. First, open the bash script:
....
$ sudo vi ~/.bashrc
....
Set the environment variables including the `PATH`.
.... ....
$ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk $ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
$ export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk/jre
$ export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin $ export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
.... ....
@ -68,7 +64,7 @@ If Cassandra is already running stop Cassandra with the following
command. command.
.... ....
[ec2-user@ip-172-30-3-146 bin]$ ./nodetool stopdaemon $ ./nodetool stopdaemon
.... ....
Build the source code from the `cassandra` directory, which has the Build the source code from the `cassandra` directory, which has the
@ -143,53 +139,19 @@ and install Java 11 on RedHat Linux run the following command.
$ yum install java-11-openjdk-devel $ yum install java-11-openjdk-devel
.... ....
Set the environment variables in the bash script for Java 11. The first Set the environment variables `JAVA_HOME` and `PATH`.
command is to open the bash script.
.... ....
$ sudo vi ~/.bashrc
$ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk $ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
$ export JRE_HOME=/usr/lib/jvm/java-11-openjdk/jre
$ export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin $ export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
.... ....
To build source code with Java 11 one of the following two options must The build output should now include the following.
be used.
____
[arabic]
. {blank}
+
Include Apache Ant command-line option `-Duse.jdk=11` as follows:::
....
$ ant -Duse.jdk=11
....
. {blank}
+
Set environment variable `CASSANDRA_USE_JDK11` to `true`:::
....
$ export CASSANDRA_USE_JDK11=true
....
____
As an example, set the environment variable `CASSANDRA_USE_JDK11` to
`true`.
....
[ec2-user@ip-172-30-3-146 cassandra]$ export CASSANDRA_USE_JDK11=true
[ec2-user@ip-172-30-3-146 cassandra]$ ant
Buildfile: /home/ec2-user/cassandra/build.xml
....
Or, set the command-line option.
....
[ec2-user@ip-172-30-3-146 cassandra]$ ant -Duse.jdk11=true
....
The build output should include the following.
.... ....
[echo] Non default JDK version used: 11
...
...
_build_java: _build_java:
[echo] Compiling for Java 11 [echo] Compiling for Java 11
... ...
@ -215,36 +177,20 @@ jar:
BUILD SUCCESSFUL BUILD SUCCESSFUL
Total time: 1 minute 3 seconds Total time: 1 minute 3 seconds
[ec2-user@ip-172-30-3-146 cassandra]$
.... ....
== Common Issues == Common Issues
One of the two options mentioned must be used to compile with JDK 11 or
the build fails and the following error message is output.
....
[ec2-user@ip-172-30-3-146 cassandra]$ ant
Buildfile: /home/ec2-user/cassandra/build.xml
validate-build-conf:
BUILD FAILED
/home/ec2-user/cassandra/build.xml:293: -Duse.jdk11=true or $CASSANDRA_USE_JDK11=true must
be set when building from java 11
Total time: 1 second
[ec2-user@ip-172-30-3-146 cassandra]$
....
The Java 11 built Apache Cassandra 4.0 source code may be run with Java The Java 11 built Apache Cassandra 4.0 source code may be run with Java
11 only. If a Java 11 built code is run with Java 8 the following error 11 only. If a Java 11 built code is run with Java 8 the following error
message gets output. message gets output.
.... ....
[root@localhost ~]# ssh -i cassandra.pem ec2-user@ec2-3-85-85-75.compute-1.amazonaws.com # ssh -i cassandra.pem ec2-user@ec2-3-85-85-75.compute-1.amazonaws.com
Last login: Wed Jul 31 20:47:26 2019 from 75.155.255.51 Last login: Wed Jul 31 20:47:26 2019 from 75.155.255.51
[ec2-user@ip-172-30-3-146 ~]$ echo $JAVA_HOME $ echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk /usr/lib/jvm/java-1.8.0-openjdk
[ec2-user@ip-172-30-3-146 ~]$ cassandra $ cassandra
... ...
... ...
Error: A JNI error has occurred, please check your installation and try again Error: A JNI error has occurred, please check your installation and try again
@ -258,33 +204,3 @@ class file versions up to 52.0
... ...
.... ....
The `CASSANDRA_USE_JDK11` variable or the command-line option
`-Duse.jdk11` cannot be used to build with Java 8. To demonstrate set
`JAVA_HOME` to version 8.
....
[root@localhost ~]# ssh -i cassandra.pem ec2-user@ec2-3-85-85-75.compute-1.amazonaws.com
Last login: Wed Jul 31 21:41:50 2019 from 75.155.255.51
[ec2-user@ip-172-30-3-146 ~]$ echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk
....
Set the `CASSANDRA_USE_JDK11=true` or command-line option
`-Duse.jdk11=true`. Subsequently, run Apache Ant to start the build. The
build fails with error message listed.
....
[ec2-user@ip-172-30-3-146 ~]$ cd
cassandra
[ec2-user@ip-172-30-3-146 cassandra]$ export CASSANDRA_USE_JDK11=true
[ec2-user@ip-172-30-3-146 cassandra]$ ant
Buildfile: /home/ec2-user/cassandra/build.xml
validate-build-conf:
BUILD FAILED
/home/ec2-user/cassandra/build.xml:285: -Duse.jdk11=true or $CASSANDRA_USE_JDK11=true cannot
be set when building from java 8
Total time: 0 seconds
....

View File

@ -41,18 +41,9 @@ export CCM_HEAP_NEWSIZE="200M"
export CCM_CONFIG_DIR=${WORKSPACE}/.ccm export CCM_CONFIG_DIR=${WORKSPACE}/.ccm
export NUM_TOKENS="16" export NUM_TOKENS="16"
export CASSANDRA_DIR=${WORKSPACE} export CASSANDRA_DIR=${WORKSPACE}
export TESTSUITE_NAME="cqlshlib.${PYTHON_VERSION}"
if [ -z "$CASSANDRA_USE_JDK11" ]; then java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | awk -F. '{print $1}')
export CASSANDRA_USE_JDK11=false export TESTSUITE_NAME="cqlshlib.${PYTHON_VERSION}.jdk${java_version}"
fi
if [ "$CASSANDRA_USE_JDK11" = true ] ; then
TESTSUITE_NAME="${TESTSUITE_NAME}.jdk11"
else
TESTSUITE_NAME="${TESTSUITE_NAME}.jdk8"
unset JAVA11_HOME
fi
ant -buildfile ${CASSANDRA_DIR}/build.xml realclean ant -buildfile ${CASSANDRA_DIR}/build.xml realclean
# Loop to prevent failure due to maven-ant-tasks not downloading a jar.. # Loop to prevent failure due to maven-ant-tasks not downloading a jar..

View File

@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.anttasks;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
public class JdkProperties extends Task
{
public void execute()
{
Project project = getProject();
project.setNewProperty("java.version." + project.getProperty("ant.java.version"), "true");
project.setNewProperty("use-jdk" + project.getProperty("ant.java.version"), "true");
}
}