yu.pitomets
yu.pitomets

Reputation: 1840

Getting AccessDeniedException when running embedded cassandra with Azul jdk 11

I am trying to run embedded Cassandra using cassandra-unit library in Azul JDK 11 with Gradle project and getting following AccessDenindException. I've checked the permissions of the build folder it is not readonly and there are some files already. Don't have anything else in the project which might causing the issue.

org.apache.cassandra.io.FSWriteError: java.nio.file.AccessDeniedException: build\embeddedCassandra\commitlog\CommitLog-6-1642719269564.log
    at org.apache.cassandra.io.util.FileUtils.deleteWithConfirm(FileUtils.java:143)
    at org.apache.cassandra.io.util.FileUtils.deleteWithConfirm(FileUtils.java:160)
    at org.apache.cassandra.db.commitlog.CommitLogSegment.discard(CommitLogSegment.java:409)

Java class

EmbeddedCassandraServerHelper.startEmbeddedCassandra();

build.gradle

testCompile 'org.cassandraunit:cassandra-unit:4.3.1.0'
testCompile 'com.datastax.oss:java-driver-core:4.13.0'

Upvotes: 2

Views: 1252

Answers (2)

T. Huber
T. Huber

Reputation: 1

Check the test dependency tree for version downgrades with gradle dependencies. My Apache Cassandra and Java Native Access libs were getting downgraded by Spring Boot 2.2. Fixing the JNA version took care of the AccessDeniedException error in Windows.

Additionally, CassandraUnit uses a JDK-internal Cleaner class that is restricted in Java 11. You can add a JVM arg in the test task(s) to make it available again.

The relevant build.gradle snippets are shown below.

dependencies {
    ...
    testImplementation 'org.cassandraunit:cassandra-unit:4.3.1.0'
    testImplementation 'com.datastax.oss:java-driver-core:4.11.3'
    testImplementation 'org.apache.cassandra:cassandra-all:4.0.8' // override 3.x from spring-data-cassandra
    testImplementation 'net.java.dev.jna:jna:5.13.0'              // override 4.5 from spring-boot-dependencies
}
tasks.withType(Test) {
    // allow cassandraunit to use jdk11 internal Cleaner
    jvmArgs '--add-exports', 'java.base/jdk.internal.ref=ALL-UNNAMED'
}

Upvotes: 0

Erick Ramirez
Erick Ramirez

Reputation: 16313

There isn't any magic that happens here since Cassandra is simply using the Java IO utilities so this is a low-level filesystem issue.

One of the things to check for is whether the existing commit logs in the directory are owned by a different user that the Cassandra process does not have access to. For example, CommitLog-6-1642719269564.log is owned by root but the C* process is running with cassandra. If so, you will need to change the file ownership. Cheers!

[UPDATE] Java 11 is only supported from Cassandra 4.x. Earlier versions of Cassandra only work with Java 8.

Upvotes: 2

Related Questions