java CassandraHector InvalidRequestException
我正试图根据我的发现创建一个Cassandra数据库 here
但无论我做什么,我总是会犯这个错误
Caused by: me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:Keyspace names must be case-insensitively unique ("myKeyspace" conflicts with "myKeyspace")
这是我的密码:
public static void setSerializedMap(int index,String serializedVector){
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
ColumnFamilyDefinition columnFamilyDefinition=HFactory.createColumnFamilyDefinition("myKeyspace", "user", ComparatorType.BYTESTYPE);
KeyspaceDefinition keyspaceDefinition=HFactory.createKeyspaceDefinition("myKeyspace",ThriftKsDef.DEF_STRATEGY_CLASS,3,Arrays.asList(columnFamilyDefinition));
cluster.addKeyspace(keyspaceDefinition,true);
Keyspace keyspace=HFactory.createKeyspace("Keyspace", cluster);
Mutator<String> mutator = HFactory.createMutator(keyspace, me.prettyprint.cassandra.serializers.StringSerializer.get());
try{
mutator.addInsertion("cluster", "user", HFactory.createStringColumn("cluster-" + index, serializedVector));
}catch(HectorException e){
e.printStackTrace();
}
}
对如何修复它有什么建议吗
# 1 楼答案
在尝试创建“myKeyspace”之前,请检查它是否存在,如果已经存在,则无法创建
如果在创建时从多个位置/节点调用,它可能会在代码中创建竞争条件。如果可以升级,这将在CQL中解决
如果使用CQL,您可以使用“创建键空间如果不存在blarg WITH…”。虽然如果使用CQL可能想考虑从hector移动到为它设计的一个库。