Я пытаюсь создать базу данных Cassandra, но независимо от того, какие версии Кассандры и Гектора я использую я получаю следующее сообщение об ошибке:Cassandra-Гектор: java.lang.NoSuchFieldError: DEFAULT_MEMTABLE_THROUGHPUT_IN_MB
java.lang.NoSuchFieldError: DEFAULT_MEMTABLE_THROUGHPUT_IN_MB
at me.prettyprint.cassandra.service.ThriftCfDef.<init>(ThriftCfDef.java:119) ~[hector-core-0.8.0-2.jar:?]
at me.prettyprint.cassandra.service.ThriftCfDef.<init>(ThriftCfDef.java:125) ~[hector-core-0.8.0-2.jar:?]
at me.prettyprint.hector.api.factory.HFactory.createColumnFamilyDefinition(HFactory.java:679) ~[hector-core-0.8.0-2.jar:?]
at Databases.NoSQL.CassandraDB.AuthorsAndFeaturesCassandraSchema.writeAuthorsAndFeaturesPerKeywordToCassandraDB(AuthorsAndFeaturesCassandraSchema.java:87) ~[classes/:?]
Вот мой код:
public class AuthorsAndFeaturesCassandraSchema {
public static StringSerializer stringSerializer=new StringSerializer();
public static String[] readAuthorsAndFeaturesPerKeywordFromCassandraDB(){
CassandraHostConfigurator hostConfigurator=new CassandraHostConfigurator("localhost:9160");
Cluster cluster= HFactory.getOrCreateCluster("TestCluster","localhost:9160");
KeyspaceDefinition keyspaceDefinition=cluster.describeKeyspace("authorAndFeaturesKeyspace");
if(cluster.describeKeyspace("authorAndFeaturesKeyspace")==null){
ColumnFamilyDefinition columnFamilyDefinition=HFactory.createColumnFamilyDefinition("authorAndFeaturesKeyspace","authorAndFeaturesKeyword", ComparatorType.BYTESTYPE);
KeyspaceDefinition keyspaceDefinition1=HFactory.createKeyspaceDefinition("authorAndFeaturesKeyspace", ThriftKsDef.DEF_STRATEGY_CLASS,1, Arrays.asList(columnFamilyDefinition));
cluster.addKeyspace(keyspaceDefinition1,true);
}
ConfigurableConsistencyLevel configurableConsistencyLevel=new ConfigurableConsistencyLevel();
Map<String,HConsistencyLevel> consistencyLevelMap=new HashMap<String, HConsistencyLevel>();
consistencyLevelMap.put("AUTHOR_AND_FEATURES",HConsistencyLevel.ONE);
configurableConsistencyLevel.setReadCfConsistencyLevels(consistencyLevelMap);
configurableConsistencyLevel.setWriteCfConsistencyLevels(consistencyLevelMap);
me.prettyprint.hector.api.Keyspace keyspace=HFactory.createKeyspace("authorAndFeaturesKeyspace",cluster,configurableConsistencyLevel);
String[] serializedauthorsAndFeaturesHashmap=new String[3],authorsAndFeatures={"authorAndFeaturesKeyword-1","authorAndFeaturesKeyword-2","authorAndFeaturesKeyword-3"};
try {
ColumnQuery<String,String,String> columnQuery=HFactory.createStringColumnQuery(keyspace);
for(int i=1;i<=authorsAndFeatures.length;i++){
columnQuery.setColumnFamily("AUTHOR_AND_FEATURES").setKey("authorsAndFeaturesKeyword").setName(authorsAndFeatures[i]);
QueryResult<HColumn<String,String>>result=columnQuery.execute();
if(result==null){
return null;
}
HColumn<String,String>column=result.get();
if(column==null){
return null;
}
serializedauthorsAndFeaturesHashmap[i]=column.getValue();
}
}catch (HectorException e){
e.printStackTrace();
}
return serializedauthorsAndFeaturesHashmap;
}
public static void writeAuthorsAndFeaturesPerKeywordToCassandraDB(String serializedAuthorsAndFeaturesPerKeywordHashmap,int index){
CassandraHostConfigurator hostConfigurator=new CassandraHostConfigurator("localhost:9160");
Cluster cluster=HFactory.getOrCreateCluster("TestCluster","localhost:9160");
ConfigurableConsistencyLevel configurableConsistencyLevel=new ConfigurableConsistencyLevel();
Map<String,HConsistencyLevel>consistencyLevelMap=new HashMap<String, HConsistencyLevel>();
consistencyLevelMap.put("AUTHOR_AND_FEATURES",HConsistencyLevel.ONE);
configurableConsistencyLevel.setReadCfConsistencyLevels(consistencyLevelMap);
configurableConsistencyLevel.setWriteCfConsistencyLevels(consistencyLevelMap);
KeyspaceDefinition keyspaceDefinition=cluster.describeKeyspace("authorAndFeaturesKeyspace");
if(cluster.describeKeyspace("authorAndFeaturesKeyspace")==null){
ColumnFamilyDefinition columnFamilyDefinition=HFactory.createColumnFamilyDefinition("authorAndFeaturesKeyspace","authorAndFeaturesKeyword",ComparatorType.BYTESTYPE);
KeyspaceDefinition keyspaceDefinition1=HFactory.createKeyspaceDefinition("authorAndFeaturesKeyspace",ThriftKsDef.DEF_STRATEGY_CLASS,1,Arrays.asList(columnFamilyDefinition));
cluster.addKeyspace(keyspaceDefinition1,true);
}
me.prettyprint.hector.api.Keyspace keyspace=HFactory.createKeyspace("authorAndFeaturesKeyspace",cluster,configurableConsistencyLevel);
Mutator<String>mutator=HFactory.createMutator(keyspace,StringSerializer.get());
try {
mutator.insert("authorAndFeaturesKeyword","AUTHOR_AND_FEATURES",HFactory.createStringColumn("authorAndFeaturesKeyword-"+index,serializedAuthorsAndFeaturesPerKeywordHashmap));
}catch (HectorException e){
e.printStackTrace();
}
}
}
кто-нибудь знает, как я могу это исправить?
настоящее время я использую Гектора 0.8.0-2 и 1.2.5 версии Кассандры
Спасибо заранее
Не должно быть оснований для написания чего-либо в Гекторе, поскольку он давно устарел. Проект Гектор на GitHub не совершил фиксацию почти за 2 года, и его readme даже говорит, что его больше нельзя использовать. Ваши самые высокие шансы на успех будут заключаться в использовании Cassandra 2.1.14 с драйвером DataStax Java. – Aaron