Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra start error with ThreadPriorityPolicy=42

When I am trying to start Cassandra it shows me error like this I already did changes in the conf file also in env.sh, the file also.

No options of similar type error is working for this.

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.

Other Information

java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
like image 297
Jayant Chauhan Avatar asked Feb 17 '18 17:02

Jayant Chauhan


3 Answers

This is a known issue of Cassandra - CASSANDRA-13107.

Before Java 9 JVM accepted any integer value for ThreadPriorityPolicy, while 0 and 1 were the only valid values.

ThreadPriorityPolicy=1 allows to raise thread priorities, but only if the process starts with root privileges. When ThreadPriorityPolicy=1, JVM explicitly checks that euid=0:

static int prio_init() {
  if (ThreadPriorityPolicy == 1) {
    // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1
    // if effective uid is not root. Perhaps, a more elegant way of doing
    // this is to test CAP_SYS_NICE capability, but that will require libcap.so
    if (geteuid() != 0) {
      if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) {
        warning("-XX:ThreadPriorityPolicy requires root privilege on Linux");
      }
      ThreadPriorityPolicy = 0;
    }
  }

Note a bug (or backdoor) in the above code: if you set ThreadPriorityPolicy to something other than 0 or 1, euid check will be skipped, but the application will be still allowed to use priorities above normal. Cassandra uses this backdoor.

As a result of JEP 245 JDK 9 improved command line argument validation, and therefore ThreadPriorityPolicy does not accept values other than 0 or 1 anymore.

How to fix

Edit %CASSANDRA_HOME%/conf/jvm.options file:

  • If you run Cassandra under root on Linux,
    replace -XX:ThreadPriorityPolicy=42 with -XX:ThreadPriorityPolicy=1
  • Otherwise remove -XX:ThreadPriorityPolicy=42 line altogether.
like image 91
apangin Avatar answered Nov 10 '22 23:11

apangin


As the exception message is already telling you, the ThreadPriorityPolicy must be between 0 and 1:

intx ThreadPriorityPolicy=42 is outside the allowed range [ 0 ... 1 ]

Did you use Gateling? Than this might help you: https://github.com/gatling/gatling/issues/2950 (issue is resolved since Gatling 2.2).

It might be also worth checking if on your OS this setting makes sense at all. The meaning of this setting is somewhat like this:

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.

like image 1
TobiSH Avatar answered Nov 10 '22 23:11

TobiSH


If there is no $CASSANDRA_HOME setup as it was not a source install, then it can likely be under /usr/local/etc/cassandra

janani@janani-C02Z78CMLVDQ fievel % find / -name jvm.options
find: /usr/sbin/authserver: Permission denied
/usr/local/etc/cassandra/jvm.options

In my local, it was not under cassandra install path.

janani@janani-C02Z78CMLVDQ fievel % brew --prefix cassandra
/usr/local/opt/cassandra
janani@janani-C02Z78CMLVDQ fievel % ls /usr/local/opt/cassandra
CHANGES.txt         LICENSE.txt         NOTICE.txt          homebrew.mxcl.cassandra.plist   share
INSTALL_RECEIPT.json        NEWS.txt            bin             libexec
janani@janani-C02Z78CMLVDQ fievel % find /usr/local/opt/cassandra -name jvm.options
janani@janani-C02Z78CMLVDQ fievel % 
like image 1
Janani Narayanan Avatar answered Nov 10 '22 23:11

Janani Narayanan