遍历结果集

时间:2016-01-07 14:00:05

标签: java cassandra cql spark-cassandra-connector

在遍历大小为100,000的结果集时,我反复收到此错误。我用过

.withReconnectionPolicy(new ConstantReconnectionPolicy(1000))
                .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
                .withQueryOptions(new QueryOptions().setFetchSize(2000))

在我的连接器中。我仍然得到这个错误。通常在获取80000行后失败。

  

com.datastax.driver.core.exceptions.NoHostAvailableException:全部   尝试查询失败的主机(尝试:/172.16.12.143:9042   (com.datastax.driver.core.exceptions.DriverException:超时   等待服务器响应),/ 172.16.12.141:9042   (com.datastax.driver.core.exceptions.DriverException:超时   等待服务器响应))   com.datastax.driver.core.exceptions.NoHostAvailableException.copy(NoHostAvailableException.java:65)     在   com.datastax.driver.core.DefaultResultSetFuture.extractCauseFromExecutionException(DefaultResultSetFuture.java:259)     在   com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:175)     在   com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:52)     在   com.payu.merchantAnalytics.FunnelHourlyUtilCql.groupByHourCql(FunnelHourlyUtilCql.java:87)     在   com.payu.merchantAnalytics.FunnelHourlyUtilCql.main(FunnelHourlyUtilCql.java:49)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:497)at   org.apache.spark.deploy.worker.DriverWrapper $。主要(DriverWrapper.scala:58)     在   org.apache.spark.deploy.worker.DriverWrapper.main(DriverWrapper.scala)   引起:   com.datastax.driver.core.exceptions.NoHostAvailableException:全部   尝试查询失败的主机(尝试:/172.16.12.143:9042   (com.datastax.driver.core.exceptions.DriverException:超时   等待服务器响应),/ 172.16.12.141:9042   (com.datastax.driver.core.exceptions.DriverException:超时   等待服务器响应))   com.datastax.driver.core.RequestHandler.sendRequest(RequestHandler.java:108)     在   com.datastax.driver.core.RequestHandler $ 1.run(RequestHandler.java:179)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)

解决 谢谢 Andy Tolbert的答案。使用SocketOptions.setReadTimeoutMillis(100000)设置readTimeoutMillis。

现在代码如下: -

SocketOptions socketOptions = new SocketOptions().setReadTimeoutMillis(100000);
Cluster.builder()
                .addContactPoints(nodes)
                .withReconnectionPolicy(new ConstantReconnectionPolicy(1000))
                .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
                .withQueryOptions(new QueryOptions().setFetchSize(2000))
                .withSocketOptions(socketOptions)
                .withCredentials(username, password).build();

非常感谢:)

0 个答案:

没有答案