且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Cassandra-选择时无需复制

更新时间:2023-02-02 21:02:07

每个数据副本,包括原始副本,都是 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.