9

我是 astyanax 的新手,尝试了一些示例程序并收到此错误。这是一个简单的写法,看起来我在做一些基本错误的事情。不使用复合键。

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)

这是代码:

    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();

这是表格描述:

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'};
4

2 回答 2

17

我也是 Astyanax 的新手,遇到了同样的例外。例外是由于基于 Astyanax Thrift 的对象认为列定义的外观与使用 CQL 3 在 1.2+ 中的存储方式之间不匹配。我学会了指定 COMPACT STORAGE 以便以 1.2 之前的格式创建表允许我通过基于 Thrift 的对象与之交互。FWIW:我正在从源代码构建 Astyanax,但我确实在 maven Central 中看到了 1.56.34;我也会对此进行更新。

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

请参阅使用 CQL 3 之前的应用程序

于 2013-04-08T19:22:24.897 回答
0

我由 user2251060 提供的解决方案完成了这项工作。此外,Netflix 正在开发新版本的 Astyanax,它依赖于 Datastax Java 驱动程序将 thrift 对象转换为基于 CQL 的底层对象。您可以在https://github.com/Netflix/astyanax/wiki/Astyanax-over-Java-Driver找到更多信息

于 2014-11-23T20:48:55.530 回答