我们使用java datastax cassandra驱动2.1.2
。我们使用的 Cassandra 版本是 2.0.9
。
我们有使用 QueryBuilder
构建的语句,我们正在明确地将一致性级别设置为 TWO
上的语句。
Select selectStatement = QueryBuilder.select().from(ARTICLES);
selectStatement.where(eq(ORGANIZATION_ID, organizationId));
selectStatement.setConsistencyLevel(ConsistencyLevel.TWO);
final ResultSet rs = session.execute(selectStatement);
//call to all() will be removed since it is enough to iterate over result set
//and then you get pagination for free instead of loading everything in
//memory
List<Row> rows = rs.all();
for (final Row row : rows) {
//do something with Row, convert to POJO
}
我们得到这样的异常:
com.datastax.driver.core.exceptions.ReadTimeoutException: Cassandra timeout during read query at consistency ALL (3 responses were required but only 2 replica responded)
com.datastax.driver.core.exceptions.ReadTimeoutException.copy (ReadTimeoutException.java:69)
com.datastax.driver.core.DefaultResultSetFuture.extractCauseFromExecutionException (DefaultResultSetFuture.java:259)
com.datastax.driver.core.ArrayBackedResultSet$MultiPage.prepareNextRow (ArrayBackedResultSet.java:279)
com.datastax.driver.core.ArrayBackedResultSet$MultiPage.isExhausted (ArrayBackedResultSet.java:239)
com.datastax.driver.core.ArrayBackedResultSet$1.hasNext (ArrayBackedResultSet.java:122)
com.datastax.driver.core.ArrayBackedResultSet.all (ArrayBackedResultSet.java:111)
我知道在 ResultSet
上调用 all()
会使它加载所有文章以在内存中组织并使用它并在 cassandra 上创建负载。如评论中所述,这将被删除。这可能会导致读取超时,但我仍然不明白为什么在异常消息中有 ALL
。
问题 是为什么当我们将原始语句设置为 TWO
时,异常告诉我们使用一致性级别 ALL
。 all()
是否在内部对查询执行某些操作并默认使用 CL ALL
?
最佳答案
你的问题几乎可以肯定是https://issues.apache.org/jira/browse/CASSANDRA-7947 .您会看到一条错误消息,表示无法执行读取修复。它与您原来的一致性级别无关。这在 2.1.3+ 中已修复。
关于java - 一致性级别 ALL 使用 while statement has consistency level TWO defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29673780/