Skip to content

Commit 7ee239a

Browse files
committed
Unwrap LongType properly when calculating min/max terms in V1SSTableIndex
patch by Caleb Rackliffe; reviewed by David Capwell for CASSANDRA-21635
1 parent c574262 commit 7ee239a

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

‎CHANGES.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
5.0.10
2+
* Unwrap LongType properly when calculating min/max terms in V1SSTableIndex (CASSANDRA-21635)
23
* Force repair should ignore min_repair_interval (CASSANDRA-21552)
34
* Render SubnetGroups as JSON in system_views.settings (CASSANDRA-21579)
45
* Avoid rebuilding per-SSTable SAI components unless missing or corrupted (CASSANDRA-21515)

‎src/java/org/apache/cassandra/index/sai/disk/v1/V1SSTableIndex.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public V1SSTableIndex(SSTableContext sstableContext, StorageAttachedIndex index)
9999

100100
this.bounds = AbstractBounds.bounds(minKey, true, maxKey, true);
101101

102-
this.minTerm = metadatas.stream().map(m -> m.minTerm).min(indexTermType.comparator()).orElse(null);
103-
this.maxTerm = metadatas.stream().map(m -> m.maxTerm).max(indexTermType.comparator()).orElse(null);
102+
this.minTerm = metadatas.stream().map(m -> m.minTerm).reduce(indexTermType::min).orElse(null);
103+
this.maxTerm = metadatas.stream().map(m -> m.maxTerm).reduce(indexTermType::max).orElse(null);
104104

105105
this.numRows = metadatas.stream().mapToLong(m -> m.numRows).sum();
106106

‎src/java/org/apache/cassandra/index/sai/utils/IndexTermType.java‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Arrays;
2626
import java.util.Collection;
2727
import java.util.Collections;
28-
import java.util.Comparator;
2928
import java.util.EnumSet;
3029
import java.util.Iterator;
3130
import java.util.List;
@@ -453,15 +452,6 @@ public Iterator<ByteBuffer> valuesOf(Row row, long nowInSecs)
453452
}
454453
}
455454

456-
public Comparator<ByteBuffer> comparator()
457-
{
458-
// Override the comparator for BigInteger, frozen collections and composite types
459-
if (isBigInteger() || isBigDecimal() || isComposite() || isFrozen())
460-
return FastByteOperations::compareUnsigned;
461-
462-
return indexType;
463-
}
464-
465455
/**
466456
* Compare two terms based on their type. This is used in place of {@link AbstractType#compare(ByteBuffer, ByteBuffer)}
467457
* so that the default comparison can be overridden for specific types.

‎test/unit/org/apache/cassandra/index/sai/cql/ClusteringKeyIndexTest.java‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
*/
1818
package org.apache.cassandra.index.sai.cql;
1919

20+
import org.junit.After;
2021
import org.junit.Before;
2122
import org.junit.Test;
2223

2324
import org.apache.cassandra.index.sai.SAITester;
25+
import org.apache.cassandra.index.sai.disk.v1.segment.SegmentBuilder;
2426

2527
import static org.assertj.core.api.Assertions.assertThatThrownBy;
28+
import static org.junit.Assert.assertEquals;
2629

2730
public class ClusteringKeyIndexTest extends SAITester
2831
{
@@ -35,6 +38,12 @@ public void createTableAndIndex()
3538
disableCompaction();
3639
}
3740

41+
@After
42+
public void resetSegmentSize()
43+
{
44+
SegmentBuilder.updateLastValidSegmentRowId(-1);
45+
}
46+
3847
private void insertData1() throws Throwable
3948
{
4049
execute("INSERT INTO %s (pk1, pk2, val) VALUES (1, '1', 1)");
@@ -57,6 +66,33 @@ public void queryFromMemtable() throws Throwable
5766
runQueries();
5867
}
5968

69+
70+
@Test
71+
public void reversedBigintClusteringMultiSegment()
72+
{
73+
createTable("CREATE TABLE %s (pk int, ck bigint, PRIMARY KEY (pk, ck)) WITH CLUSTERING ORDER BY (ck DESC)");
74+
createIndex("CREATE INDEX ON %s(ck) USING 'sai'");
75+
disableCompaction(keyspace());
76+
77+
for (long ck = 10; ck < 16; ck++)
78+
execute("INSERT INTO %s (pk, ck) VALUES (?, ?)", 1, ck);
79+
flush();
80+
81+
for (long ck = 16; ck < 22; ck++)
82+
execute("INSERT INTO %s (pk, ck) VALUES (?, ?)", 1, ck);
83+
flush();
84+
85+
// Force compaction with a small segment size cap, producing multiple segments.
86+
SegmentBuilder.updateLastValidSegmentRowId(3);
87+
compact();
88+
89+
for (long ck = 10; ck < 22; ck++)
90+
{
91+
int cnt = getRows(execute("SELECT ck FROM %s WHERE ck = ?", ck)).length;
92+
assertEquals("Missing row for ck=" + ck, 1, cnt);
93+
}
94+
}
95+
6096
private Object[] expectedRow(int index)
6197
{
6298
return row(index, Integer.toString(index), index);

0 commit comments

Comments
 (0)