在cassandra中创建计数器列族?

6tr1vspr  于 2021-06-14  发布在  Cassandra
关注(0)|答案(1)|浏览(394)

我正在使用cassandra-2.0.10和hector api。
我试过:

public static void createCounterColumnFamily(Keyspace keyspace, String ccfName) {   
    Mutator<String> mutator = HFactory.createMutator(keyspace,StringSerializer.get());
    mutator.addCounter("salary", ccfName, HFactory.createCounterColumn("salary", 10L));
    mutator.execute();}

但是,我有个例外:

Exception in thread "main" me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:unconfigured columnfamily counter_column_family_1)
    at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:45)
    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 com.cassandra.practice.CounterColumnFamily.createCounterColumnFamily(CounterColumnFamily.java:18)
    at com.cassandra.practice.Bootstrapper.main(Bootstrapper.java:33)
Caused by: InvalidRequestException(why:unconfigured columnfamily counter_column_family_1)
    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:243)
    at me.prettyprint.cassandra.service.Operation.executeAndSetResult(Operation.java:104)
    at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:258)
    ... 4 more

我错过什么了吗?

zqry0prt

zqry0prt1#

在插入数据之前,需要显式创建列族和键空间。
也就是说,hector api在五年前就被弃用了,而您使用的cassandra版本也同样落后。更重要的是,thrift api已经被完全弃用了很多年,并且在即将发布的4.0版本中已经从 Backbone.js 中删除。
请切换到cassandra的3.11.4版本:http://cassandra.apache.org/download/
使用cql和java驱动程序来实现以下功能:https://github.com/datastax/java-driver/tree/3.x/manual
出于好奇,您是如何发现当前使用的版本的?

相关问题