cassandra的cqlsh控制台中的操作超时错误

我有三个节点Cassandra Cluster,我创建了一个有超过2,000,000行的表。

当我在cqlsh中执行此操作( select count(*) from userdetails )查询时,出现此错误:

OperationTimedOut:errors = {},last_host = 192.168.1.2

当我为较少的行或限制50,000运行计数function时它工作正常。

count(*)实际上遍历所有数据。 因此, select count(*) from userdetails没有限制的select count(*) from userdetails预计将超过那么多行。 这里有一些细节: http : //planetcassandra.org/blog/counting-key-in-cassandra/

您可能需要考虑使用Spark自己维护计数,或者如果您只想要一个球场号码,您可以从JMX获取它。

要从JMX中获取它可能有点棘手,具体取决于您的数据模型。 要获取分区数,请获取org.apache.cassandra.metrics:type=ColumnFamily,keyspace={{Keyspace}},scope={{Table​}},name=EstimatedColumnCountHistogram mbean并汇总所有90个值(这个是nodetool cfstats输出的内容)。 它只会给你sstables中存在的数字,以便更准确地你可以执行刷新或尝试从MemtableColumnsCount mbean估计memtables中的MemtableColumnsCount

您还可以在cqlsh命令中增加超时,例如:

 cqlsh --request-timeout 120 myhost 

要在Apache Cassandra中更改客户端超时限制,有两种方法:

技巧1:修改cqlshrc文件。

技巧2:打开程序cqlsh并使用client_timeout变量修改指定的时间。

有关详细信息,请参阅链接: https : //playwithcassandra.wordpress.com/2015/11/05/cqlsh-increase-timeout-limit/

如果你使用cqlsh:在编辑器中打开脚本并找到所有单词“timeout”。 将默认值从10更改为60并保存脚本。

我正在使用Cassandra 3.4和cqlsh来获取记录计数。 似乎3.4中的代码发生了变化。 cqlsh只调用cqlsh.py。 在cqlsh.py中有一个DEFAULT_REQUEST_TIMEOUT_SECONDS变量,默认为10(秒)。 我将其更改为3600(1小时),现在我的SELECT count(*)查询工作。

如果我计算一天的话会遇到与你相同的问题,但作为一种解决方法,我将计数分成两个请求(12小时+ 12小时),如下图所示。

 cqlsh:jw_schema1> select count(*) from flight_statistics where insert_time >= '2015-08-20 00:00:00' and insert_time <= '2015-08-20 11:59:59' ALLOW FILTERING; count ------- 42528 (1 rows) cqlsh:jw_schema1> select count(*) from flight_statistics where insert_time >= '2015-08-20 12:00:00' and insert_time <= '2015-08-20 23:59:59' ALLOW FILTERING; count ------- 86580 (1 rows) cqlsh:jw_schema1>