Hello,

I wanted to use the new CAS functionality in Cassandra 2.0 and for some reason it does not work when I try to update or insert a row when CAS fails. Let me show:

I have a fresh installation of Cassandra 2.0 on my Mac OS filled with a keyspace and this column family:

CREATE TABLE cardinality (
  key blob,
  column1 blob,
  value blob,
  PRIMARY KEY (key, column1)
) WITH COMPACT STORAGE AND
  bloom_filter_fp_chance=0.010000 AND
  caching='KEYS_ONLY' AND
  comment='' AND
  dclocal_read_repair_chance=0.000000 AND
  gc_grace_seconds=864000 AND
  index_interval=128 AND
  read_repair_chance=1.000000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  default_time_to_live=0 AND
  speculative_retry='NONE' AND
  memtable_flush_period_in_ms=0 AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'LZ4Compressor'};

Using CQL shell:

cqlsh:keyspace> select * from cardinality;

(0 rows)

cqlsh:keyspace> insert into cardinality (key, column1, value) values (0x0001, 0x0002, 0x0003) if not exists;
cqlsh:keyspace> insert into cardinality (key, column1, value) values (0x0001, 0x0002, 0x0003) if not exists;
Request did not complete within rpc_timeout.
cqlsh:keyspace> select * from cardinality;

 key    | column1 | value
--------+---------+--------
 0x0001 |  0x0002 | 0x0003

(1 rows)

cqlsh:keyspace> update cardinality set value = 0x0004 where key = 0x0001 and column1 = 0x0002 if value = 0x0003;
cqlsh:keyspace> select * from cardinality;

 key    | column1 | value
--------+---------+--------
 0x0001 |  0x0002 | 0x0004

(1 rows)

cqlsh:keyspace> update cardinality set value = 0x0005 where key = 0x0001 and column1 = 0x0002 if value = 0x9999;
Internal application error
cqlsh:keyspace> select * from cardinality;

 key    | column1 | value
--------+---------+--------
 0x0001 |  0x0002 | 0x0004

(1 rows)

Can someone explain why I get the "rpc_timeout" and "Internal application error" errors? In my opinion this should work and only give me the result that insert/update failed because of CAS condtion.

The Cassandra outputs these stacktraces:
ERROR 15:47:42,072 Exception in thread Thread[ReadStage:82,5,main]
java.lang.RuntimeException: java.lang.ClassCastException: org.apache.cassandra.db.marshal.BytesType cannot be cast to org.apache.cassandra.db.marshal.CompositeType
at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1867)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassCastException: org.apache.cassandra.db.marshal.BytesType cannot be cast to org.apache.cassandra.db.marshal.CompositeType
at org.apache.cassandra.db.filter.SliceQueryFilter.columnCounter(SliceQueryFilter.java:219)
at org.apache.cassandra.db.filter.SliceQueryFilter.collectReducedColumns(SliceQueryFilter.java:186)
at org.apache.cassandra.db.filter.QueryFilter.collateColumns(QueryFilter.java:122)
at org.apache.cassandra.db.filter.QueryFilter.collateOnDiskAtom(QueryFilter.java:80)
at org.apache.cassandra.db.filter.QueryFilter.collateOnDiskAtom(QueryFilter.java:72)
at org.apache.cassandra.db.CollationController.collectAllData(CollationController.java:314)
at org.apache.cassandra.db.CollationController.getTopLevelColumns(CollationController.java:53)
at org.apache.cassandra.db.ColumnFamilyStore.getTopLevelColumns(ColumnFamilyStore.java:1469)
at org.apache.cassandra.db.ColumnFamilyStore.getColumnFamily(ColumnFamilyStore.java:1295)
at org.apache.cassandra.db.Keyspace.getRow(Keyspace.java:332)
at org.apache.cassandra.db.SliceFromReadCommand.getRow(SliceFromReadCommand.java:65)
at org.apache.cassandra.service.StorageProxy$LocalReadRunnable.runMayThrow(StorageProxy.java:1336)
at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1863)
... 3 more
ERROR 15:48:50,811 Internal error processing execute_cql3_query
java.lang.NullPointerException
at org.apache.cassandra.cql3.CFDefinition.get(CFDefinition.java:119)
at org.apache.cassandra.cql3.statements.ModificationStatement.buildCasFailureResultSet(ModificationStatement.java:441)
at org.apache.cassandra.cql3.statements.ModificationStatement.buildCasResultSet(ModificationStatement.java:407)
at org.apache.cassandra.cql3.statements.ModificationStatement.executeWithCondition(ModificationStatement.java:395)
at org.apache.cassandra.cql3.statements.ModificationStatement.execute(ModificationStatement.java:344)
at org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:101)
at org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:117)
at org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:108)
at org.apache.cassandra.thrift.CassandraServer.execute_cql3_query(CassandraServer.java:1920)
at org.apache.cassandra.thrift.Cassandra$Processor$execute_cql3_query.getResult(Cassandra.java:4372)
at org.apache.cassandra.thrift.Cassandra$Processor$execute_cql3_query.getResult(Cassandra.java:4356)
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
at org.apache.cassandra.thrift.CustomTThreadPoolServer$WorkerProcess.run(CustomTThreadPoolServer.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)

Thanks for any help.
-- 
Jakub Janeček