Cassandra 数据库 Datastax 协调器节点超时?

Cassandra Database Datastax Coordinator node timed out?

我收到以下错误。

cassandra.ReadTimeOut: Error from server: code =1200 [Coordinator node timed out waiting for replica nodes' responses] message = Operation timed out - received only 0 responses." info={consistency: 'LOCAL_ONE',required_responses": 1, 'received_responses": 0}

这是查询 运行

query = "select col1,col2,col3,col4 from table where timestamp >= last_hour and <= current_hour ALLOW FILTERING"

last_hour 和 current_hour 是获取当前时间和最近 1 小时时间的变量。

那我做

queryResult = session.execute_async(query)

并收到错误。

它有时会成功运行,而其他时候会抛出该错误。

主要原因是您错误地使用了Cassandra。仅当您仅执行特定分区的读取时,它才能快速运行。但是在你的情况下,你对非分区列有一个条件(或者即使它是一个分区,你也不能对其进行范围查询),这会导致 Cassandra 扫描数据库中的所有数据(在所有节点上)得到你的结果。对于合理数量的数据,这会花费大量时间,并导致超时。

Cassandra数据建模的第一条规则是"if you use ALLOW FILTERING, you're doing something wrong"...

我建议学习 DataStax Academy 上的 DS201 和 DS220 课程,以了解 Cassandra 的工作原理,以及如何为其设计数据模型。