Cassandra hector连接打开时出错:“无法分配请求的地址”

时间:2013-09-26 09:34:21

标签: cassandra database-connection hector

我正在尝试打开新连接并执行以下更新:

for(String str: queries){
    query = getQuery(str);
    TTransport tx_CUCR = getNewTransaction();
    try {
        System.out.println("opening...");
        tx_CUCR.open();
        CqlQuery<String, String, ByteBuffer> cqlQuery = new CqlQuery<String, String, ByteBuffer>(keyspace, StringSerializer.get(), StringSerializer.get(), ByteBufferSerializer.get());
        cqlQuery.setQuery(query);
        System.out.println("executing...");
        QueryResult<CqlRows<String, String, ByteBuffer>> result = cqlQuery.execute();
        if (null != result) {
            rows = result.get();
        }
        System.out.println("flushing...");
        tx_CUCR.flush();
    } catch (HectorException e) {
        e.printStackTrace();
        translateException(e);
    } catch (TTransportException e) {
        e.printStackTrace();
    } finally {
        tx_CUCR.close();
    }
}

其中queries包含50万个密钥。在运行for循环时,在几次成功更新后,在打开新连接时会出现以下错误:

opening...
org.apache.thrift.transport.TTransportException: java.net.NoRouteToHostException: Cannot assign requested address
    at org.apache.thrift.transport.TSocket.open(TSocket.java:183)
    at org.apache.thrift.transport.TFramedTransport.open(TFramedTransport.java:81)
    at com.germinait.influence.cassandra.utils.CassandraUtils.executeQuery(CassandraUtils.java:546)
    at com.germinait.influence.cassandra.utils.CassandraUtils.updateByKey(CassandraUtils.java:484)
    at com.germinait.influence.cassandra.utils.IACassandraUtils.update(IACassandraUtils.java:298)
    at com.germinait.influence.cassandra.utils.IACassandraUtils.updateNodeScores(IACassandraUtils.java:274)
    at com.germinait.influence.cassandra.data.IACassBONodeScores.commit(IACassBONodeScores.java:94)
    at com.germinait.influence.facebook.db.updates.UpdateWithinGraph.initScores(UpdateWithinGraph.java:1048)
    at com.germinait.influence.facebook.db.updates.UpdateWithinGraph.initializePersonInfluenceScores(UpdateWithinGraph.java:981)
    at com.germinait.influence.facebook.db.updates.UpdateWithinGraph.applyInfluenceRankAlgo(UpdateWithinGraph.java:726)
    at com.germinait.influence.utils.IAUpdateUtils.runAlgorithm(IAUpdateUtils.java:296)
    at com.germinait.influence.NetworkIAMain.IA_runAlgorithm(NetworkIAMain.java:422)
    at com.germinait.influence.NetworkIAMain.main(NetworkIAMain.java:587)
Caused by: java.net.NoRouteToHostException: Cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
    at java.net.Socket.connect(Socket.java:546)
    at org.apache.thrift.transport.TSocket.open(TSocket.java:178)
    ... 12 more

如果我暂停,在调试时,异常一段时间然后继续,它会继续进行几次下一次更新并成功完成,然后再在另一个点再次导致此异常。

我怎样才能克服这个?

0 个答案:

没有答案