【问题标题】:Cassandra-Hector Single-Node Cluster HUnavailableException: : May not be enough replicas present to handle consistency levelCassandra-Hector 单节点集群 HUnavailableException: : 可能没有足够的副本来处理一致性级别
【发布时间】:2015-06-03 20:18:49
【问题描述】:

我正在尝试使用单节点集群创建一个 cassandra 数据库(我认为),但无论我设置的复制因子是什么值,我都会不断收到此错误:

me.prettyprint.hector.api.exceptions.HUnavailableException: : 可能没有足够的副本来处理一致性级别。

这是我的代码:

public static String[]getSerializedClusterMap(){
    Cluster cluster=HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
 //   Keyspace keyspace=HFactory.createKeyspace("KMeans", cluster);

    KeyspaceDefinition keyspaceDefinition=cluster.describeKeyspace("myKeyspace");

    if (cluster.describeKeyspace("myKeyspace")==null){
        ColumnFamilyDefinition columnFamilyDefinition=HFactory.createColumnFamilyDefinition("myKeyspace","clusters",ComparatorType.BYTESTYPE);
        KeyspaceDefinition keyspaceDefinition1=HFactory.createKeyspaceDefinition("myKeyspace",ThriftKsDef.DEF_STRATEGY_CLASS,1,Arrays.asList(columnFamilyDefinition));
        cluster.addKeyspace(keyspaceDefinition1,true);

    }

    Keyspace keyspace=HFactory.createKeyspace("myKeyspace", cluster);

    Mutator<String>mutator=HFactory.createMutator(keyspace, me.prettyprint.cassandra.serializers.StringSerializer.get());
    String[]serializedMap=new String[2],clusters={"cluster-0","cluster-1"};
    try{
        me.prettyprint.hector.api.query.ColumnQuery<String,String,String> columnQuery=HFactory.createStringColumnQuery(keyspace);
        for(int i=0;i<clusters.length;i++){
            columnQuery.setColumnFamily("user").setKey("cluster").setName(clusters[i]);
            QueryResult<HColumn<String,String>>result=columnQuery.execute();
            serializedMap[i]=result.get().getValue();
        }
    }catch (HectorException ex){
       ex.printStackTrace();
    }
    return serializedMap;
}

关于我应该做什么或复制因子的值应该是什么的任何建议?

运行后,'use keyspace "myKeyspace;'和'describe;',输出是:

    Keyspace: myKeyspace:
  Replication Strategy: org.apache.cassandra.locator.SimpleStrategy
  Durable Writes: true
    Options: [replication_factor:3]
  Column Families:
    ColumnFamily: user
      Key Validation Class: org.apache.cassandra.db.marshal.BytesType
      Default column value validator: org.apache.cassandra.db.marshal.BytesType
      Cells sorted by: org.apache.cassandra.db.marshal.BytesType
      GC grace seconds: 864000
      Compaction min/max thresholds: 4/32
      Read repair chance: 1.0
      DC Local Read repair chance: 0.0
      Populate IO Cache on flush: false
      Replicate on write: true
      Caching: KEYS_ONLY
      Bloom Filter FP chance: default
      Built indexes: []
      Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
      Compression Options:
        sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor

【问题讨论】:

  • 你能运行 cqlsh 并包含describe keyspace "myKeyspace" 的输出吗?此外,如果这是一个新应用程序,我强烈建议使用 cql 而不是 thrift
  • 我发布了上面的输出结果

标签: java cassandra hector


【解决方案1】:

您的密钥空间配置为 RF 为 3

选项:[replication_factor:3]

在 1 个节点的集群上,永远无法达到仲裁,因为它至少需要 2 个。将您的 rf 更改为 1 或使用一致性级别 ONE。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 2015-10-09
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    • 2016-06-20
    • 1970-01-01
    相关资源
    最近更新 更多