【问题标题】:ReadTimeout: Error from server: code=1200 [Coordinator node timed out waiting for replica nodes' responses]ReadTimeout:来自服务器的错误:code=1200 [协调节点超时等待副本节点的响应]
【发布时间】:2020-02-04 19:16:50
【问题描述】:

我们创建了具有以下架构的表:

创建表 test_table(col_1 text, col_2 text, col_3 text, col_4 text, col_5 text, col_6 text, col_7 text, PRIMARY KEY (col_1, col_2, col_3, col_4, col_5));

此表包含近十亿条记录。(大量记录)

并尝试如下查询,

select * from test_table where col_1='value' and col_2='value'; --> 得到结果

但是当我们像下面这样尝试时,

select * from test_table where col_1='value' and col_3='value' 允许过滤; --> 没有得到结果

select * from test_table where col_1='value' and col_4='value' 允许过滤; --> 没有得到结果

我们遇到以下错误:

"ReadTimeout: 来自服务器的错误:code=1200 [协调节点超时等待副本节点的响应] message="操作超时 - 仅收到 0 个响应。" info={'received_responses': 0, 'required_responses': 1, '一致性': 'ONE'}"

出现上述错误后,我在 cassandra.yaml 配置文件中将超时参数从 5 秒延长到 60 分钟。

然后结果来了,但是执行时间很长,需要 50 分钟。

谁能建议我在不扩展配置的情况下解决“ReadTimeout:”问题?

【问题讨论】:

  • 当您简单地选择 where col1 = 'XXXXX' 时会发生什么?是超时还是结束?我的想法是,您正在做的事情与我刚刚要求您运行的事情相似,并且预计它会超时。我最初的预感是你可能有一个非常大的分区?如果您对该表执行“nodetool tablehistograms”或对该表执行“nodetool tablestats”会发生什么?
  • 当我在 col1 上运行查询时,我会在几秒钟内获得数据。没有超时。

标签: cassandra cqlsh


【解决方案1】:

您的分区和集群键是什么?它超时导致数据大小太大而无法在给定的超时时间内处理。尝试查看分页和二级索引。 尽管二级索引可能会降低 wright 的性能。

【讨论】:

  • 二级索引还有其他替代方案吗?如果表已经有 1 TB 数据,这有什么建议?
【解决方案2】:

通过使用“允许过滤”,您正在执行全表扫描,这会超时,这就是您遇到错误的原因。

您需要更改分区/集群键,以便在没有“允许过滤”参数的情况下运行查询。

当您只执行上面给定的查询时,您可以考虑将数据复制到 3 个表中:

create table test_table_1(col_1 text, col_2 text, col_3 text, col_4 text, col_5 text, col_6 text, col_7 text, PRIMARY KEY (col_1, col_2));
create table test_table_2(col_1 text, col_2 text, col_3 text, col_4 text, col_5 text, col_6 text, col_7 text, PRIMARY KEY (col_1, col_3));
create table test_table_3(col_1 text, col_2 text, col_3 text, col_4 text, col_5 text, col_6 text, col_7 text, PRIMARY KEY (col_1, col_4));

您的查询将是:

select * from test_table_1 where col_1='value' and col_2='value';
select * from test_table_2 where col_1='value' and col_3='value';
select * from test_table_3 where col_1='value' and col_4='value';

记住: 在 cassandra 中,您可以围绕查询设计表格。

【讨论】:

  • 我不能创建 3 个表,我必须用 1 个表来实现。如果该表中已经包含 1 TB 数据,那么二级索引是否适用于该场景?
猜你喜欢
  • 2019-07-14
  • 2016-01-16
  • 2021-04-29
  • 2015-08-15
  • 2017-08-21
  • 1970-01-01
  • 1970-01-01
  • 2021-02-07
  • 2020-11-06
相关资源
最近更新 更多