Lets say I've created a keyspace and table:

    WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 0};

    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?


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.

  • shouldnt it throw an error? when i run select * from system.schema_keyspaces it shows me strategy_options as {"replication_factor":"0"} and I am able to write into this table with ConsistenctLevel.ANY(at least does not throw en error) but i cant select any data. – Mustafa Genç Nov 25 '14 at 10:43
  • @MustafaGenç I would've thought so, too, but see edits in answer above. – William Price Nov 25 '14 at 10:51

Your Answer

