Cassandra - Select without replication

送分小仙女□ 提交于 2019-12-07 09:14:42

问题


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)
);

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.

I got the following errors when querying with consistency levels ANY and ONE, respectively:

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.

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?


回答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.

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.

And the write does not result in an error probably due to hinted handoff as mentioned in the descriptions for consistency levels, for 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.

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.



来源:https://stackoverflow.com/questions/27124284/cassandra-select-without-replication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!