[ 
https://issues.apache.org/jira/browse/CASSANDRA-19011?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17790521#comment-17790521
 ] 

Mike Adamson commented on CASSANDRA-19011:
------------------------------------------

I have reproduced this issue in a simple random test and have a fix. The issue 
is as follows:

The PostingListRangeIterator.performSkipTo method currently looks like this:

{code:java}
    protected void performSkipTo(PrimaryKey nextKey)
    {
        if (skipToToken != null && skipToToken.compareTo(nextKey) >= 0)
            return;

        skipToToken = nextKey;
        needsSkipping = true;
    }
{code}
The problem is in the first line. The comparison is >=. Currently, this means 
that if the  skipToToken is a token only  primary key then it will be equal to 
any other primary key with the same token. If nextKey is a wide key (with 
clustering) it will match. This means that the skip will be to the first row in 
the partition and not the required row indicated by the clustering. 

The, easy, fix for this is to change the comparison to > so we only keep the 
existing skipToToken if it is greater than nextKey. This fixes the problem but 
I think it is worth looking at the PrimaryKey comparisons generally to make 
sure that they meet a specific set of comparison requirements. This is the 
second identified issue relating to PrimaryKey comparisons, the other being 
CASSANDRA-19034.


> Harry-found exception in during SAI query
> -----------------------------------------
>
>                 Key: CASSANDRA-19011
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-19011
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Feature/SAI
>            Reporter: Alex Petrov
>            Assignee: Mike Adamson
>            Priority: Normal
>             Fix For: 5.0-rc
>
>
> Schema:
> {code:java}
> CREATE TABLE IF NOT EXISTS distributed_test_keyspace.tbl1 (pk1 bigint,ck1 
> bigint,v1 ascii,v2 bigint, PRIMARY KEY (pk1, ck1)) WITH  CLUSTERING ORDER BY 
> (ck1 ASC);
> CREATE CUSTOM INDEX v1_sai_idx ON distributed_test_keyspace.tbl1 (v1) USING 
> 'StorageAttachedIndex' WITH OPTIONS = {'case_sensitive': 'false', 
> 'normalize': 'true', 'ascii': 'true'}; ;
> CREATE CUSTOM INDEX v2_sai_idx ON distributed_test_keyspace.tbl1 (v2) USING 
> 'StorageAttachedIndex';
>  {code}
> {code:java}
> java.lang.AssertionError: skipped to an item smaller than the target; 
> iterator: 
> org.apache.cassandra.index.sai.disk.IndexSearchResultIterator@f399f79, target 
> key: PrimaryKey: { token: 8384965201802291970, partition: 
> DecoratedKey(8384965201802291970, c4bc1c50f9e76a50), clustering: 
> CLUSTERING:8b4b4c5991a4ea10 } , returned key: PrimaryKey: { token: 
> 8384965201802291970, partition: DecoratedKey(8384965201802291970, 
> c4bc1c50f9e76a50), clustering: CLUSTERING:89f1cf92658cb668 } 
>       at 
> org.apache.cassandra.index.sai.iterators.KeyRangeIntersectionIterator.computeNext(KeyRangeIntersectionIterator.java:95)
>       at 
> org.apache.cassandra.index.sai.iterators.KeyRangeIntersectionIterator.computeNext(KeyRangeIntersectionIterator.java:39)
>       at 
> org.apache.cassandra.utils.AbstractGuavaIterator.tryToComputeNext(AbstractGuavaIterator.java:122)
>       at 
> org.apache.cassandra.index.sai.iterators.KeyRangeIterator.tryToComputeNext(KeyRangeIterator.java:129)
>       at 
> org.apache.cassandra.utils.AbstractGuavaIterator.hasNext(AbstractGuavaIterator.java:116)
>       at 
> org.apache.cassandra.index.sai.plan.StorageAttachedIndexSearcher$ResultRetriever.nextKey(StorageAttachedIndexSearcher.java:274)
>       at 
> org.apache.cassandra.index.sai.plan.StorageAttachedIndexSearcher$ResultRetriever.nextKeyInRange(StorageAttachedIndexSearcher.java:203)
>       at 
> org.apache.cassandra.index.sai.plan.StorageAttachedIndexSearcher$ResultRetriever.nextSelectedKeyInRange(StorageAttachedIndexSearcher.java:234)
>       at 
> org.apache.cassandra.index.sai.plan.StorageAttachedIndexSearcher$ResultRetriever.nextRowIterator(StorageAttachedIndexSearcher.java:188)
>       at 
> org.apache.cassandra.index.sai.plan.StorageAttachedIndexSearcher$ResultRetriever.computeNext(StorageAttachedIndexSearcher.java:169)
>       at 
> org.apache.cassandra.index.sai.plan.StorageAttachedIndexSearcher$ResultRetriever.computeNext(StorageAttachedIndexSearcher.java:111)
>       at 
> org.apache.cassandra.utils.AbstractIterator.hasNext(AbstractIterator.java:47)
>       at 
> org.apache.cassandra.db.transform.BasePartitions.hasNext(BasePartitions.java:91)
>       at 
> org.apache.cassandra.db.partitions.UnfilteredPartitionIterators$Serializer.serialize(UnfilteredPartitionIterators.java:338)
>       at 
> org.apache.cassandra.db.ReadResponse$LocalDataResponse.build(ReadResponse.java:201)
>       at 
> org.apache.cassandra.db.ReadResponse$LocalDataResponse.<init>(ReadResponse.java:186)
>       at 
> org.apache.cassandra.db.ReadResponse.createDataResponse(ReadResponse.java:48)
>       at 
> org.apache.cassandra.db.ReadCommand.createResponse(ReadCommand.java:346)
>       at 
> org.apache.cassandra.service.StorageProxy$LocalReadRunnable.runMayThrow(StorageProxy.java:2186)
>       at 
> org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:2581)
>       at 
> org.apache.cassandra.concurrent.ExecutionFailure$2.run(ExecutionFailure.java:163)
>       at org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:143)
>       at 
> relocated.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
>       at java.base/java.lang.Thread.run(Thread.java:829) {code}
>  
> Unfortunately, there's no tooling for shrinking around SAI just yet, but I 
> have a programmatic repro using INSERT and DELETE statements. I will do my 
> best to post it asap, but thought this can already be useful for visibility.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to