Cassandra OperationTimedOut [英] Cassandra OperationTimedOut

查看:766
本文介绍了Cassandra OperationTimedOut的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从my_table中选择计数(*)给我 OperationTimedOut:errors = {},last_host = 127.0.0.1

select count (*) from my_table gives me OperationTimedOut: errors={}, last_host=127.0.0.1

我已经尝试在cqlshrc.sample中更改cassandra.yaml中的 request_timeout_in_ms request_timeout 中的值。 (两者都在C:\Programs\DataStax-DDC\apache-cassandra\conf)但是没有成功。

I have already tried to change the values in request_timeout_in_ms in cassandra.yaml and request_timeout in cqlshrc.sample. (Both are in C:\Programs\DataStax-DDC\apache-cassandra\conf) But without success.

如何增加超时? p>

How can I increse timeout?

推荐答案

select count(*)不是你的想法。它实际上是昂贵的,因为它一行一行计数。您可以使用带有计数器的单独列族跟踪记录数,您需要为每个在表中执行的插入操作增加记录数。例如

select count (*) is not doing what you think. It is actually expensive as it counts the rows one by one. You can track number of records using a separate column family with a counter, which you will need to increment for every insert you do into your table. For example

CREATE TABLE IF NOT EXISTS my_table_counter (
  mykey text,
  count counter, 
  PRIMARY KEY (mykey)
);

然后对于每次插入到表中,执行计数器更新:

Then for every insert into your table, do counter update:

INSERT into my_table (mykey, mydata) VALUES (?, ?);
UPDATE my_table_counter SET count = count + 1 WHERE mykey = ?;

要获得计数:

SELECT count FROM my_table_counter WHERE mykey = ?

请注意,计数器不是幂等的,因此在罕见的失败情况下,过度计数。上面的代码假设你只插入一个新的键。

Note that counters are not idempotent, so in a rare event of a failure your data might be under or over-counted. Also the code above assumes that you only insert with a new key.

如果你需要一个精确的计数,Cassandra可能不是一个很好的适合。此外,如果您没有使用唯一键插入,您可能需要考虑使用轻量级事务插入(IF NOT EXISTS),并仅在应用事务时更新计数器。

If you need a precise counting, Cassandra may be not a good fit for that. Also if you are not inserting with unique keys you may need to consider using light weight transaction with insert (IF NOT EXISTS) and update a counter only if transaction was applied.

这篇关于Cassandra OperationTimedOut的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