Search code examples
cassandrahector

Problem when using Hector0.8.0 do addCounter


I'm using hector-core 0.8.0-1 and Cassandra 0.8.0 to test a addCounter operation, but I found my code cannot insert any data into the CF, can anyone tell me the reason?

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

and I found the following info in my log:

> 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
> -

seems something wrong while doing mutator.execute();

Thanks in advance!


Solution

  • This way:

    cfDef.setDefaultValidationClass(...)
    

    This is available in the latest version of trunk, 0.7.0 and 0.8.0 branch.

    So you need to pull from sources.

    or, if you want to do that, and assoming you are using the latest hector available at maven central, you can do this

    ThriftCfDef cfDef = new ThriftCfDef(String keyspace, String   columnFamilyName, ComparatorType comparatorType)
    
    cf.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName());
    
    cluster.addColumnFamiily(cfDef);