0
votes

If I have 2 datacentres, dc1 and dc2 with dc1 containing 2 nodes and dc2 containing 1 node; how will I define the replication factor in the keyspace if I want each node to have 2 replicas. for e.g. will I set dc1:2, dc2: 1 or dc1: 3, dc2:3

1
A node cannot have multiple replicas. If you want two replicas in a DC, then you need at least two nodes in that DC. - Aaron
Can I set the replication factor of a data center higher than the number of nodes in it i.e. suppose I've 2 data centers. dc1 has 3 nodes and dc2 has 2 nodes so can I set replication factor as dc1:4, dc2:1? - Vishal Sharma
You could, but it wouldn't help any. Plus your reads/writes will fail for anything done at consistency level ALL. In the 2 replicas on 1 node scenario from your original question, your reads/writes will fail for anything done at LOCAL_QUORUM. - Aaron
Excuse me if I'm bothering with silly questions but I wanted to understand whether, in case of a read query, consistency means that the given number of replica nodes are reachable/replying to a query or does it mean that the given number of replica nodes are providing the 'same' result for the query? I don't understand what you have stated above that reads/writes will fail for anything done at consistency level ALL. - Vishal Sharma

1 Answers

1
votes

In NetworkTopologyStragegy you set the number of replicas per datacenter you want. For your example:

CREATE KEYSPACE demo
  WITH REPLICATION = { 
   'class' : 'NetworkTopologyStrategy', 
   'dc1' : 1,
   'dc2' : 1 
  } ;

This will ensure that you will have two replicas of your data in your cluster. NetworkTopolgyStragegy will place one copy in dc1 and one in dc2. Of course this will put more data on your single node in dc2 as it has to hold all the data from both dc1 nodes.