使用Hector0.8.0时出现问题,请执行addCounter

时间:2011-06-21 09:04:37

标签: cassandra hector

我正在使用hector-core 0.8.0-1和Cassandra 0.8.0来测试addCounter操作,但是我发现我的代码无法将任何数据插入到CF中,有人能告诉我原因吗?

StringSerializer ser = StringSerializer.get();
Mutator<String> mutator = HFactory.createMutator(keyspace, ser);

List<HCounterColumn<String>> counterColumns = Arrays.asList(
        HFactory.createCounterColumn("1", 30L, ser),
        HFactory.createCounterColumn("2", 20L, ser)
        );  

for (HCounterColumn c : counterColumns)
{   
    mutator.addCounter("testKey1", "CounterColumn", c); 
    mutator.addCounter("testKey2", "CounterColumn", c); 
}   

mutator.execute();

我在日志中找到了以下信息:

> 2011-06-21 17:17:00,025 [Thread-3]
> INFO me.prettyprint.cassandra.hector.TimingLogger
> - Tag                                       Avg(ms) 
>      Min      Max  Std Dev     95th   Count 2011-06-21 17:17:00,030
> [Thread-3] INFO me.prettyprint.cassandra.hector.TimingLogger
> - WRITE.fail_                                  4.84 
>     4.84     4.84     0.00     4.84       1 2011-06-21 17:17:00,031 [Thread-3]
> INFO me.prettyprint.cassandra.hector.TimingLogger
> - META_WRITE.fail_                            17.20 
>    11.31    23.09     5.89    23.09       2 2011-06-21 17:17:00,031 [Thread-3]
> INFO me.prettyprint.cassandra.hector.TimingLogger
> -
执行mutator.execute();

时,

似乎有问题

提前致谢!

2 个答案:

答案 0 :(得分:5)

目前,在Cassandra 0.8.0中,您无法在未专门为处理计数器而创建的列族中创建计数器列:

create column family Counter1 with default_validation_class = CounterColumnType;

以下是JIRA参考:https://issues.apache.org/jira/browse/CASSANDRA-2614

答案 1 :(得分:2)

这样:

cfDef.setDefaultValidationClass(...)

这在最新版本的trunk,0.7.0和0.8.0分支中可用。

所以你需要从消息来源中获取。

或者,如果你想这样做,并且想要使用maven central提供的最新hector,你可以这样做

ThriftCfDef cfDef = new ThriftCfDef(String keyspace, String   columnFamilyName, ComparatorType comparatorType)

cf.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName());

cluster.addColumnFamiily(cfDef);