首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >卡桑德拉-赫克托: java.lang.NoSuchFieldError: DEFAULT_MEMTABLE_THROUGHPUT_IN_MB

卡桑德拉-赫克托: java.lang.NoSuchFieldError: DEFAULT_MEMTABLE_THROUGHPUT_IN_MB
EN

Stack Overflow用户
提问于 2016-06-23 02:18:15
回答 1查看 899关注 0票数 0

我正在尝试创建cassandra数据库,但是无论我使用哪些版本的cassandra和hector,我都会得到以下错误:

代码语言:javascript
复制
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/:?]

这是我的密码:

代码语言:javascript
复制
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();
    }
}

}

有人知道我该怎么修吗?

我目前使用的是hector的0.8.0-2和cassandra的1.2.5版本

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2016-06-23 02:28:12

这很可能是因为您使用的是不兼容版本的Hector和Cassandra。您应该使用Hector 1.0-5和Cassandra1.2.5。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37981255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档