[
https://issues.apache.org/jira/browse/CASSANDRA-5023?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13509962#comment-13509962
]
Yuki Morishita commented on CASSANDRA-5023:
-------------------------------------------
In above case, inserting via CQL stores value(and key in index) in
IntegerType(BigInteger), and you are querying that with 1 byte
ByteBuffer(ByteBufferUtil.bytes(0)). If you change the line
{code}
indexExpressions.add(new
IndexExpression(ByteBufferUtil.bytes("numberOfDeloreans"), IndexOperator.EQ,
ByteBufferUtil.bytes(0)));
{code}
to
{code}
indexExpressions.add(new
IndexExpression(ByteBufferUtil.bytes("numberOfDeloreans"), IndexOperator.EQ,
IntegerType.instance.fromString("0")));
{code}
it all works fine.
So why the code has been working with 1.0? In 1.0, DecoratedKey#compareTo just
compares two tokens. LocalToken, which is used for secondary index, from
ByteBufferUtil.bytes(0) ...(1) and from
IntegerType.instance.fromString("0")...(2) are considered equal when using
IntegerType, and that's why you can query IntegerTyped DK with both (1) and (2).
DK#comparedTo changed since 1.1(CASSANDRA-1034), and now DKs are compared by
key itself byte by byte if two tokens are considered equal. In above case,
tokens are equal but keys are different byte-wise. So you only can query
IndexedTyped value with the same IndexTyped value now.
So I conclude that the behavior of 1.0 can be considered as a "bug".
> Upgrading from 1.0 to 1.1 makes secondary indexes no longer work
> ----------------------------------------------------------------
>
> Key: CASSANDRA-5023
> URL: https://issues.apache.org/jira/browse/CASSANDRA-5023
> Project: Cassandra
> Issue Type: Bug
> Components: Core
> Reporter: Jeremy Hanna
> Assignee: Yuki Morishita
> Fix For: 1.1.8
>
>
> To reproduce:
> Create column family with C* 1.0.8:
> {code}
> CREATE KEYSPACE Keyspace1
> with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'
> and strategy_options = {replication_factor:1};
> use Keyspace1;
> CREATE COLUMN FAMILY 'User' WITH
> key_validation_class = 'UTF8Type' AND
> comparator = 'UTF8Type' AND
> default_validation_class = 'UTF8Type' AND
> compression_options =
> {sstable_compression:SnappyCompressor,chunk_length_kb:64} AND
> column_metadata = [
> {column_name: 'numberOfDeloreans', validation_class: 'IntegerType',
> index_type: KEYS}
> ];
> {code}
> Then in cqlsh add some data:
> {code}
> use Keyspace1;
> update User set 'numberOfDeloreans'=0 where key = 'marty';
> update User set 'userId'='themartymcfly' where key = 'marty';
> {code}
> In cqlsh, do
> {code}select * from User where numberOfDeloreans=0;{code}
> Then in thrift do:
> {code}
> package org.mostlyharmless;
> import org.apache.cassandra.thrift.*;
> import org.apache.cassandra.utils.ByteBufferUtil;
> import org.apache.thrift.TException;
> import org.apache.thrift.protocol.TProtocol;
> import org.apache.thrift.transport.TFramedTransport;
> import org.apache.thrift.transport.TSocket;
> import org.apache.thrift.transport.TTransport;
> import java.io.UnsupportedEncodingException;
> import java.nio.ByteBuffer;
> import java.util.ArrayList;
> import java.util.List;
> public class ThriftQuery {
> public static void main(String[] args)
> throws TException, InvalidRequestException, UnavailableException,
> UnsupportedEncodingException, NotFoundException, TimedOutException
> {
> TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
> TProtocol proto = new TBinaryProtocol(tr);
> Cassandra.Client client = new Cassandra.Client(proto);
> tr.open();
> client.set_keyspace("Keyspace1");
> ColumnParent columnParent = new ColumnParent("User");
> SlicePredicate slicePredicate = new SlicePredicate();
> List<ByteBuffer> columnNames = new ArrayList<ByteBuffer>();
> columnNames.add(ByteBufferUtil.bytes("userId"));
> slicePredicate.setColumn_names(columnNames);
> KeyRange keyRange = new KeyRange();
> keyRange.setStart_token("0");
> keyRange.setEnd_token("0");
> List<IndexExpression> indexExpressions = new
> ArrayList<IndexExpression>();
> indexExpressions.add(new
> IndexExpression(ByteBufferUtil.bytes("numberOfDeloreans"), IndexOperator.EQ,
> ByteBufferUtil.bytes(0)));
> keyRange.setRow_filter(indexExpressions);
> List<KeySlice> keySlices = client.get_range_slices(columnParent,
> slicePredicate, keyRange, ConsistencyLevel.ONE);
> System.out.println("number of keyslices returned: " +
> keySlices.size());
> tr.close();
> }
> }
> {code}
> Note that 1 record is returned in both instances.
> Run nodetool drain on 1.0.8. Start 1.1.7. Do the cqlsh query again, returns
> the result. Run the thrift code again, get 0 results.
> Tried both upgradesstables and rebuild_index. Didn't help.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira