This is an automated email from the ASF dual-hosted git repository.
edimitrova pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new fe8a6eb70f CASSANDRA-18180 Fix bulkLoaderSuccessfullyStreamsOverSsl
fails with ClassCastException on JDK17
fe8a6eb70f is described below
commit fe8a6eb70f35b5404b15303f314023ce8d08042f
Author: Daniel Jatnieks <[email protected]>
AuthorDate: Wed Apr 19 18:53:07 2023 -0700
CASSANDRA-18180 Fix bulkLoaderSuccessfullyStreamsOverSsl fails with
ClassCastException on JDK17
Fix ClassCastException from jdk GaloisCounterMode when using JDK17 provider
Add javac exports to build.xml for java.base/jdk.internal.ref and
java.base/sun.nio.ch
Replace checktestnameshelper ant task in build.xml with _check-test-names
java target to be able to pass jvm args to TestNameCheckTask
patch by Dan Janieks; revewed by Ekaterina Dimitrova and Andres de la Pena
for CASSANDRA-18180
---
CHANGES.txt | 1 +
build.xml | 36 ++++++++------
.../org/apache/cassandra/utils/MerkleTree.java | 6 +--
.../org/apache/cassandra/utils/concurrent/Ref.java | 55 ++++++++++++++++++++++
.../apache/cassandra/utils/memory/BufferPool.java | 31 ++++++++++--
.../apache/cassandra/utils/memory/MemoryUtil.java | 2 +
.../cassandra/anttasks/TestNameCheckTask.java | 5 ++
7 files changed, 114 insertions(+), 22 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 1fb6970f16..2fc9df8995 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
5.0
+ * Fix ClassCastException from jdk GaloisCounterMode when using JDK17
provider (CASSANDRA-18180)
* Drop JDK8, add JDK17 (CASSANDRA-18255)
* Remove WaitingOnFreeMemtableSpace and DroppedMutations metrics
(CASSANDRA-18298)
* Upgrade Jamm version to 0.4.0 (CASSANDRA-17884, CASSANDRA-16304,
CASSANDRA-18329)
diff --git a/build.xml b/build.xml
index 80c8902f1e..eb221855ad 100644
--- a/build.xml
+++ b/build.xml
@@ -305,7 +305,8 @@
<!-- needed to compile org.apache.cassandra.utils.JMXServerUtils -->
<!-- needed to compile org.apache.cassandra.distributed.impl.Instance-->
- <property name="jdk11plus-javac-exports" value="--add-exports
java.rmi/sun.rmi.registry=ALL-UNNAMED --add-exports
java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED" />
+ <!-- needed to compile org.apache.cassandra.utils.memory.BufferPool -->
+ <property name="jdk11plus-javac-exports" value="--add-exports
java.rmi/sun.rmi.registry=ALL-UNNAMED --add-exports
java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED --add-exports
java.base/jdk.internal.ref=ALL-UNNAMED --add-exports
java.base/sun.nio.ch=ALL-UNNAMED" />
<!--
Add all the dependencies.
@@ -1002,7 +1003,7 @@
<target name="build-test"
depends="_main-jar,stress-build-test,fqltool-build,resolver-dist-lib,simulator-jars"
description="Compile test classes">
<antcall target="_build-test"/>
- <checktestnameshelper/>
+ <antcall target="_check-test-names"/>
</target>
<target name="_build-test">
@@ -1020,6 +1021,8 @@
<pathelement location="${fqltool.build.classes}"/>
</classpath>
<compilerarg value="-XDignore.symbol.file"/>
+ <!-- needed to compile org.apache.cassandra.utils.memory.BufferPoolTest
-->
+ <compilerarg line="${jdk11plus-javac-exports}"/>
<src path="${test.anttasks.src}"/>
<src path="${test.unit.src}"/>
<src path="${test.long.src}"/>
@@ -1040,17 +1043,19 @@
</copy>
</target>
- <macrodef name="checktestnameshelper">
- <sequential>
- <taskdef name="test-name-check_"
classname="org.apache.cassandra.anttasks.TestNameCheckTask"
classpath="${test.classes}">
- <classpath>
- <path refid="cassandra.classpath.test"/>
- <path location="${fqltool.build.classes}"/>
- </classpath>
- </taskdef>
- <test-name-check_/>
- </sequential>
- </macrodef>
+ <target name="_check-test-names">
+ <java taskname="check-test-names" fork="true" failonerror="yes"
classname="org.apache.cassandra.anttasks.TestNameCheckTask"
classpath="${test.classes}">
+ <classpath>
+ <path refid="cassandra.classpath" />
+ <pathelement location="${test.classes}"/>
+ <pathelement location="${fqltool.build.classes}" />
+ <fileset dir="${test.lib}">
+ <include name="**/*.jar" />
+ </fileset>
+ </classpath>
+ <jvmarg line="${java-jvmargs}"/>
+ </java>
+ </target>
<!-- Run tests separately and report errors after and generate a junit
report -->
<macrodef name="testhelper">
@@ -1873,7 +1878,10 @@
<echo file=".idea/compiler.xml"><![CDATA[<?xml version="1.0"
encoding="UTF-8"?>
<project version="4">
<component name="JavacSettings">
- <option name="ADDITIONAL_OPTIONS_STRING" value="--add-exports
java.rmi/sun.rmi.registry=ALL-UNNAMED --add-exports
java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED" />
+ <option name="ADDITIONAL_OPTIONS_STRING" value="--add-exports
java.rmi/sun.rmi.registry=ALL-UNNAMED
+ --add-exports
java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED
+ --add-exports
java.base/jdk.internal.ref=ALL-UNNAMED
+ --add-exports
java.base/sun.nio.ch=ALL-UNNAMED" />
</component>
</project>]]></echo>
</target>
diff --git a/src/java/org/apache/cassandra/utils/MerkleTree.java
b/src/java/org/apache/cassandra/utils/MerkleTree.java
index e4d21d2cad..0cdb74e742 100644
--- a/src/java/org/apache/cassandra/utils/MerkleTree.java
+++ b/src/java/org/apache/cassandra/utils/MerkleTree.java
@@ -741,7 +741,7 @@ public class MerkleTree
logger.debug("Allocating direct buffer of size {} for an off-heap
merkle tree", size);
ByteBuffer buffer = ByteBuffer.allocateDirect(size);
if (Ref.DEBUG_ENABLED)
- MemoryUtil.setAttachment(buffer, new Ref<>(null, null));
+ MemoryUtil.setAttachment(buffer, new Ref.DirectBufferRef<>(null,
null));
return buffer;
}
@@ -976,8 +976,8 @@ public class MerkleTree
void release()
{
Object attachment = MemoryUtil.getAttachment(buffer);
- if (attachment instanceof Ref)
- ((Ref) attachment).release();
+ if (attachment instanceof Ref.DirectBufferRef)
+ ((Ref.DirectBufferRef) attachment).release();
FileUtils.clean(buffer);
}
diff --git a/src/java/org/apache/cassandra/utils/concurrent/Ref.java
b/src/java/org/apache/cassandra/utils/concurrent/Ref.java
index 1e27dc79c2..706a982f59 100644
--- a/src/java/org/apache/cassandra/utils/concurrent/Ref.java
+++ b/src/java/org/apache/cassandra/utils/concurrent/Ref.java
@@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import jdk.internal.ref.Cleaner;
import org.apache.cassandra.concurrent.Shutdownable;
import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.Keyspace;
@@ -48,6 +49,7 @@ import org.apache.cassandra.utils.ExecutorUtils;
import org.apache.cassandra.utils.NoSpamLogger;
import org.apache.cassandra.utils.Pair;
import org.apache.cassandra.utils.Shared;
+import sun.nio.ch.DirectBuffer;
import org.cliffc.high_scale_lib.NonBlockingHashMap;
@@ -739,4 +741,57 @@ public final class Ref<T> implements RefCounted<T>
{
ExecutorUtils.shutdownNowAndWait(timeout, unit, EXEC,
STRONG_LEAK_DETECTOR);
}
+
+ /**
+ * A version of {@link Ref} for objects that implement {@link
DirectBuffer}.
+ */
+ public static final class DirectBufferRef<T extends DirectBuffer>
implements RefCounted<T>, DirectBuffer
+ {
+ private final Ref<T> wrappedRef;
+
+ public DirectBufferRef(T referent, Tidy tidy)
+ {
+ wrappedRef = new Ref<>(referent, tidy);
+ }
+
+ @Override
+ public long address()
+ {
+ return wrappedRef.referent != null ? wrappedRef.referent.address()
: 0;
+ }
+
+ @Override
+ public Object attachment()
+ {
+ return wrappedRef.referent != null ?
wrappedRef.referent.attachment() : null;
+ }
+
+ @Override
+ public Cleaner cleaner()
+ {
+ return wrappedRef.referent != null ? wrappedRef.referent.cleaner()
: null;
+ }
+
+ @Override
+ public Ref<T> tryRef()
+ {
+ return wrappedRef.tryRef();
+ }
+
+ @Override
+ public Ref<T> ref()
+ {
+ return wrappedRef.ref();
+ }
+
+ public void release()
+ {
+ wrappedRef.release();
+ }
+
+ public T get()
+ {
+ return wrappedRef.get();
+ }
+ }
}
diff --git a/src/java/org/apache/cassandra/utils/memory/BufferPool.java
b/src/java/org/apache/cassandra/utils/memory/BufferPool.java
index b9009bcee1..cddfc8fe61 100644
--- a/src/java/org/apache/cassandra/utils/memory/BufferPool.java
+++ b/src/java/org/apache/cassandra/utils/memory/BufferPool.java
@@ -37,6 +37,7 @@ import java.util.function.Supplier;
import com.google.common.annotations.VisibleForTesting;
+import jdk.internal.ref.Cleaner;
import net.nicoulaj.compilecommand.annotations.Inline;
import org.apache.cassandra.concurrent.Shutdownable;
import org.slf4j.Logger;
@@ -50,6 +51,8 @@ import org.apache.cassandra.metrics.BufferPoolMetrics;
import org.apache.cassandra.utils.NoSpamLogger;
import org.apache.cassandra.utils.Shared;
import org.apache.cassandra.utils.concurrent.Ref;
+import org.apache.cassandra.utils.concurrent.Ref.DirectBufferRef;
+import sun.nio.ch.DirectBuffer;
import static com.google.common.collect.ImmutableList.of;
import static
org.apache.cassandra.concurrent.ExecutorFactory.Global.executorFactory;
@@ -1129,7 +1132,7 @@ public class BufferPool
* When we reiceve a release request we work out the position by comparing
the buffer
* address to our base address and we simply release the units.
*/
- final static class Chunk
+ final static class Chunk implements DirectBuffer
{
enum Status
{
@@ -1184,6 +1187,24 @@ public class BufferPool
this.freeSlots = slab.capacity() == 0 ? 0L : -1L;
}
+ @Override
+ public long address()
+ {
+ return baseAddress;
+ }
+
+ @Override
+ public Object attachment()
+ {
+ return MemoryUtil.getAttachment(slab);
+ }
+
+ @Override
+ public Cleaner cleaner()
+ {
+ return null;
+ }
+
/**
* Acquire the chunk for future allocations: set the owner
*/
@@ -1301,8 +1322,8 @@ public class BufferPool
if (attachment instanceof Chunk)
return (Chunk) attachment;
- if (attachment instanceof Ref)
- return ((Ref<Chunk>) attachment).get();
+ if (attachment instanceof DirectBufferRef)
+ return ((DirectBufferRef<Chunk>) attachment).get();
return null;
}
@@ -1310,7 +1331,7 @@ public class BufferPool
void setAttachment(ByteBuffer buffer)
{
if (Ref.DEBUG_ENABLED)
- MemoryUtil.setAttachment(buffer, new Ref<>(this, null));
+ MemoryUtil.setAttachment(buffer, new DirectBufferRef<>(this,
null));
else
MemoryUtil.setAttachment(buffer, this);
}
@@ -1322,7 +1343,7 @@ public class BufferPool
return false;
if (Ref.DEBUG_ENABLED)
- ((Ref<Chunk>) attachment).release();
+ ((DirectBufferRef<Chunk>) attachment).release();
return true;
}
diff --git a/src/java/org/apache/cassandra/utils/memory/MemoryUtil.java
b/src/java/org/apache/cassandra/utils/memory/MemoryUtil.java
index e194962756..4a9f41409a 100644
--- a/src/java/org/apache/cassandra/utils/memory/MemoryUtil.java
+++ b/src/java/org/apache/cassandra/utils/memory/MemoryUtil.java
@@ -207,6 +207,8 @@ public abstract class MemoryUtil
return unsafe.getObject(instance,
DIRECT_BYTE_BUFFER_ATTACHMENT_OFFSET);
}
+ // Note: If encryption is used, the Object attached must implement
sun.nio.ch.DirectBuffer
+ // @see CASSANDRA-18081
public static void setAttachment(ByteBuffer instance, Object next)
{
assert instance.getClass() == DIRECT_BYTE_BUFFER_CLASS;
diff --git a/test/anttasks/org/apache/cassandra/anttasks/TestNameCheckTask.java
b/test/anttasks/org/apache/cassandra/anttasks/TestNameCheckTask.java
index a5222261f2..0b16f5e440 100644
--- a/test/anttasks/org/apache/cassandra/anttasks/TestNameCheckTask.java
+++ b/test/anttasks/org/apache/cassandra/anttasks/TestNameCheckTask.java
@@ -45,6 +45,11 @@ public class TestNameCheckTask extends Task
{
}
+ public static void main(String[] args)
+ {
+ new TestNameCheckTask().execute();
+ }
+
@Override
public void execute() throws BuildException
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]