Support for Java 11

In the new Java release cadence a new Java version is made available every six months. The more frequent release cycle is favored as it brings new Java features to the developers as and when they are developed without the wait that the earlier 3 year release model incurred. Not every Java version is a Long Term Support (LTS) version. After Java 8 the next LTS version is Java 11. Java 9, 10, 12 and 13 are all non-LTS versions.

One of the objectives of the Apache Cassandra 4.0 version is to support the recent LTS Java versions 8 and 11 (CASSANDRA-9608). Java 8 and Java 11 may be used to build and run Apache Cassandra 4.0. Effective Cassandra 4.0.2 there is full Java 11 support, it is not experimental anymore.

Support Matrix

The support matrix for the Java versions for compiling and running Apache Cassandra 4.0 is detailed in Table 1. The build version is along the vertical axis and the run version is along the horizontal axis.

Table 1 : Support Matrix for Java

Java 8 (Run)

Java 11 (Run)

Java 8 (Build)

Supported

Supported

Java 11(Build)

Not Supported

Supported

Essentially 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 run Apache Cassandra 4.0.

Using Java 8 to Build

To start with, install Java 8. As an example, for installing Java 8 on RedHat Linux the command is as follows:

  1. $ sudo yum install java-1.8.0-openjdk-devel

Set JAVA_HOME and JRE_HOME environment variables in the shell bash script. First, open the bash script:

  1. $ sudo vi ~/.bashrc

Set the environment variables including the PATH.

  1. $ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
  2. $ export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk/jre
  3. $ export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

Download and install Apache Cassandra 4.0 source code from the Git along with the dependencies.

  1. $ git clone https://github.com/apache/cassandra.git

If Cassandra is already running stop Cassandra with the following command.

  1. [ec2-user@ip-172-30-3-146 bin]$ ./nodetool stopdaemon

Build the source code from the cassandra directory, which has the build.xml build script. The Apache Ant uses the Java version set in the JAVA_HOME environment variable.

  1. $ cd ~/cassandra
  2. $ ant

Apache Cassandra 4.0 gets built with Java 8. Set the environment variable for CASSANDRA_HOME in the bash script. Also add the CASSANDRA_HOME/bin to the PATH variable.

  1. $ export CASSANDRA_HOME=~/cassandra
  2. $ export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$CASSANDRA_HOME/bin

To run Apache Cassandra 4.0 with either of Java 8 or Java 11 run the Cassandra application in the CASSANDRA_HOME/bin directory, which is in the PATH env variable.

  1. $ cassandra

The Java version used to run Cassandra gets output as Cassandra is getting started. As an example if Java 11 is used, the run output should include similar to the following output snippet:

  1. INFO [main] 2019-07-31 21:18:16,862 CassandraDaemon.java:480 - Hostname: ip-172-30-3-
  2. 146.ec2.internal:7000:7001
  3. INFO [main] 2019-07-31 21:18:16,862 CassandraDaemon.java:487 - JVM vendor/version: OpenJDK
  4. 64-Bit Server VM/11.0.3
  5. INFO [main] 2019-07-31 21:18:16,863 CassandraDaemon.java:488 - Heap size:
  6. 1004.000MiB/1004.000MiB

The following output indicates a single node Cassandra 4.0 cluster has started.

  1. INFO [main] 2019-07-31 21:18:19,687 InboundConnectionInitiator.java:130 - Listening on
  2. address: (127.0.0.1:7000), nic: lo, encryption: enabled (openssl)
  3. ...
  4. ...
  5. INFO [main] 2019-07-31 21:18:19,850 StorageService.java:512 - Unable to gossip with any
  6. peers but continuing anyway since node is in its own seed list
  7. INFO [main] 2019-07-31 21:18:19,864 StorageService.java:695 - Loading persisted ring state
  8. INFO [main] 2019-07-31 21:18:19,865 StorageService.java:814 - Starting up server gossip
  9. INFO [main] 2019-07-31 21:18:20,088 BufferPool.java:216 - Global buffer pool is enabled,
  10. when pool is exhausted (max is 251.000MiB) it will allocate on heap
  11. INFO [main] 2019-07-31 21:18:20,110 StorageService.java:875 - This node will not auto
  12. bootstrap because it is configured to be a seed node.
  13. ...
  14. ...
  15. INFO [main] 2019-07-31 21:18:20,809 StorageService.java:1507 - JOINING: Finish joining ring
  16. INFO [main] 2019-07-31 21:18:20,921 StorageService.java:2508 - Node 127.0.0.1:7000 state
  17. jump to NORMAL

Using Java 11 to Build

If Java 11 is used to build Apache Cassandra 4.0, first Java 11 must be installed and the environment variables set. As an example, to download and install Java 11 on RedHat Linux run the following command.

  1. $ yum install java-11-openjdk-devel

