cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Spriegel (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CASSANDRA-6892) Cassandra 2.0.x validates Thrift columns incorrectly and causes InvalidRequestException
Date Fri, 21 Mar 2014 21:13:49 GMT

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

Christian Spriegel commented on CASSANDRA-6892:
-----------------------------------------------

Tyler can reproduce the issue now, but I am posting this anyway :-)

The thrift-schema:
{code}
create column family MasterdataIndex with
    compression_options = {sstable_compression:SnappyCompressor, chunk_length_kb:64} and
    comparator = UTF8Type and
    key_validation_class = 'CompositeType(UTF8Type,LongType)' and
    default_validation_class = BytesType;
{code}

With the following data:
{code}
[default@MDS_0] list MasterdataIndex ;
Using default limit of 100
Using default cell limit of 100
-------------------
RowKey: G:1
=> (name=GOOD, value=474f4f44, timestamp=1395434320342000)
-------------------
RowKey: K:1
=> (name=key0, value=160218046b6579301804474f4f4416c29a0c160000, timestamp=1395434320347001)
=> (name=key1, value=160218046b6579311804474f4f4416c49a0c160000, timestamp=1395434320351001)

2 Rows Returned.
Elapsed time: 30 msec(s).
[default@MDS_0] 
{code}
(and a "key2" which failed to insert)



results in the following CFMetaData.toString():
{code}
org.apache.cassandra.config.CFMetaData@54196399[
cfId=1d46d5a5-726e-3610-b08e-ebeca28b6325,ksName=MDS_0,
cfName=MasterdataIndex,
cfType=Standard,
comparator=org.apache.cassandra.db.marshal.UTF8Type,
comment=,readRepairChance=0.1,dclocalReadRepairChance=0.0,replicateOnWrite=true,
gcGraceSeconds=864000,
defaultValidator=org.apache.cassandra.db.marshal.BytesType,
keyValidator=org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.UTF8Type,org.apache.cassandra.db.marshal.LongType),minCompactionThreshold=4,maxCompactionThreshold=32,
column_metadata=
{
java.nio.HeapByteBuffer[pos=0 lim=4 cap=4]=ColumnDefinition{name=6b657932, validator=org.apache.cassandra.db.marshal.LongType,
type=PARTITION_KEY, componentIndex=1, indexName=null, indexType=null}, 
java.nio.HeapByteBuffer[pos=0 lim=3 cap=3]=ColumnDefinition{name=6b6579, validator=org.apache.cassandra.db.marshal.UTF8Type,
type=PARTITION_KEY, componentIndex=0, indexName=null, indexType=null}
},
compactionStrategyClass=class org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy,compactionStrategyOptions={},compressionOptions={sstable_compression=org.apache.cassandra.io.compress.SnappyCompressor,
chunk_length_kb=64},bloomFilterFpChance=<null>,memtable_flush_period_in_ms=0,caching=KEYS_ONLY,defaultTimeToLive=0,speculative_retry=NONE,indexInterval=128,populateIoCacheOnFlush=false,droppedColumns={},triggers={}]
{code}

> Cassandra 2.0.x validates Thrift columns incorrectly and causes InvalidRequestException
> ---------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-6892
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-6892
>             Project: Cassandra
>          Issue Type: Bug
>          Components: API
>            Reporter: Christian Spriegel
>            Assignee: Tyler Hobbs
>            Priority: Minor
>             Fix For: 2.0.7
>
>         Attachments: CASSANDRA-6892_V1.patch
>
>
> I just upgrade my local dev machine to Cassandra 2.0, which causes one of my automated
tests to fail now. With the latest 1.2.x it was working fine.
> The Exception I get on my client (using Hector) is:
> {code}
> me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:(Expected
8 or 0 byte long (21)) [MDS_0][MasterdataIndex][key2] failed validation)
> 	at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:52)
> 	at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:265)
> 	at me.prettyprint.cassandra.model.ExecutingKeyspace.doExecuteOperation(ExecutingKeyspace.java:113)
> 	at me.prettyprint.cassandra.model.MutatorImpl.execute(MutatorImpl.java:243)
> 	at me.prettyprint.cassandra.service.template.AbstractColumnFamilyTemplate.executeBatch(AbstractColumnFamilyTemplate.java:115)
> 	at me.prettyprint.cassandra.service.template.AbstractColumnFamilyTemplate.executeIfNotBatched(AbstractColumnFamilyTemplate.java:163)
> 	at me.prettyprint.cassandra.service.template.ColumnFamilyTemplate.update(ColumnFamilyTemplate.java:69)
> 	at com.mycompany.spring3utils.dataaccess.cassandra.AbstractCassandraDAO.doUpdate(AbstractCassandraDAO.java:482)
> 	....
> Caused by: InvalidRequestException(why:(Expected 8 or 0 byte long (21)) [MDS_0][MasterdataIndex][key2]
failed validation)
> 	at org.apache.cassandra.thrift.Cassandra$batch_mutate_result.read(Cassandra.java:20833)
> 	at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
> 	at org.apache.cassandra.thrift.Cassandra$Client.recv_batch_mutate(Cassandra.java:964)
> 	at org.apache.cassandra.thrift.Cassandra$Client.batch_mutate(Cassandra.java:950)
> 	at me.prettyprint.cassandra.model.MutatorImpl$3.execute(MutatorImpl.java:246)
> 	at me.prettyprint.cassandra.model.MutatorImpl$3.execute(MutatorImpl.java:1)
> 	at me.prettyprint.cassandra.service.Operation.executeAndSetResult(Operation.java:104)
> 	at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:258)
> 	... 46 more
> {code}
> The schema of my column family is:
> {code}
> create column family MasterdataIndex with
>     compression_options = {sstable_compression:SnappyCompressor, chunk_length_kb:64}
and
>     comparator = UTF8Type and
>     key_validation_class = 'CompositeType(UTF8Type,LongType)' and
>     default_validation_class = BytesType;
> {code}
> From the error message it looks like Cassandra is trying to validate the value with the
key-validator! (My value in this case it 21 bytes long)
> I studied the Cassandra 2.0 code and found something wrong. It seems in CFMetaData.addDefaultKeyAliases
it passes the KeyValidator into ColumnDefinition.partitionKeyDef. Inside ColumnDefinition
the validator is expected to be the value validator!
> In CFMetaData:
> {code}
>     private List<ColumnDefinition> addDefaultKeyAliases(List<ColumnDefinition>
pkCols)
>     {
>         for (int i = 0; i < pkCols.size(); i++)
>         {
>             if (pkCols.get(i) == null)
>             {
>                 Integer idx = null;
>                 AbstractType<?> type = keyValidator;
>                 if (keyValidator instanceof CompositeType)
>                 {
>                     idx = i;
>                     type = ((CompositeType)keyValidator).types.get(i);
>                 }
>                 // For compatibility sake, we call the first alias 'key' rather than
'key1'. This
>                 // is inconsistent with column alias, but it's probably not worth risking
breaking compatibility now.
>                 ByteBuffer name = ByteBufferUtil.bytes(i == 0 ? DEFAULT_KEY_ALIAS : DEFAULT_KEY_ALIAS
+ (i + 1));
>                 ColumnDefinition newDef = ColumnDefinition.partitionKeyDef(name, type,
idx); // type is LongType in my case, as it uses keyValidator !!!
>                 column_metadata.put(newDef.name, newDef);
>                 pkCols.set(i, newDef);
>             }
>         }
>         return pkCols;
>     }
> ...
>     public AbstractType<?> getValidator() // in ThriftValidation this is expected
to be the value validator!
>     {
>         return validator;
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message