java - Cassandra-Hector 单节点集群 HUnavailableException : : May not be enough replicas present to handle consistency level

标签 java cassandra hector

我正在尝试使用单节点集群创建 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;'和“描述;”,输出是:

    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

最佳答案

您的 key 空间配置的 RF 为 3

Options: [replication_factor:3]

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

关于java - Cassandra-Hector 单节点集群 HUnavailableException : : May not be enough replicas present to handle consistency level,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29352612/

相关文章:

cassandra - Cassandra 连接的健康检查(使用 hector)?

scala - Cassandra 切片查询不适用于复合键

solr - 如何通过查询更新solr索引?

java - 从文本字段获取文本并使用 BufferedReader 对象传递到字符串

java - Java 类的单个实例

java - 可以维护插入顺序,过滤掉重复元素并轻松删除第一个元素的数据结构?

java - cassandra快照时出现打开文件过多的情况

c - 无法使用 Cassandra 的 C 驱动程序连接到 key 空间

ubuntu - 由于 sstable 损坏,无法启动 Cassandra

java - 如何禁止两个 JTable 之间的拖放?