From 03ea75894f55230a5ced0cfbd1b57c795e83a50a Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Fri, 27 Sep 2024 22:45:52 +0100 Subject: [PATCH 1/2] Enables access to FileTime private field When running tests with JDK17 we see NoClassDefFoundError when trying to instante org.apache.cassandra.Util class due caused by getSupportedMTimeGranularity trying to access a private field. This patch modified the build configuration to add a jvm option allowing that access. --- build.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/build.xml b/build.xml index 3f9fecb6c77a..bd646f9e0c4f 100644 --- a/build.xml +++ b/build.xml @@ -308,6 +308,7 @@ --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED + --add-opens java.base/java.nio.file.attribute=ALL-UNNAMED --add-opens java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED From ab675c43cb357d8d0f6d416f09bbb70e9dfc6289 Mon Sep 17 00:00:00 2001 From: Ekaterina Dimitrova Date: Mon, 10 Jun 2024 10:06:51 +0300 Subject: [PATCH 2/2] Fix tests post JDK-8210522 (rewrite reflection of modifiers field) --- test/unit/org/apache/cassandra/index/sai/SAITester.java | 3 ++- test/unit/org/apache/cassandra/index/sai/SAIUtil.java | 3 ++- .../apache/cassandra/index/sai/cql/VectorUpdateDeleteTest.java | 1 + .../cassandra/index/sai/disk/io/TrackingIndexFileUtils.java | 1 + .../cassandra/index/sai/memory/TrieMemtableIndexTest.java | 3 ++- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/test/unit/org/apache/cassandra/index/sai/SAITester.java b/test/unit/org/apache/cassandra/index/sai/SAITester.java index d1d46d1f7c18..ce82c9fafd66 100644 --- a/test/unit/org/apache/cassandra/index/sai/SAITester.java +++ b/test/unit/org/apache/cassandra/index/sai/SAITester.java @@ -92,6 +92,7 @@ import org.apache.cassandra.service.StorageService; import org.apache.cassandra.service.snapshot.TableSnapshot; import org.apache.cassandra.utils.FBUtilities; +import org.apache.cassandra.utils.ReflectionUtils; import org.apache.cassandra.utils.Throwables; import org.apache.lucene.codecs.CodecUtil; import org.awaitility.Awaitility; @@ -898,7 +899,7 @@ protected static void setSegmentWriteBufferSpace(final int segmentSize) throws E NamedMemoryLimiter limiter = (NamedMemoryLimiter) V1OnDiskFormat.class.getDeclaredField("SEGMENT_BUILD_MEMORY_LIMITER").get(null); Field limitBytes = limiter.getClass().getDeclaredField("limitBytes"); limitBytes.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); + Field modifiersField = ReflectionUtils.getField(Field.class, "modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(limitBytes, limitBytes.getModifiers() & ~Modifier.FINAL); limitBytes.set(limiter, segmentSize); diff --git a/test/unit/org/apache/cassandra/index/sai/SAIUtil.java b/test/unit/org/apache/cassandra/index/sai/SAIUtil.java index 8f56a0f4ca9b..f7580332077c 100644 --- a/test/unit/org/apache/cassandra/index/sai/SAIUtil.java +++ b/test/unit/org/apache/cassandra/index/sai/SAIUtil.java @@ -21,6 +21,7 @@ import java.lang.reflect.Field; import org.apache.cassandra.index.sai.disk.format.Version; +import org.apache.cassandra.utils.ReflectionUtils; public class SAIUtil { @@ -31,7 +32,7 @@ public static void setLatestVersion(Version version) { latest = Version.class.getDeclaredField("LATEST"); latest.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); + Field modifiersField = ReflectionUtils.getField(Field.class, "modifiers"); modifiersField.setAccessible(true); latest.set(null, version); } diff --git a/test/unit/org/apache/cassandra/index/sai/cql/VectorUpdateDeleteTest.java b/test/unit/org/apache/cassandra/index/sai/cql/VectorUpdateDeleteTest.java index 5b74719c87fb..97f4bc5ef2f3 100644 --- a/test/unit/org/apache/cassandra/index/sai/cql/VectorUpdateDeleteTest.java +++ b/test/unit/org/apache/cassandra/index/sai/cql/VectorUpdateDeleteTest.java @@ -34,6 +34,7 @@ import org.apache.cassandra.index.sai.disk.format.Version; import org.apache.cassandra.index.sai.disk.vector.VectorMemtableIndex; import org.apache.cassandra.index.sai.plan.QueryController; +import org.apache.cassandra.utils.ReflectionUtils; import static org.apache.cassandra.index.sai.cql.VectorTypeTest.assertContainsInt; import static org.apache.cassandra.index.sai.disk.vector.CassandraOnHeapGraph.MIN_PQ_ROWS; diff --git a/test/unit/org/apache/cassandra/index/sai/disk/io/TrackingIndexFileUtils.java b/test/unit/org/apache/cassandra/index/sai/disk/io/TrackingIndexFileUtils.java index be9bca5c3300..53ed1295e899 100644 --- a/test/unit/org/apache/cassandra/index/sai/disk/io/TrackingIndexFileUtils.java +++ b/test/unit/org/apache/cassandra/index/sai/disk/io/TrackingIndexFileUtils.java @@ -29,6 +29,7 @@ import org.apache.cassandra.io.util.FileHandle; import org.apache.cassandra.io.util.SequentialWriterOption; +import org.apache.cassandra.utils.ReflectionUtils; public class TrackingIndexFileUtils extends IndexFileUtils { diff --git a/test/unit/org/apache/cassandra/index/sai/memory/TrieMemtableIndexTest.java b/test/unit/org/apache/cassandra/index/sai/memory/TrieMemtableIndexTest.java index b6995a64ba88..8184bea22c8c 100644 --- a/test/unit/org/apache/cassandra/index/sai/memory/TrieMemtableIndexTest.java +++ b/test/unit/org/apache/cassandra/index/sai/memory/TrieMemtableIndexTest.java @@ -67,6 +67,7 @@ import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.Pair; +import org.apache.cassandra.utils.ReflectionUtils; import org.apache.cassandra.utils.bytecomparable.ByteComparable; import org.apache.cassandra.utils.bytecomparable.ByteSource; import org.apache.cassandra.utils.concurrent.OpOrder; @@ -364,7 +365,7 @@ private void setTrieMemtableBufferType(final BufferType newBufferType) throws Ex { Field bufferType = TrieMemtable.class.getDeclaredField("BUFFER_TYPE"); bufferType.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); + Field modifiersField = ReflectionUtils.getField(Field.class, "modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(bufferType, bufferType.getModifiers() & ~Modifier.FINAL); bufferType.set(null, newBufferType);