我正在运行一个查询,该查询可获取数百万行(5.000.000 左右)。我的节点似乎非常繁忙,因为协调器返回 com.datastax.driver.core.exceptions.ReadTimeoutException: Cassandra timeout during read query at consistency ONE (1 responses were required but only 0 replica responded)
异常(exception)。 (我真的不知道节点是否繁忙或发生其他事情)。
到目前为止,我已经尝试在每个 Cassandra 节点中设置更高的 read_request_timeout_in_millis,并像这样执行查询
new SimpleStatement("SELECT * FROM where date = ? ",param1)
.setFetchSize(pageSize).setConsistencyLevel(ConsistencyLevel.ONE)
.setReadTimeoutMillis(ONE_DAY_IN_MILLIS);
ResultSet resultSet = this.session.execute(statement);
但是异常仍然被抛出。我的下一步是尝试自定义 RetryPolicy,但是有人可以告诉我 readTimeout 重试是否会再次执行整个查询,还是会从失败的当前页面重试?
我正在尝试这样的事情:
@Override
public RetryDecision onReadTimeout(Statement statement, ConsistencyLevel cl, int requiredResponses, int receivedResponses, boolean dataRetrieved, int nbRetry) {
if (dataRetrieved) {
return RetryDecision.ignore();
} else if (nbRetry < readRetries) {
LOGGER.info("Retry attemp {} out of {} ",nbRetry,readRetries);
return RetryDecision.retry(cl);
} else {
return RetryDecision.rethrow();
}
}
其中 readReatries 是我尝试获取数据的重试次数。
最佳答案
当您在查询驱动程序上使用获取大小时,永远不会预先发出整个查询。即使您没有指定获取大小,驱动程序也会使用 5000 作为获取大小,以防止许多对象使内存过载。发生的情况是,结果 block 是通过发出带有限制的查询来获取的,当您迭代结果时,当您到达 block 末尾时,驱动程序将发出以下数量的结果查询,依此类推。总而言之,如果结果数大于获取大小,将从驱动程序向集群发出多个查询。很好的序列图以及其他解释可以在 official datastax driver page 上看到。 .
话虽如此,RetryPolicy
适用于单个语句,并且对获取大小一无所知,因此该语句将重试您定义的次数(意味着只有该 block 将在超时时重试) .
关于java - Datastax Cassandra java 驱动程序 RetryPolicy for Statement with paging,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39006050/