Cassandra-选择时无需复制 [英] Cassandra - Select without replication

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

问题描述

可以说我已经创建了一个键空间和表:

Lets say I've created a keyspace and table:

CREATE KEYSPACE IF NOT EXISTS keyspace_rep_0
    WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 0};

CREATE TABLE IF NOT EXISTS some_table (
    some_key ascii,
    some_data ascii,
    PRIMARY KEY (some_key)
);

我不需要此数据的任何副本。我可以以一致性级别 ANY 插入此表。但是我无法从该表中选择任何数据。

I don't want any replica of this data. I can insert into this table with consistency level ANY. But I couldn't select any data from this table.

以一致性级别 ANY 和 ONE 分别:

message="ANY ConsistencyLevel is only supported for writes"

message="Cannot achieve consistency level ONE"
   info={'required_replicas': 1, 'alive_replicas': 0, 'consistency': 1}

我尝试了其他读取一致性级别,但没有一个适合我。

I've tried other read consistency levels but none of them worked for me.

这与选择'replication_factor':1 并关闭节点非常相似。同样,我无法选择任何数据。所有读取一致性级别都需要至少一个副本。这是Cassandra的工作方式吗?您不能选择没有复制的数据吗?我缺少什么?

This is very similar to choosing 'replication_factor': 1 and shutting down a node. Again I couldn't select any data. All read consistency levels require at least one replica to be up. Is this how Cassandra works? You cannot select data without replication? What am I missing?

推荐答案

每个数据副本,包括原始副本,都是 a 副本。复制因子不是额外个副本的计数,而是总数个副本的数量。您需要RF> = 1。

Every copy of the data, including the original, is a replica. Replication factor is not a count of additional copies, it is the total number of copies. You need RF >= 1.

我很惊讶它允许RF ==0。在没有可用副本的情况下,没有任何内容可供读取。但是,对 CASSANDRA-4486 表示这是有意允许的,但出于特殊目的:

I'm rather surprised that it allows RF == 0. With no replicas available, there's nothing to read. However, a comment on CASSANDRA-4486 indicates that this is intentionally allowed, but for special purposes:


。 。 。关键是设置零复制键空间(在添加新数据中心时很常见)并在以后进行更改是合法的。同时,拒绝写入是正确的。

. . . the point is that it's legitimate to set up a zero-replication keyspace (this is common when adding a new datacenter) and change it later. In the meantime, it's correct to reject writes to it.

而且写入不会导致错误,可能是由于 有关一致性级别的说明中提到的 / a>,对于 ANY

And the write does not result in an error probably due to hinted handoff as mentioned in the descriptions for consistency levels, for ANY:


必须至少写入一次写入一个节点。如果给定分区键的所有副本节点均已关闭,则在写入提示的切换后,写入仍然可以成功。如果所有副本节点在写入时都处于关闭状态,则在该分区的副本节点恢复之前,ANY写入都是不可读的。

A write must be written to at least one node. If all replica nodes for the given partition key are down, the write can still succeed after a hinted handoff has been written. If all replica nodes are down at write time, an ANY write is not readable until the replica nodes for that partition have recovered.

,如果您想确认您的写操作被持久保存到至少一个节点并且不依赖所提示的切换(该操作可能会过期),请以一致性级别 ONE 而不是 ANY

So, if you want confirmation that your write was persisted to at least one node and not rely on the hinted handoff (which can expire), then write with consistency level ONE and not ANY.

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

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