带有 COUNT 查询的 Cassandra 超时

Cassandra Timeout with COUNT query

NOTE: I am having more than 15967908 records. I am a newbie to Cassandra. Reference:

嗨朋友们,我搜索了其他答案,但没有找到答案。他们提到我们需要增加 cassandra.yaml 文件的超时时间,但问题是我没有文件。

我已经用 HomeBrew 安装了 Cassandra。以下是我目前 运行 在我的 MacBook

上的版本
cqlsh:cassandra_training> show version;
[cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]

当我做

cqlsh:cassandra_training> select count(*) from access_point_logs;

然后出现如下错误

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

哪个文件我需要增加超时时间。因为我没有得到 cassandra.yaml 文件。

我的Cassandra安装路径如下

/usr/local/Cellar/cassandra/3.11.4

有什么方法可以统计记录数吗

简而言之,答案是否定的。您不应该 运行 在不指定任何键的情况下进行查询,因为这不是 Cassandra 的设计方式。

如果您只需要一个一次性号码,可以使用 nodetool tablestats

nodetool tablestats cassandra_training.access_point_logs

在输出中查找 "Number of keys (estimate)"。

以上命令将为您提供 table 中 分区键 的估计数量,因此这可能是也可能不是您要查找的内容。

如果您需要定期获取此号码,我通常会创建另一个 table 计数器并在您 add/remove 从另一个 table 记录时管理它。

我解决了这个问题。在创建 table 时,我没有正确添加 Primary KeyCluster Key 因为它显示了这种错误。

之前我用以下方式创建了一个 table 结构

create table access_point_logs (
    id bigint primary key,
    wd_number varchar,
    ip_address varchar,
    mac_address varchar,
    created_at timestamp,
    updated_at timestamp,
    access_point_id bigint
);

现改为如下

create table access_point_logs(
    id bigint,
    wd_number varchar,
    ip_address varchar,
    mac_address varchar,
    created_at timestamp,
    updated_at timestamp,
    access_point_id bigint,
    primary key ((wd_number), created_at, mac_address)
) with clustering order by (created_at desc);

以防万一像我这样的新手我想添加以下定义和示例以了解什么是分区键和什么是集群键

仔细观察下面的变化

primary key ((wd_number), created_at, mac_address);


Partition Key - wd_number

Cluster Key - created_at, mac_address

Partition Key - Which particular node to store the data in the Cluster.

Clustering Key - Mainly used for sorting the data and how to display default order while fetching the data.

Primary Key - Maybe a combination of Partition Key + Cluster Key or just a Partition Key

希望它能对某人有所帮助。如果有人有任何疑问,请随时开火。我会尽力回答这些问题。