From ed1e9e2339d2a01073da01d3b88f4d3420099169 Mon Sep 17 00:00:00 2001 From: Ruslan Fomkin Date: Wed, 19 Nov 2025 12:14:35 +0100 Subject: [PATCH 1/6] CNDB-15608 fix lint issues in affected files While working on CNDB-15608, IntelliJ lint complains were noticed, which are not related to the actual changes in the patch port. Thus I fix them in this separate commit to avoid unnecessary noise while working on the actual patch port. The changes include: - Remove unused imports - Remove unnecessary boilerplate code for unnamed Comparator construction - Use the formatter of the logger instead of string concatenation - Use method instead of lambda - Remove unnecessary suppression of resource warnings - Simplify Boolean conditions - Remove unnecessary modifiers in interfaces - Fix typos - Fixing links in javadoc comments - Add static modifier to nested classes - Remove class fields when not used - Remove unnecessary throws in method signatures - Use final when recommended - Remove unused method arguments - Replace single char strings with chars - Remove unnecessary null variable initialization - Replace assert true with assert equal - Change order of assert arguments to have expected value first - Remove unnecessary explicit casting --- .../cassandra/db/marshal/AbstractType.java | 19 +++-------- .../cassandra/index/sai/IndexContext.java | 4 +-- .../cassandra/index/sai/SSTableContext.java | 1 - .../index/sai/StorageAttachedIndexGroup.java | 8 ++--- .../index/sai/disk/PerSSTableWriter.java | 4 +-- .../sai/disk/format/IndexDescriptor.java | 2 +- .../index/sai/disk/format/OnDiskFormat.java | 33 ++++++++++--------- .../v1/PartitionAwarePrimaryKeyFactory.java | 2 +- .../disk/v1/PartitionAwarePrimaryKeyMap.java | 14 +++----- .../index/sai/disk/v1/PerIndexFiles.java | 1 - .../index/sai/disk/v1/V1OnDiskFormat.java | 2 +- .../disk/v2/RowAwarePrimaryKeyFactory.java | 2 +- .../sai/disk/v2/RowAwarePrimaryKeyMap.java | 12 ++----- .../v2/sortedterms/SortedTermsReader.java | 2 +- .../v2/sortedterms/SortedTermsWriter.java | 2 -- .../apache/cassandra/io/sstable/SSTable.java | 4 +-- .../AbstractTrieMemoryIndexBenchmark.java | 2 +- .../apache/cassandra/index/sai/SAITester.java | 14 ++++---- .../index/sai/cql/NativeIndexDDLTest.java | 2 +- .../index/sai/disk/NodeStartupTest.java | 6 ++-- .../index/sai/disk/v1/SegmentFlushTest.java | 2 +- .../disk/v1/bitpack/NumericValuesTest.java | 2 +- .../disk/v2/sortedterms/SortedTermsTest.java | 2 +- .../sai/utils/AbstractPrimaryKeyTest.java | 6 ++-- .../index/sai/utils/SaiRandomizedTest.java | 4 +-- 25 files changed, 63 insertions(+), 89 deletions(-) diff --git a/src/java/org/apache/cassandra/db/marshal/AbstractType.java b/src/java/org/apache/cassandra/db/marshal/AbstractType.java index 69fb679ffef0..537335c8a29c 100644 --- a/src/java/org/apache/cassandra/db/marshal/AbstractType.java +++ b/src/java/org/apache/cassandra/db/marshal/AbstractType.java @@ -117,21 +117,10 @@ protected AbstractType(ComparisonType comparisonType, boolean isMultiCell, List< throw new IllegalStateException(); } - comparatorSet = new ValueComparators(new Comparator<>() - { - @Override - public int compare(byte[] l, byte[] r) - { - return AbstractType.this.compare(l, ByteArrayAccessor.instance, r, ByteArrayAccessor.instance); - } - }, new Comparator<>() - { - @Override - public int compare(ByteBuffer l, ByteBuffer r) - { - return AbstractType.this.compare(l, ByteBufferAccessor.instance, r, ByteBufferAccessor.instance); - } - }); + comparatorSet = new ValueComparators((l, r) -> + AbstractType.this.compare(l, ByteArrayAccessor.instance, r, ByteArrayAccessor.instance), + (l, r) -> + AbstractType.this.compare(l, ByteBufferAccessor.instance, r, ByteBufferAccessor.instance)); this.isMultiCell = isMultiCell; diff --git a/src/java/org/apache/cassandra/index/sai/IndexContext.java b/src/java/org/apache/cassandra/index/sai/IndexContext.java index 696b58bf9eb4..e88f7e6c791b 100644 --- a/src/java/org/apache/cassandra/index/sai/IndexContext.java +++ b/src/java/org/apache/cassandra/index/sai/IndexContext.java @@ -614,7 +614,7 @@ public int getIntOption(String name, int defaultValue) } catch (NumberFormatException e) { - logger.error("Failed to parse index configuration " + name + " = " + value + " as integer"); + logger.error("Failed to parse index configuration {} = {} as integer", name, value); return defaultValue; } } @@ -1003,7 +1003,7 @@ public long indexFileCacheSize() public IndexFeatureSet indexFeatureSet() { IndexFeatureSet.Accumulator accumulator = new IndexFeatureSet.Accumulator(version); - getView().getIndexes().stream().map(SSTableIndex::indexFeatureSet).forEach(set -> accumulator.accumulate(set)); + getView().getIndexes().stream().map(SSTableIndex::indexFeatureSet).forEach(accumulator::accumulate); return accumulator.complete(); } } diff --git a/src/java/org/apache/cassandra/index/sai/SSTableContext.java b/src/java/org/apache/cassandra/index/sai/SSTableContext.java index e18a697dcddd..2a272dae54aa 100644 --- a/src/java/org/apache/cassandra/index/sai/SSTableContext.java +++ b/src/java/org/apache/cassandra/index/sai/SSTableContext.java @@ -65,7 +65,6 @@ private SSTableContext(SSTableContext copy) this.primaryKeyMapFactory = copy.primaryKeyMapFactory; } - @SuppressWarnings("resource") public static SSTableContext create(SSTableReader sstable, IndexComponents.ForRead perSSTableComponents) { var onDiskFormat = perSSTableComponents.onDiskFormat(); diff --git a/src/java/org/apache/cassandra/index/sai/StorageAttachedIndexGroup.java b/src/java/org/apache/cassandra/index/sai/StorageAttachedIndexGroup.java index 512250bbd6a0..16ba4dfe9b2a 100644 --- a/src/java/org/apache/cassandra/index/sai/StorageAttachedIndexGroup.java +++ b/src/java/org/apache/cassandra/index/sai/StorageAttachedIndexGroup.java @@ -246,7 +246,7 @@ public void rangeTombstone(RangeTombstone tombstone) private void forEach(Consumer action) { - indexers.forEach(action::accept); + indexers.forEach(action); } }; } @@ -336,7 +336,7 @@ public void handleNotification(INotification notification, Object sender) // Avoid validation for index files just written following Memtable flush. ZCS streaming should // validate index checksum. - boolean validate = notice.fromStreaming() || !notice.memtable().isPresent(); + boolean validate = notice.fromStreaming() || notice.memtable().isEmpty(); onSSTableChanged(Collections.emptySet(), notice.added, indices, validate); } else if (notification instanceof SSTableListChangedNotification) @@ -436,7 +436,7 @@ public int totalIndexBuildsInProgress() */ public int totalQueryableIndexCount() { - return (int) indices.stream().filter(i -> baseCfs.indexManager.isIndexQueryable(i)).count(); + return (int) indices.stream().filter(baseCfs.indexManager::isIndexQueryable).count(); } /** @@ -513,7 +513,7 @@ public void unsafeReload() public void reset() { contextManager.clear(); - indices.forEach(index -> index.makeIndexNonQueryable()); + indices.forEach(StorageAttachedIndex::makeIndexNonQueryable); onSSTableChanged(baseCfs.getLiveSSTables(), Collections.emptySet(), indices, false); } } diff --git a/src/java/org/apache/cassandra/index/sai/disk/PerSSTableWriter.java b/src/java/org/apache/cassandra/index/sai/disk/PerSSTableWriter.java index a14357eaa3b5..fe03644324c1 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/PerSSTableWriter.java +++ b/src/java/org/apache/cassandra/index/sai/disk/PerSSTableWriter.java @@ -21,8 +21,6 @@ import com.google.common.base.Stopwatch; -import org.apache.cassandra.db.DecoratedKey; -import org.apache.cassandra.db.rows.Unfiltered; import org.apache.cassandra.index.sai.utils.PrimaryKey; /** @@ -30,7 +28,7 @@ */ public interface PerSSTableWriter { - public static final PerSSTableWriter NONE = (key) -> {}; + PerSSTableWriter NONE = (key) -> {}; default void startPartition(long position) throws IOException {} diff --git a/src/java/org/apache/cassandra/index/sai/disk/format/IndexDescriptor.java b/src/java/org/apache/cassandra/index/sai/disk/format/IndexDescriptor.java index a76eedb2bc26..613042ee44f4 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/format/IndexDescriptor.java +++ b/src/java/org/apache/cassandra/index/sai/disk/format/IndexDescriptor.java @@ -522,7 +522,7 @@ public void markComplete() throws IOException { addOrGet(completionMarkerComponent()).createEmpty(); sealed = true; - // Until this call, the group is not attached to the parent. This create the link. + // Until this call, the group is not attached to the parent. This creates the link. updateParentLink(this); } diff --git a/src/java/org/apache/cassandra/index/sai/disk/format/OnDiskFormat.java b/src/java/org/apache/cassandra/index/sai/disk/format/OnDiskFormat.java index 611eab5e37b5..7fc45021aa10 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/format/OnDiskFormat.java +++ b/src/java/org/apache/cassandra/index/sai/disk/format/OnDiskFormat.java @@ -28,6 +28,7 @@ import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.index.sai.IndexContext; import org.apache.cassandra.index.sai.SSTableContext; +import org.apache.cassandra.index.sai.SSTableIndex; import org.apache.cassandra.index.sai.StorageAttachedIndex; import org.apache.cassandra.index.sai.disk.PerIndexWriter; import org.apache.cassandra.index.sai.disk.PerSSTableWriter; @@ -73,7 +74,7 @@ public interface OnDiskFormat * * @return the index feature set */ - public IndexFeatureSet indexFeatureSet(); + IndexFeatureSet indexFeatureSet(); /** * Returns the {@link PrimaryKey.Factory} for the on-disk format @@ -81,7 +82,7 @@ public interface OnDiskFormat * @param comparator * @return the primary key factory */ - public PrimaryKey.Factory newPrimaryKeyFactory(ClusteringComparator comparator); + PrimaryKey.Factory newPrimaryKeyFactory(ClusteringComparator comparator); /** * Returns a {@link PrimaryKeyMap.Factory} for the SSTable @@ -92,10 +93,10 @@ public interface OnDiskFormat * @return a {@link PrimaryKeyMap.Factory} for the SSTable * @throws IOException */ - public PrimaryKeyMap.Factory newPrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComponents, PrimaryKey.Factory primaryKeyFactory, SSTableReader sstable) throws IOException; + PrimaryKeyMap.Factory newPrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComponents, PrimaryKey.Factory primaryKeyFactory, SSTableReader sstable) throws IOException; /** - * Create a new {@link SearchableIndex} for an on-disk index. This is held by the {@SSTableIndex} + * Create a new {@link SearchableIndex} for an on-disk index. This is held by the {@link SSTableIndex} * and shared between queries. * * @param sstableContext The {@link SSTableContext} holding the per-SSTable information for the index @@ -103,7 +104,7 @@ public interface OnDiskFormat * also link to the underlying {@link IndexContext} for the index). * @return the created {@link SearchableIndex}. */ - public SearchableIndex newSearchableIndex(SSTableContext sstableContext, IndexComponents.ForRead perIndexComponents); + SearchableIndex newSearchableIndex(SSTableContext sstableContext, IndexComponents.ForRead perIndexComponents); IndexSearcher newIndexSearcher(SSTableContext sstableContext, IndexContext indexContext, @@ -117,7 +118,7 @@ IndexSearcher newIndexSearcher(SSTableContext sstableContext, * @return The {@link PerSSTableWriter} to write the per-SSTable on-disk components * @throws IOException */ - public PerSSTableWriter newPerSSTableWriter(IndexDescriptor indexDescriptor) throws IOException; + PerSSTableWriter newPerSSTableWriter(IndexDescriptor indexDescriptor) throws IOException; /** * Create a new writer for the per-index on-disk components of an index. The {@link LifecycleNewTracker} @@ -132,10 +133,10 @@ IndexSearcher newIndexSearcher(SSTableContext sstableContext, * @param keyCount * @return The {@link PerIndexWriter} that will write the per-index on-disk components */ - public PerIndexWriter newPerIndexWriter(StorageAttachedIndex index, - IndexDescriptor indexDescriptor, - LifecycleNewTracker tracker, - RowMapping rowMapping, long keyCount); + PerIndexWriter newPerIndexWriter(StorageAttachedIndex index, + IndexDescriptor indexDescriptor, + LifecycleNewTracker tracker, + RowMapping rowMapping, long keyCount); /** * Validate the provided on-disk components (that must be for this version). @@ -154,7 +155,7 @@ public PerIndexWriter newPerIndexWriter(StorageAttachedIndex index, * * @return The set of {@link IndexComponentType} for the per-SSTable index */ - public Set perSSTableComponentTypes(); + Set perSSTableComponentTypes(); /** * Returns the set of {@link IndexComponentType} for the per-index part of an index. @@ -164,12 +165,12 @@ public PerIndexWriter newPerIndexWriter(StorageAttachedIndex index, * @param indexContext The {@link IndexContext} for the index * @return The set of {@link IndexComponentType} for the per-index index */ - default public Set perIndexComponentTypes(IndexContext indexContext) + default Set perIndexComponentTypes(IndexContext indexContext) { return perIndexComponentTypes(indexContext.getValidator()); } - public Set perIndexComponentTypes(AbstractType validator); + Set perIndexComponentTypes(AbstractType validator); /** * Return the number of open per-SSTable files that can be open during a query. @@ -178,7 +179,7 @@ default public Set perIndexComponentTypes(IndexContext index * * @return The number of open per-SSTable files */ - public int openFilesPerSSTable(); + int openFilesPerSSTable(); /** * Return the number of open per-index files that can be open during a query. @@ -188,7 +189,7 @@ default public Set perIndexComponentTypes(IndexContext index * @param indexContext The {@link IndexContext} for the index * @return The number of open per-index files */ - public int openFilesPerIndex(IndexContext indexContext); + int openFilesPerIndex(IndexContext indexContext); /** * Return the {@link ByteOrder} for the given {@link IndexComponentType} and {@link IndexContext}. @@ -197,7 +198,7 @@ default public Set perIndexComponentTypes(IndexContext index * @param context - The {@link IndexContext} for the index * @return The {@link ByteOrder} for the file associated with the {@link IndexComponentType} */ - public ByteOrder byteOrderFor(IndexComponentType component, IndexContext context); + ByteOrder byteOrderFor(IndexComponentType component, IndexContext context); /** * Encode the given {@link ByteBuffer} into a {@link ByteComparable} object based on the provided {@link AbstractType} diff --git a/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyFactory.java b/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyFactory.java index 80eac7ce0cb8..6d7f9f535a23 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyFactory.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyFactory.java @@ -56,7 +56,7 @@ public PrimaryKey create(DecoratedKey partitionKey, Clustering clustering) return new PartitionAwarePrimaryKey(partitionKey.getToken(), partitionKey, null); } - private class PartitionAwarePrimaryKey implements PrimaryKey + private static class PartitionAwarePrimaryKey implements PrimaryKey { private final Token token; private DecoratedKey partitionKey; diff --git a/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyMap.java b/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyMap.java index d49fae12a0a8..df780a4ee404 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyMap.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyMap.java @@ -19,7 +19,6 @@ package org.apache.cassandra.index.sai.disk.v1; import java.io.IOException; -import java.nio.ByteBuffer; import javax.annotation.concurrent.NotThreadSafe; import javax.annotation.concurrent.ThreadSafe; @@ -60,10 +59,8 @@ public class PartitionAwarePrimaryKeyMap implements PrimaryKeyMap @ThreadSafe public static class PartitionAwarePrimaryKeyMapFactory implements Factory { - private final IndexComponents.ForRead perSSTableComponents; private final LongArray.Factory tokenReaderFactory; private final LongArray.Factory offsetReaderFactory; - private final MetadataSource metadata; private final KeyFetcher keyFetcher; private final IPartitioner partitioner; private final PrimaryKey.Factory primaryKeyFactory; @@ -77,14 +74,13 @@ public PartitionAwarePrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComp { try { - this.perSSTableComponents = perSSTableComponents; - this.metadata = MetadataSource.loadMetadata(perSSTableComponents); + MetadataSource metadata = MetadataSource.loadMetadata(perSSTableComponents); IndexComponent.ForRead offsetsComponent = perSSTableComponents.get(IndexComponentType.OFFSETS_VALUES); IndexComponent.ForRead tokensComponent = perSSTableComponents.get(IndexComponentType.TOKEN_VALUES); - NumericValuesMeta offsetsMeta = new NumericValuesMeta(this.metadata.get(offsetsComponent)); - NumericValuesMeta tokensMeta = new NumericValuesMeta(this.metadata.get(tokensComponent)); + NumericValuesMeta offsetsMeta = new NumericValuesMeta(metadata.get(offsetsComponent)); + NumericValuesMeta tokensMeta = new NumericValuesMeta(metadata.get(tokensComponent)); count = tokensMeta.valueCount; token = tokensComponent.createFileHandle(); @@ -106,8 +102,8 @@ public PartitionAwarePrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComp @Override public PrimaryKeyMap newPerSSTablePrimaryKeyMap() { - final LongArray rowIdToToken = new LongArray.DeferredLongArray(() -> tokenReaderFactory.open()); - final LongArray rowIdToOffset = new LongArray.DeferredLongArray(() -> offsetReaderFactory.open()); + final LongArray rowIdToToken = new LongArray.DeferredLongArray(tokenReaderFactory::open); + final LongArray rowIdToOffset = new LongArray.DeferredLongArray(offsetReaderFactory::open); return new PartitionAwarePrimaryKeyMap(rowIdToToken, rowIdToOffset, partitioner, keyFetcher, primaryKeyFactory, sstableId); } diff --git a/src/java/org/apache/cassandra/index/sai/disk/v1/PerIndexFiles.java b/src/java/org/apache/cassandra/index/sai/disk/v1/PerIndexFiles.java index b82c23cc589d..3df29c987edf 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v1/PerIndexFiles.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v1/PerIndexFiles.java @@ -28,7 +28,6 @@ import org.apache.cassandra.index.sai.disk.format.IndexComponents; import org.apache.cassandra.index.sai.disk.format.IndexComponentType; -import org.apache.cassandra.index.sai.disk.format.Version; import org.apache.cassandra.io.util.FileHandle; import org.apache.cassandra.io.util.FileUtils; diff --git a/src/java/org/apache/cassandra/index/sai/disk/v1/V1OnDiskFormat.java b/src/java/org/apache/cassandra/index/sai/disk/v1/V1OnDiskFormat.java index 305d9e94d5c4..a5466611aa0e 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v1/V1OnDiskFormat.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v1/V1OnDiskFormat.java @@ -154,7 +154,7 @@ public PrimaryKey.Factory newPrimaryKeyFactory(ClusteringComparator comparator) } @Override - public PrimaryKeyMap.Factory newPrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComponents, PrimaryKey.Factory primaryKeyFactory, SSTableReader sstable) throws IOException + public PrimaryKeyMap.Factory newPrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComponents, PrimaryKey.Factory primaryKeyFactory, SSTableReader sstable) { return new PartitionAwarePrimaryKeyMap.PartitionAwarePrimaryKeyMapFactory(perSSTableComponents, sstable, primaryKeyFactory); } diff --git a/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyFactory.java b/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyFactory.java index 748541c476b9..cf2b0c5f8844 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyFactory.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyFactory.java @@ -75,7 +75,7 @@ PrimaryKey createWithSource(PrimaryKeyMap primaryKeyMap, long sstableRowId, Prim private class RowAwarePrimaryKey implements PrimaryKey { - private Token token; + private final Token token; private DecoratedKey partitionKey; private Clustering clustering; private Supplier primaryKeySupplier; diff --git a/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java b/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java index 5b95076e3ea5..ef95247aef9a 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java @@ -71,7 +71,6 @@ public class RowAwarePrimaryKeyMap implements PrimaryKeyMap @ThreadSafe public static class RowAwarePrimaryKeyMapFactory implements Factory { - private final IndexComponents.ForRead perSSTableComponents; private final LongArray.Factory tokenReaderFactory; private final SortedTermsReader sortedTermsReader; private final long count; @@ -89,7 +88,6 @@ public RowAwarePrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComponents { try { - this.perSSTableComponents = perSSTableComponents; MetadataSource metadataSource = MetadataSource.loadMetadata(perSSTableComponents); NumericValuesMeta tokensMeta = new NumericValuesMeta(metadataSource.get(perSSTableComponents.get(IndexComponentType.TOKEN_VALUES))); count = tokensMeta.valueCount; @@ -117,11 +115,10 @@ public RowAwarePrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComponents @Override public PrimaryKeyMap newPerSSTablePrimaryKeyMap() { - final LongArray rowIdToToken = new LongArray.DeferredLongArray(() -> tokenReaderFactory.open()); + final LongArray rowIdToToken = new LongArray.DeferredLongArray(tokenReaderFactory::open); try { return new RowAwarePrimaryKeyMap(rowIdToToken, - sortedTermsReader, sortedTermsReader.openCursor(), partitioner, primaryKeyFactory, @@ -149,7 +146,6 @@ public void close() throws IOException } private final LongArray rowIdToToken; - private final SortedTermsReader sortedTermsReader; private final SortedTermsReader.Cursor cursor; private final IPartitioner partitioner; private final RowAwarePrimaryKeyFactory primaryKeyFactory; @@ -158,7 +154,6 @@ public void close() throws IOException private final boolean hasStaticColumns; private RowAwarePrimaryKeyMap(LongArray rowIdToToken, - SortedTermsReader sortedTermsReader, SortedTermsReader.Cursor cursor, IPartitioner partitioner, RowAwarePrimaryKeyFactory primaryKeyFactory, @@ -167,7 +162,6 @@ private RowAwarePrimaryKeyMap(LongArray rowIdToToken, boolean hasStaticColumns) { this.rowIdToToken = rowIdToToken; - this.sortedTermsReader = sortedTermsReader; this.cursor = cursor; this.partitioner = partitioner; this.primaryKeyFactory = primaryKeyFactory; @@ -235,10 +229,10 @@ public long exactRowIdOrInvertedCeiling(PrimaryKey key) if (clusteringComparator.size() == 0) return skinnyExactRowIdOrInvertedCeiling(key); - long pointId = cursor.getExactPointId(v -> key.asComparableBytes(v)); + long pointId = cursor.getExactPointId(key::asComparableBytes); if (pointId >= 0) return pointId; - long ceiling = cursor.ceiling(v -> key.asComparableBytesMinPrefix(v)); + long ceiling = cursor.ceiling(key::asComparableBytesMinPrefix); // Use min value since -(Long.MIN_VALUE) - 1 == Long.MAX_VALUE. return ceiling < 0 ? Long.MIN_VALUE : -ceiling - 1; } diff --git a/src/java/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsReader.java b/src/java/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsReader.java index c7465062edfa..e0898c310e96 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsReader.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsReader.java @@ -145,7 +145,7 @@ public class Cursor implements AutoCloseable // The point id the cursor currently points to. -1 means before the first item. private long pointId = -1; - private TrieTermsDictionaryReader reader; + private final TrieTermsDictionaryReader reader; Cursor(FileHandle termsData, LongArray.Factory blockOffsetsFactory) throws IOException { diff --git a/src/java/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsWriter.java b/src/java/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsWriter.java index 97f856fe3aef..b4c52852f2c2 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsWriter.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsWriter.java @@ -73,8 +73,6 @@ public class SortedTermsWriter implements Closeable static final int TERMS_DICT_BLOCK_SIZE = 1 << TERMS_DICT_BLOCK_SHIFT; static final int TERMS_DICT_BLOCK_MASK = TERMS_DICT_BLOCK_SIZE - 1; - static final int DIRECT_MONOTONIC_BLOCK_SHIFT = 16; - private final IncrementalTrieWriter trieWriter; private final IndexOutputWriter trieOutput; private final IndexOutput termsOutput; diff --git a/src/java/org/apache/cassandra/io/sstable/SSTable.java b/src/java/org/apache/cassandra/io/sstable/SSTable.java index 08211c0f37ad..76db307576f4 100644 --- a/src/java/org/apache/cassandra/io/sstable/SSTable.java +++ b/src/java/org/apache/cassandra/io/sstable/SSTable.java @@ -341,7 +341,7 @@ public long bytesOnDisk() @Override public String toString() { - return getClass().getSimpleName() + "(" + + return getClass().getSimpleName() + '(' + "path='" + getFilename() + '\'' + ')'; } @@ -403,7 +403,7 @@ private static void rewriteTOC(Descriptor descriptor, Collection comp */ public static void writeTOC(File tocFile, Collection components, File.WriteMode writeMode) { - FileOutputStreamPlus fos = null; + FileOutputStreamPlus fos; try (PrintWriter w = new PrintWriter((fos = tocFile.newOutputStream(writeMode)))) { for (Component component : components) diff --git a/test/microbench/org/apache/cassandra/test/microbench/index/sai/memory/AbstractTrieMemoryIndexBenchmark.java b/test/microbench/org/apache/cassandra/test/microbench/index/sai/memory/AbstractTrieMemoryIndexBenchmark.java index 697c1fc8089a..d781fbf64dee 100644 --- a/test/microbench/org/apache/cassandra/test/microbench/index/sai/memory/AbstractTrieMemoryIndexBenchmark.java +++ b/test/microbench/org/apache/cassandra/test/microbench/index/sai/memory/AbstractTrieMemoryIndexBenchmark.java @@ -56,7 +56,7 @@ public abstract class AbstractTrieMemoryIndexBenchmark private static final String INTEGER_INDEX = "integer_index"; private static final int RANDOM_STRING_SIZE = 64 * 1024 * 1024; - private char[] randomChars = new char[RANDOM_STRING_SIZE]; + private final char[] randomChars = new char[RANDOM_STRING_SIZE]; protected int randomSeed; diff --git a/test/unit/org/apache/cassandra/index/sai/SAITester.java b/test/unit/org/apache/cassandra/index/sai/SAITester.java index 933c433ddc24..7ea9a45a87a0 100644 --- a/test/unit/org/apache/cassandra/index/sai/SAITester.java +++ b/test/unit/org/apache/cassandra/index/sai/SAITester.java @@ -227,7 +227,7 @@ public void corrupt(File file) throws IOException public TestRule testRules = new ResourceLeakDetector(); @Before - public void resetQueryOptimizationLevel() throws Throwable + public void resetQueryOptimizationLevel() { // Enable the optimizer by default. If there are any tests that need to disable it, they can do so explicitly. QueryController.QUERY_OPT_LEVEL = 1; @@ -235,7 +235,7 @@ public void resetQueryOptimizationLevel() throws Throwable } @Before - public void resetLastValidSegmentRowId() throws Throwable + public void resetLastValidSegmentRowId() { // Don't want this setting to impact peer tests SegmentBuilder.updateLastValidSegmentRowId(-1); @@ -361,7 +361,7 @@ protected void simulateNodeRestart(boolean wait) cfs.indexManager.listIndexes().forEach(index -> { ((StorageAttachedIndexGroup)cfs.indexManager.getIndexGroup(index)).reset(); }); - cfs.indexManager.listIndexes().forEach(index -> cfs.indexManager.buildIndex(index)); + cfs.indexManager.listIndexes().forEach(cfs.indexManager::buildIndex); cfs.indexManager.executePreJoinTasksBlocking(true); if (wait) { @@ -852,9 +852,9 @@ protected int getCompactionTasks() return CompactionManager.instance.getActiveCompactions() + CompactionManager.instance.getPendingTasks(); } - protected String getSingleTraceStatement(Session session, String query, String contains) throws Throwable + protected String getSingleTraceStatement(Session session, String query, String contains) { - query = String.format(query, KEYSPACE + "." + currentTable()); + query = String.format(query, KEYSPACE + '.' + currentTable()); QueryTrace trace = session.execute(session.prepare(query).bind().enableTracing()).getExecutionInfo().getQueryTrace(); waitForTracingEvents(); @@ -866,7 +866,7 @@ protected String getSingleTraceStatement(Session session, String query, String c return null; } - protected void assertNumRows(int expected, String query, Object... args) throws Throwable + protected void assertNumRows(int expected, String query, Object... args) { ResultSet rs = executeNet(String.format(query, args)); assertEquals(expected, rs.all().size()); @@ -981,7 +981,7 @@ protected static class TestWithConcurrentVerification private final CountDownLatch taskCompleted = new CountDownLatch(1); private final int verificationIntervalInMs; - private final int verificationMaxInMs = 300_000; // 300s + private static final int verificationMaxInMs = 300_000; // 300s public TestWithConcurrentVerification(Runnable verificationTask, Runnable targetTask) { diff --git a/test/unit/org/apache/cassandra/index/sai/cql/NativeIndexDDLTest.java b/test/unit/org/apache/cassandra/index/sai/cql/NativeIndexDDLTest.java index ad7a96c2c84d..86c08133e6b2 100644 --- a/test/unit/org/apache/cassandra/index/sai/cql/NativeIndexDDLTest.java +++ b/test/unit/org/apache/cassandra/index/sai/cql/NativeIndexDDLTest.java @@ -1149,7 +1149,7 @@ private void verifyRebuildIndexComponent(IndexContext numericIndexContext, (corruptionType != CorruptionType.REMOVED)) return; - logger.info("CORRUPTING: " + component + ", corruption type = " + corruptionType); + logger.info("CORRUPTING: {}, corruption type = {}", component, corruptionType); int rowCount = 2; diff --git a/test/unit/org/apache/cassandra/index/sai/disk/NodeStartupTest.java b/test/unit/org/apache/cassandra/index/sai/disk/NodeStartupTest.java index a8bd18f1c08c..9e21d4ff015c 100644 --- a/test/unit/org/apache/cassandra/index/sai/disk/NodeStartupTest.java +++ b/test/unit/org/apache/cassandra/index/sai/disk/NodeStartupTest.java @@ -176,7 +176,7 @@ enum IndexStateOnRestart PER_SSTABLE_INCOMPLETE, PER_COLUMN_INCOMPLETE, PER_SSTABLE_CORRUPT, - PER_COLUMN_CORRUPT; + PER_COLUMN_CORRUPT } enum StartupTaskRunOrder @@ -349,13 +349,13 @@ public void populateTombstones() } } - private boolean isGroupIndexComplete() throws Exception + private boolean isGroupIndexComplete() { ColumnFamilyStore cfs = Objects.requireNonNull(Schema.instance.getKeyspaceInstance(KEYSPACE)).getColumnFamilyStore(currentTable()); return cfs.getLiveSSTables().stream().allMatch(sstable -> loadDescriptor(sstable, cfs).perSSTableComponents().isComplete()); } - private boolean isColumnIndexComplete() throws Exception + private boolean isColumnIndexComplete() { ColumnFamilyStore cfs = Objects.requireNonNull(Schema.instance.getKeyspaceInstance(KEYSPACE)).getColumnFamilyStore(currentTable()); return cfs.getLiveSSTables().stream().allMatch(sstable -> IndexDescriptor.isIndexBuildCompleteOnDisk(sstable, indexContext)); diff --git a/test/unit/org/apache/cassandra/index/sai/disk/v1/SegmentFlushTest.java b/test/unit/org/apache/cassandra/index/sai/disk/v1/SegmentFlushTest.java index 557f433df267..5572421a4705 100644 --- a/test/unit/org/apache/cassandra/index/sai/disk/v1/SegmentFlushTest.java +++ b/test/unit/org/apache/cassandra/index/sai/disk/v1/SegmentFlushTest.java @@ -202,7 +202,7 @@ private void testFlushBetweenRowIds(long sstableRowId1, long sstableRowId2, int minSegmentRowId = 0; maxSegmentRowId = 0; minKey = SAITester.TEST_FACTORY.createTokenOnly(key2.getToken()); - maxKey = SAITester.TEST_FACTORY.createTokenOnly(key2.getToken());; + maxKey = SAITester.TEST_FACTORY.createTokenOnly(key2.getToken()); minTerm = term2; maxTerm = term2; numRowsPerSegment = 1; diff --git a/test/unit/org/apache/cassandra/index/sai/disk/v1/bitpack/NumericValuesTest.java b/test/unit/org/apache/cassandra/index/sai/disk/v1/bitpack/NumericValuesTest.java index 0ded82ceff2e..d50004d423ff 100644 --- a/test/unit/org/apache/cassandra/index/sai/disk/v1/bitpack/NumericValuesTest.java +++ b/test/unit/org/apache/cassandra/index/sai/disk/v1/bitpack/NumericValuesTest.java @@ -77,7 +77,7 @@ private void testRepeatedNumericValues(boolean monotonic) throws Exception { for (int x = 0; x < length; x++) { - assertEquals(reader.get(x), 1000); + assertEquals(1000, reader.get(x)); } } } diff --git a/test/unit/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsTest.java b/test/unit/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsTest.java index b2a12ad0c75b..63178353df9c 100644 --- a/test/unit/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsTest.java +++ b/test/unit/org/apache/cassandra/index/sai/disk/v2/sortedterms/SortedTermsTest.java @@ -114,7 +114,7 @@ public void testFileValidation() throws Exception primaryKeys.forEach(primaryKey -> { try { - writer.add(v -> primaryKey.asComparableBytes(v)); + writer.add(primaryKey::asComparableBytes); } catch (IOException e) { diff --git a/test/unit/org/apache/cassandra/index/sai/utils/AbstractPrimaryKeyTest.java b/test/unit/org/apache/cassandra/index/sai/utils/AbstractPrimaryKeyTest.java index 1353fc6fbb76..30f688ed1af9 100644 --- a/test/unit/org/apache/cassandra/index/sai/utils/AbstractPrimaryKeyTest.java +++ b/test/unit/org/apache/cassandra/index/sai/utils/AbstractPrimaryKeyTest.java @@ -116,8 +116,8 @@ public class AbstractPrimaryKeyTest extends SaiRandomizedTest void assertByteComparison(PrimaryKey a, PrimaryKey b, int expected) { - assertEquals(expected, ByteComparable.compare(v -> a.asComparableBytes(v), - v -> b.asComparableBytes(v), + assertEquals(expected, ByteComparable.compare(a::asComparableBytes, + b::asComparableBytes, TypeUtil.BYTE_COMPARABLE_VERSION)); } @@ -135,7 +135,7 @@ else if (expected < 0) } else { - assertTrue(a.compareTo(b) == 0); + assertEquals(0, a.compareTo(b)); assertEquals(a, b); } } diff --git a/test/unit/org/apache/cassandra/index/sai/utils/SaiRandomizedTest.java b/test/unit/org/apache/cassandra/index/sai/utils/SaiRandomizedTest.java index b2b7ace5de8f..d5f2b99f45d3 100644 --- a/test/unit/org/apache/cassandra/index/sai/utils/SaiRandomizedTest.java +++ b/test/unit/org/apache/cassandra/index/sai/utils/SaiRandomizedTest.java @@ -74,7 +74,7 @@ private static void restoreUncaughtExceptionHandler() Thread.setDefaultUncaughtExceptionHandler(handler); } - private static IndexInputLeakDetector indexInputLeakDetector; + private static final IndexInputLeakDetector indexInputLeakDetector; protected static TemporaryFolder temporaryFolder; @@ -152,7 +152,7 @@ public static int randomIntBetween(int min, int max) { if (min < 0) throw new IllegalArgumentException("min must be >= 0: " + min); if (min > max) throw new IllegalArgumentException("max must be >= min: " + min + ", " + max); - return min == max ? min : (int) randomDoubleBetween((double) min, (double) max); + return min == max ? min : (int) randomDoubleBetween(min, max); } public static long randomLongBetween(long min, long max) From 7cf9326507aea3a63b72b23dbde5f05049196def Mon Sep 17 00:00:00 2001 From: Ruslan Fomkin Date: Wed, 19 Nov 2025 15:44:10 +0100 Subject: [PATCH 2/6] Fix tests and Sonar warning --- src/java/org/apache/cassandra/index/sai/SSTableContext.java | 1 + .../org/apache/cassandra/index/sai/disk/PerSSTableWriter.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/cassandra/index/sai/SSTableContext.java b/src/java/org/apache/cassandra/index/sai/SSTableContext.java index 2a272dae54aa..e18a697dcddd 100644 --- a/src/java/org/apache/cassandra/index/sai/SSTableContext.java +++ b/src/java/org/apache/cassandra/index/sai/SSTableContext.java @@ -65,6 +65,7 @@ private SSTableContext(SSTableContext copy) this.primaryKeyMapFactory = copy.primaryKeyMapFactory; } + @SuppressWarnings("resource") public static SSTableContext create(SSTableReader sstable, IndexComponents.ForRead perSSTableComponents) { var onDiskFormat = perSSTableComponents.onDiskFormat(); diff --git a/src/java/org/apache/cassandra/index/sai/disk/PerSSTableWriter.java b/src/java/org/apache/cassandra/index/sai/disk/PerSSTableWriter.java index fe03644324c1..fdf1d4b4ccb1 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/PerSSTableWriter.java +++ b/src/java/org/apache/cassandra/index/sai/disk/PerSSTableWriter.java @@ -28,7 +28,7 @@ */ public interface PerSSTableWriter { - PerSSTableWriter NONE = (key) -> {}; + PerSSTableWriter NONE = key -> {}; default void startPartition(long position) throws IOException {} From f83b7e3b4135b54b19e9cd4b8402f5efb2e70764 Mon Sep 17 00:00:00 2001 From: Ruslan Fomkin Date: Thu, 20 Nov 2025 12:14:30 +0100 Subject: [PATCH 3/6] Fix resource leaks failing tests --- .../org/apache/cassandra/index/sai/SSTableContext.java | 1 - .../index/sai/disk/v1/PartitionAwarePrimaryKeyMap.java | 9 ++++++--- .../index/sai/disk/v2/RowAwarePrimaryKeyMap.java | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/cassandra/index/sai/SSTableContext.java b/src/java/org/apache/cassandra/index/sai/SSTableContext.java index e18a697dcddd..2a272dae54aa 100644 --- a/src/java/org/apache/cassandra/index/sai/SSTableContext.java +++ b/src/java/org/apache/cassandra/index/sai/SSTableContext.java @@ -65,7 +65,6 @@ private SSTableContext(SSTableContext copy) this.primaryKeyMapFactory = copy.primaryKeyMapFactory; } - @SuppressWarnings("resource") public static SSTableContext create(SSTableReader sstable, IndexComponents.ForRead perSSTableComponents) { var onDiskFormat = perSSTableComponents.onDiskFormat(); diff --git a/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyMap.java b/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyMap.java index df780a4ee404..ad27da121b51 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyMap.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyMap.java @@ -59,8 +59,10 @@ public class PartitionAwarePrimaryKeyMap implements PrimaryKeyMap @ThreadSafe public static class PartitionAwarePrimaryKeyMapFactory implements Factory { + private final IndexComponents.ForRead perSSTableComponents; private final LongArray.Factory tokenReaderFactory; private final LongArray.Factory offsetReaderFactory; + private final MetadataSource metadata; private final KeyFetcher keyFetcher; private final IPartitioner partitioner; private final PrimaryKey.Factory primaryKeyFactory; @@ -74,13 +76,14 @@ public PartitionAwarePrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComp { try { - MetadataSource metadata = MetadataSource.loadMetadata(perSSTableComponents); + this.perSSTableComponents = perSSTableComponents; + this.metadata = MetadataSource.loadMetadata(perSSTableComponents); IndexComponent.ForRead offsetsComponent = perSSTableComponents.get(IndexComponentType.OFFSETS_VALUES); IndexComponent.ForRead tokensComponent = perSSTableComponents.get(IndexComponentType.TOKEN_VALUES); - NumericValuesMeta offsetsMeta = new NumericValuesMeta(metadata.get(offsetsComponent)); - NumericValuesMeta tokensMeta = new NumericValuesMeta(metadata.get(tokensComponent)); + NumericValuesMeta offsetsMeta = new NumericValuesMeta(this.metadata.get(offsetsComponent)); + NumericValuesMeta tokensMeta = new NumericValuesMeta(this.metadata.get(tokensComponent)); count = tokensMeta.valueCount; token = tokensComponent.createFileHandle(); diff --git a/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java b/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java index ef95247aef9a..c6f16a32eacd 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java @@ -71,6 +71,7 @@ public class RowAwarePrimaryKeyMap implements PrimaryKeyMap @ThreadSafe public static class RowAwarePrimaryKeyMapFactory implements Factory { + private final IndexComponents.ForRead perSSTableComponents; private final LongArray.Factory tokenReaderFactory; private final SortedTermsReader sortedTermsReader; private final long count; @@ -88,6 +89,7 @@ public RowAwarePrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComponents { try { + this.perSSTableComponents = perSSTableComponents; MetadataSource metadataSource = MetadataSource.loadMetadata(perSSTableComponents); NumericValuesMeta tokensMeta = new NumericValuesMeta(metadataSource.get(perSSTableComponents.get(IndexComponentType.TOKEN_VALUES))); count = tokensMeta.valueCount; From 47a4e16ff6bffca4e37ec0d3af94257eb7817d7c Mon Sep 17 00:00:00 2001 From: Ruslan Fomkin Date: Fri, 21 Nov 2025 11:39:46 +0100 Subject: [PATCH 4/6] Try to fix CNDB CI failuers --- .../cassandra/db/marshal/AbstractType.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/cassandra/db/marshal/AbstractType.java b/src/java/org/apache/cassandra/db/marshal/AbstractType.java index 537335c8a29c..2ddf69d5eb3d 100644 --- a/src/java/org/apache/cassandra/db/marshal/AbstractType.java +++ b/src/java/org/apache/cassandra/db/marshal/AbstractType.java @@ -37,6 +37,7 @@ import org.apache.cassandra.cql3.CQL3Type; import org.apache.cassandra.cql3.ColumnSpecification; import org.apache.cassandra.cql3.Term; +import org.apache.cassandra.db.rows.Cell; import org.apache.cassandra.exceptions.InvalidColumnTypeException; import org.apache.cassandra.exceptions.SyntaxException; import org.apache.cassandra.io.util.DataInputPlus; @@ -117,10 +118,21 @@ protected AbstractType(ComparisonType comparisonType, boolean isMultiCell, List< throw new IllegalStateException(); } - comparatorSet = new ValueComparators((l, r) -> - AbstractType.this.compare(l, ByteArrayAccessor.instance, r, ByteArrayAccessor.instance), - (l, r) -> - AbstractType.this.compare(l, ByteBufferAccessor.instance, r, ByteBufferAccessor.instance)); + comparatorSet = new ValueComparators(new Comparator<>() + { + @Override + public int compare(byte[] l, byte[] r) + { + return AbstractType.this.compare(l, ByteArrayAccessor.instance, r, ByteArrayAccessor.instance); + } + }, new Comparator<>() + { + @Override + public int compare(ByteBuffer l, ByteBuffer r) + { + return AbstractType.this.compare(l, ByteBufferAccessor.instance, r, ByteBufferAccessor.instance); + } + }); this.isMultiCell = isMultiCell; From 6b6de5f666e5364be54432e670aacd3e9454f081 Mon Sep 17 00:00:00 2001 From: Ruslan Fomkin Date: Wed, 26 Nov 2025 12:01:17 +0100 Subject: [PATCH 5/6] Avoid unnecessary class field --- .../cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java b/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java index c6f16a32eacd..ef95247aef9a 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java @@ -71,7 +71,6 @@ public class RowAwarePrimaryKeyMap implements PrimaryKeyMap @ThreadSafe public static class RowAwarePrimaryKeyMapFactory implements Factory { - private final IndexComponents.ForRead perSSTableComponents; private final LongArray.Factory tokenReaderFactory; private final SortedTermsReader sortedTermsReader; private final long count; @@ -89,7 +88,6 @@ public RowAwarePrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComponents { try { - this.perSSTableComponents = perSSTableComponents; MetadataSource metadataSource = MetadataSource.loadMetadata(perSSTableComponents); NumericValuesMeta tokensMeta = new NumericValuesMeta(metadataSource.get(perSSTableComponents.get(IndexComponentType.TOKEN_VALUES))); count = tokensMeta.valueCount; From 9a7f49af5d5498cd13dac842b1bfa43c335d5103 Mon Sep 17 00:00:00 2001 From: Ruslan Fomkin Date: Fri, 28 Nov 2025 11:26:00 +0100 Subject: [PATCH 6/6] Revert "Avoid unnecessary class field" This reverts commit 6b6de5f666e5364be54432e670aacd3e9454f081. --- .../cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java b/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java index ef95247aef9a..c6f16a32eacd 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyMap.java @@ -71,6 +71,7 @@ public class RowAwarePrimaryKeyMap implements PrimaryKeyMap @ThreadSafe public static class RowAwarePrimaryKeyMapFactory implements Factory { + private final IndexComponents.ForRead perSSTableComponents; private final LongArray.Factory tokenReaderFactory; private final SortedTermsReader sortedTermsReader; private final long count; @@ -88,6 +89,7 @@ public RowAwarePrimaryKeyMapFactory(IndexComponents.ForRead perSSTableComponents { try { + this.perSSTableComponents = perSSTableComponents; MetadataSource metadataSource = MetadataSource.loadMetadata(perSSTableComponents); NumericValuesMeta tokensMeta = new NumericValuesMeta(metadataSource.get(perSSTableComponents.get(IndexComponentType.TOKEN_VALUES))); count = tokensMeta.valueCount;