Cassandra and Java 9 - ThreadPriorityPolicy=42 is outside the allowed range
Asked Answered
P

7

34

Very recently I installed JDK 9 and Apache Cassandra from the official site. But now when I start cassandra in foreground, I get this message:

apache-cassandra-3.11.1/bin$ ./cassandra -f

[0.000s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/home/mmatak/monero/apache-cassandra-3.11.1/logs/gc.log instead.
intx ThreadPriorityPolicy=42 is outside the allowed range [ 0 ... 1 ]
Improperly specified VM option 'ThreadPriorityPolicy=42'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

So far I didn't find any solution for this. Is it maybe possible that Java 9 and Cassandra are not yet compatible? Here is that problem mentioned as well - #CASSANDRA-13107

But I am not sure how to just "remove the flag"? Where is it possible to override or remove this flag?

Patron answered 25/10, 2017 at 15:17 Comment(6)
AFAIK, 0 and 1 have always been the only valid values for this option. The checking has been tightened up in JDK 9 so this may why you see this now.Idem
And do you know maybe where cassandra set this flag to 42?Patron
@AlanBateman That's already shared in the question :) The question is I believe to solve it temporarily or permanently.Lumisterol
@MartinMatak I would suggest trying to update the JVM_OPTS in the cassandra-env.sh. Another way is to edit the jvm.options file and disable the option there.Lumisterol
issues.apache.org/jira/browse/CASSANDRA-9608 seems be the issue that tracks adding support for JDK 9.Idem
Possible duplicate of Can't start Cassandra (Single-Node Cluster on CentOS7)Cycloplegia
T
17

I had exactly the same issue: Can't start Cassandra (Single-Node Cluster on CentOS7)

If it is an option for you, using Java 8, instead of 9, is the simplest way to solve the issue.

Tenant answered 27/10, 2017 at 7:34 Comment(2)
Yeah, currently I downgraded it to Java 8. I hope this error will be fixed soon..Patron
For Mac based system, you can try export JAVA_HOME=/usr/libexec/java_home -v 1.8``Ceilidh
R
12

Setting the following env variables solved the problem in MAC export JAVA8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

Retsina answered 22/12, 2018 at 18:35 Comment(1)
i have set the JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home" , but same error.Inappetence
N
7

@Martin Matak Just comment out that line in the conf/jvm.options file:

########################
# GENERAL JVM SETTINGS #
########################



# allows lowering thread priority without being root on linux - probably
# not necessary on Windows but doesn't harm anything.
# see http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html
**#-XX:ThreadPriorityPolicy=42**
Namecalling answered 8/2, 2018 at 10:49 Comment(1)
And what would be the consequences then?Patron
C
3

Some background on -XX:ThreadPriorityPolicy.

These were the values, as documented in the source code.

0 : Normal.
    VM chooses priorities that are appropriate for normal
    applications. On Solaris NORM_PRIORITY and above are mapped
    to normal native priority. Java priorities below
    NORM_PRIORITY map to lower native priority values. On
    Windows applications are allowed to use higher native
    priorities. However, with ThreadPriorityPolicy=0, VM will
    not use the highest possible native priority,
    THREAD_PRIORITY_TIME_CRITICAL, as it may interfere with
    system threads. On Linux thread priorities are ignored
    because the OS does not support static priority in
    SCHED_OTHER scheduling class which is the only choice for
    non-root, non-realtime applications.
1 : Aggressive.
    Java thread priorities map over to the entire range of
    native thread priorities. Higher Java thread priorities map
    to higher native thread priorities. This policy should be
    used with care, as sometimes it can cause performance
    degradation in the application and/or the entire system. On
    Linux this policy requires root privilege.

In other words: The default Normal setting causes thread priorities to be ignored on Linux.

Now someone found a bug in the code, which disabled the "is root?" check for values other than 1, but would still try to set the thread priority for every value other than 0.

Unless running as root, it would only be possible to lower the thread priority. So although not perfect, this was quite an improvement, compared to not being able to control the priorities at all.

Starting with Java 9, command line arguments like this one started to get checked, and this hack stopped working.

Fwiw, on Java 11/Linux, I can set the parameter to 1 without being root, and setting thread priorities does have an effect. So something has changed in the meantime, and at least with recent JVMs, and this hack does not seem necessary any more.

Confocal answered 11/10, 2019 at 0:37 Comment(0)
C
1

Solution to your Question

Reason for this exception

  1. Multiple JDK versions running,probably JDK9,JDK 10 is causing this exception.
  2. Set the Path to Point JDK 8 Version only.
  3. Currently cassandra 3.1 is desired to run greater than jdk 8 only.

Change in Cassandra-Conf file (/opt/apache-cassandra-3.11.2/conf/cassandra-env.sh)

4.If you want to use higher JDK Version, update the system path variables based on your OS.

Condemnation answered 4/7, 2018 at 13:48 Comment(0)
M
0

Theres a jvm.options in your conf directory which sets it:

https://github.com/apache/cassandra/blob/12d4e2f189fb228250edc876963d0c74b5ab0d4f/conf/jvm.options#L96

Maxama answered 25/10, 2017 at 16:35 Comment(1)
And do you know maybe how it should be set so that I can run Cassandra properly with Java 9?Patron
Y
0

Following from Jay's answer if you're on macOS and installed via Homebrew: the file is located at local/etc/cassandra/jvm.options.

Yaya answered 20/7, 2019 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.