当前位置: 代码迷 >> java >> 用Java创建Hector集群
  详细解决方案

用Java创建Hector集群

热度:70   发布时间:2023-07-25 19:15:48.0

我正在尝试使用Hector的基本定义来创建Cassandra集群。 这是我的代码(仅连接和架构部分)。

CassandraHostConfigurator chc = new CassandraHostConfigurator(
       "localhost");
    chc.setMaxActive(20);
    chc.setCassandraThriftSocketTimeout(3000);
    chc.setMaxWaitTimeWhenExhausted(4000);    
    Cluster cluster = HFactory.getOrCreateCluster("mycluster", chc);
    System.out.println("cluster: " + cluster.getKnownPoolHosts(false));
    try{
        KeyspaceDefinition keyspaceDef = cluster.describeKeyspace("sensornetwork");
    } catch (HectorException he){
        ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("sensornetwork",
                                                                     "ColumnFamilyName",
                                                                     ComparatorType.BYTESTYPE);

        KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition("sensornetwork",
                                                                   ThriftKsDef.DEF_STRATEGY_CLASS,
                                                                   1,
                                                                   Arrays.asList(cfDef));    
        cluster.addKeyspace(newKeyspace, true);
   }


    // If keyspace does not exist, the CFs don't exist either. => create them.


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

我基本上是通过遵循自己网站上的Hector文档来完成此操作的。

我得到的错误是这个:

线程“主”中的异常me.prettyprint.hector.api.exceptions.HectorException:所有主机池均已标记。 重试负担被推送给客户端。 在me.prettyprint.cassandra.connection.HConnectionManager.getClientFromLBPolicy(HConnectionManager.java:401)在me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:232)在me.prettyprint.cassandra.service.ThriftCluster.addKeyspace (ThriftCluster.java:168)位于com.mycompany.mavenpails2.SpeedLayer.CassandraPrepwork(SpeedLayer.java:62)

显然,我正在创建一个没有工作池连接的集群。 我已经更改了端口并尝试了所有操作,但无法正常工作。 有什么建议么?

最有可能的“本地主机”没有节俭。 可能会想使用像这样的cql客户端。 否则,请确保在cassandra.yaml中启用了节俭功能

  相关解决方案