我在遍历大小为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.2.12.141:9042(com.datastax.driver.core.exceptions.DriverException:超时等待服务器响应))com.datastax.driver.core.exceptions.NoHostAvailableException.copy(NoHostAvailableException.java:65) at com.datastax.driver.core.DefaultResultSetFuture.extractCauseFromExecutionException(DefaultResultSetFuture.java:259)at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:175)at com.datastax.driver.core.AbstractSession.execute (AbstractSession.java:52)at com.payu.merchantAnalytics.FunnelHourlyUtilCql.groupByHourCql(FunnelHourlyUtilCql.java:87)at com.payu.merchantAnalytics.FunnelHourlyUtilCql.main(FunnelHourlyUtilCql.java:49)at sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在sun.reflect.NativeM ethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)位于org.apache.spark.deploy的java.lang.reflect.Method.invoke(Method.java:497)的sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) .worker.DriverWrapper $ .main(DriverWrapper.scala:58)at org.apache.spark.deploy.worker.DriverWrapper.main(DriverWrapper.scala)引起:com.datastax.driver.core.exceptions.NoHostAvailableException:所有主机(s)尝试查询失败(尝试:/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)at com.datastax.driver.core.RequestHandler $ 1.run(RequestHandler.java) :179)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExe) cutor.java:617)at java.lang.Thread.run(Thread.java:745)


Solved 谢谢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();

非常感谢 :)