【问题标题】:Datastax Cassandra java driver RetryPolicy for Statement with pagingDatastax Cassandra java驱动程序RetryPolicy for Statement with paging
【发布时间】:2016-12-24 16:01:03
【问题描述】:

我正在运行一个获取数百万行(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) 异常。 (我真的不知道节点是忙还是发生了其他事情)。

到目前为止,我已经尝试在每个 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 是我将尝试获取数据的重试次数。

【问题讨论】:

  • 你的页面大小是多少?
  • @fuggy_yama 我正在处理 100 行的页面大小。

标签: java cassandra datastax-java-driver


【解决方案1】:

当您在查询驱动程序上使用 fetch size 时,永远不会预先发出整个查询。即使您没有指定 fetch size,驱动程序也会使用 5000 作为 fetch size,以防止内存因许多对象而过载。正在发生的事情是,通过发出带限制的查询来获取结果块,当您迭代结果时,当您到达块驱动程序的末尾时,将发出查询以获取以下数量的结果等等。总而言之,如果结果数大于获取大小,则会从驱动程序向集群发出多个查询。在official datastax driver page 上可以看到漂亮的序列图以及其他解释。

话虽如此,RetryPolicy 适用于单个语句,并且对获取大小一无所知,因此该语句将被重试您定义的次数(意味着只有该块会在超时时重试)。

【讨论】:

  • 谢谢内纳德·博齐奇!考虑到这一点,我将尝试弄清楚如何迁移这数百万行。
  • 您可以查看我们的开源代码github.com/smartcat-labs/cassandra-migration-tool-java,它处理架构和数据迁移,我们广泛使用它来将数据从一个地方迁移到另一个地方。
猜你喜欢
  • 2018-02-15
  • 1970-01-01
  • 2017-07-13
  • 2014-05-04
  • 1970-01-01
  • 2016-02-27
  • 2017-01-20
  • 2017-08-12
  • 2021-02-09
相关资源
最近更新 更多