Set the environment variables in the bash script for Java 11. The first command is to open the bash script.

  1. $ sudo vi ~/.bashrc
  2. $ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
  3. $ export JRE_HOME=/usr/lib/jvm/java-11-openjdk/jre
  4. $ export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

To build source code with Java 11 one of the following two options must be used.

  1. Include Apache Ant command-line option -Duse.jdk=11 as follows
  1. $ ant -Duse.jdk=11
  1. Set environment variable CASSANDRA_USE_JDK11 to true
  1. $ export CASSANDRA_USE_JDK11=true

As an example, set the environment variable CASSANDRA_USE_JDK11 to true.

  1. [ec2-user@ip-172-30-3-146 cassandra]$ export CASSANDRA_USE_JDK11=true
  2. [ec2-user@ip-172-30-3-146 cassandra]$ ant
  3. Buildfile: /home/ec2-user/cassandra/build.xml

Or, set the command-line option.

  1. [ec2-user@ip-172-30-3-146 cassandra]$ ant -Duse.jdk11=true

The build output should include the following.

  1. _build_java:
  2. [echo] Compiling for Java 11
  3. ...
  4. ...
  5. build:
  6. _main-jar:
  7. [copy] Copying 1 file to /home/ec2-user/cassandra/build/classes/main/META-INF
  8. [jar] Building jar: /home/ec2-user/cassandra/build/apache-cassandra-4.0-SNAPSHOT.jar
  9. ...
  10. ...
  11. _build-test:
  12. [javac] Compiling 739 source files to /home/ec2-user/cassandra/build/test/classes
  13. [copy] Copying 25 files to /home/ec2-user/cassandra/build/test/classes
  14. ...
  15. ...
  16. jar:
  17. [mkdir] Created dir: /home/ec2-user/cassandra/build/classes/stress/META-INF
  18. [mkdir] Created dir: /home/ec2-user/cassandra/build/tools/lib
  19. [jar] Building jar: /home/ec2-user/cassandra/build/tools/lib/stress.jar
  20. [mkdir] Created dir: /home/ec2-user/cassandra/build/classes/fqltool/META-INF
  21. [jar] Building jar: /home/ec2-user/cassandra/build/tools/lib/fqltool.jar
  22. BUILD SUCCESSFUL
  23. Total time: 1 minute 3 seconds
  24. [ec2-user@ip-172-30-3-146 cassandra]$

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.

  1. [ec2-user@ip-172-30-3-146 cassandra]$ ant
  2. Buildfile: /home/ec2-user/cassandra/build.xml
  3. validate-build-conf:
  4. BUILD FAILED
  5. /home/ec2-user/cassandra/build.xml:293: -Duse.jdk11=true or $CASSANDRA_USE_JDK11=true must
  6. be set when building from java 11
  7. Total time: 1 second
  8. [ec2-user@ip-172-30-3-146 cassandra]$

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 message gets output.

  1. [root@localhost ~]# ssh -i cassandra.pem ec2-user@ec2-3-85-85-75.compute-1.amazonaws.com
  2. Last login: Wed Jul 31 20:47:26 2019 from 75.155.255.51
  3. [ec2-user@ip-172-30-3-146 ~]$ echo $JAVA_HOME
  4. /usr/lib/jvm/java-1.8.0-openjdk
  5. [ec2-user@ip-172-30-3-146 ~]$ cassandra
  6. ...
  7. ...
  8. Error: A JNI error has occurred, please check your installation and try again
  9. Exception in thread "main" java.lang.UnsupportedClassVersionError:
  10. org/apache/cassandra/service/CassandraDaemon has been compiled by a more recent version of
  11. the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes
  12. class file versions up to 52.0
  13. at java.lang.ClassLoader.defineClass1(Native Method)
  14. at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
  15. at ...
  16. ...

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.

  1. [root@localhost ~]# ssh -i cassandra.pem ec2-user@ec2-3-85-85-75.compute-1.amazonaws.com
  2. Last login: Wed Jul 31 21:41:50 2019 from 75.155.255.51
  3. [ec2-user@ip-172-30-3-146 ~]$ echo $JAVA_HOME
  4. /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.

  1. [ec2-user@ip-172-30-3-146 ~]$ cd
  2. cassandra
  3. [ec2-user@ip-172-30-3-146 cassandra]$ export CASSANDRA_USE_JDK11=true
  4. [ec2-user@ip-172-30-3-146 cassandra]$ ant
  5. Buildfile: /home/ec2-user/cassandra/build.xml
  6. validate-build-conf:
  7. BUILD FAILED
  8. /home/ec2-user/cassandra/build.xml:285: -Duse.jdk11=true or $CASSANDRA_USE_JDK11=true cannot
  9. be set when building from java 8
  10. Total time: 0 seconds