Astyanax: simple write throwing this exception: Not enough bytes to read value of component
Asked Answered
H

2

9

I am new to astyanax and trying some sample programs and getting this error. This is a simple write and looks like am doing some thing basic wrong. Not using composite keys.

Caused by: InvalidRequestException(why:Not enough bytes to read value of component 0)
    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 com.netflix.astyanax.thrift.ThriftKeyspaceImpl$1$1.internalExecute(ThriftKeyspaceImpl.java:120)
    at com.netflix.astyanax.thrift.ThriftKeyspaceImpl$1$1.internalExecute(ThriftKeyspaceImpl.java:117)
    at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:56)

Here's the code:

    AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
        .forCluster(CLUSTER_NAME)
        .forKeyspace(keySpaceName)
        .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()      
            .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
            .setCqlVersion("3.0.0")
            .setTargetCassandraVersion("1.2")
        )
        .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
            .setPort(50825)
            .setMaxConnsPerHost(10)
            .setSeeds("nodename:50825")
            .setConnectTimeout(20000)
        )
        .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
        .buildKeyspace(ThriftFamilyFactory.getInstance());

    context.start();
    System.out.println("getting context.. done ");
    Keyspace keyspace = context.getEntity();
    MutationBatch m = keyspace.prepareMutationBatch();

    ColumnFamily<String, String> colFam = new ColumnFamily<String, String>("test",
            StringSerializer.get(), StringSerializer.get());

    m.withRow(colFam, "abc")
        .putColumn("col2", "test1", null);
    m.execute();

Here's the table describe:

CREATE TABLE test (
 col1 text PRIMARY KEY,
 col2 text,
 col3 text
) WITH
 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
 read_repair_chance=0.100000 AND
 replicate_on_write='true' AND
 populate_io_cache_on_flush='false' AND
 compaction={'class': 'SizeTieredCompactionStrategy'} AND
 compression={'sstable_compression': 'SnappyCompressor'};
Homology answered 16/3, 2013 at 6:11 Comment(3)
One other update: The table is created using CQL3 and cassandra version used is 1.2.2 Also if i use a cql3 command to insert a row, its working fine. ColumnFamily<String, String> TAG_CF = ColumnFamily.newColumnFamily("grd.test", StringSerializer.get(), StringSerializer.get()); keyspace.prepareQuery(TAG_CF).withCql("insert into grd.test(col1, col2, col3) " + "values ('id2', 'sample1', 'sample1');") .execute(); So if i use MutationBatch its still not working. Really appreciate some help. thanks.Homology
Filed an Issue to get thoughts .. github.com/Netflix/astyanax/issues/314 @Blair - Did you work around by having COMPACT STORAGE - pre 1.2 form (I'm about to experiment that ..)Houser
@ Jerish Sam David : I have composite key as primary key. I get : COMPACT STORAGE with composite PRIMARY KEY allows no more than one column not part of the PRIMARY KEY How to resolve this other than changing the schemaWildwood
S
17

I'm also new to Astyanax and encountering the the same exceptions. The exception is due to a mismatch between what Astyanax Thrift-based objects think the column definition should look like and how it is store in 1.2+ using CQL 3. I learned specifying COMPACT STORAGE so that the table is created in the pre 1.2 format will allow me interact with it via the Thrift-based objects. FWIW: I'm building Astyanax from source, but I did see a 1.56.34 in maven central; I would update to that also.

CREATE TABLE test (
 col1 text PRIMARY KEY,
 col2 text,
 col3 text
) WITH COMPACT STORAGE AND
...

See Working with pre-CQL 3 applications

Suppliant answered 8/4, 2013 at 19:22 Comment(3)
Is there any work on having Astyanax Thrift-based objects understand CQL3 column definition? I'm wondering if my new Cassandra schema should use CQL3 everywhere or use the programmatic method of creating column families.Colloid
I also get a similar exception using 1.56.37 and testing ColumnPrefixDistributedRowLock.Colloid
The link is dead, it moved to Working with pre-CQL 3 applicationsRenell
E
0

I solution provided by user2251060 does the job. In addition, Netflix is working on a new version of Astyanax that depends on the Datastax java driver to convert the thrift objects to the underlying CQL based ones. You can find more information at https://github.com/Netflix/astyanax/wiki/Astyanax-over-Java-Driver

Erinerina answered 23/11, 2014 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.