Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replication in cassandra

How does replication work in Cassandra? If I have 3 racks and 3 RF with NetworkTopologyStratagy then will the data be replicated to all the 3 racks?

How exactly will data be replicated across the cluster? I ask because we are designing our cluster to cater for the worst case scenario that 2 of 3 racks go down, and we don't want to lose data.

We have only one datacenter with 3 racks.

If I use:

CREATE KEYSPACE "myKeyspaceName"
WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'DC1' : 3  }

Will this replicate to all three racks?

like image 553
Rock Avatar asked Dec 09 '22 08:12

Rock


2 Answers

In the Cassandra 1.0 docs, they have an article that explains this pretty well: About Replication in Cassandra.

I'll assume that you have two (logical?) datacenters. Let's say that you have two racks in one DC and the last rack in another, and on each RACK you have 2 nodes. You'll have these defined in your topology file to look something like this:

server1IP=DC1:RACK1
server2IP=DC1:RACK1
server3IP=DC2:RACK1
server4IP=DC2:RACK1
server5IP=DC2:RACK2
server6IP=DC2:RACK2

If you want to have 3 copies of the data out there (one for each logical rack) then you'll define your keyspace to use the NetworkTopologyStrategy, with replications settings for each DC, like this:

CREATE KEYSPACE "myKeyspaceName"
WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'DC1' : 1, 'DC2' : 2};

The PropertyFile snitch is also "rack aware," so when a write occurs it will make sure that one copy of the data is on a node in RACK1 in DC1, and one copy is on each RACK in DC2. Based on what you are saying, it might make sense to have three logical datacenters, each with one rack.

You should also have a look at this doc in the "Choosing Keyspace Replication Options" section that further explains how to configure replication.

EDIT:

If I use the CREATE KEYSPACE "myKeyspaceName" WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', replicationfactor: 3 }. Will this replicate to all the three racks?

I'm not sure. But every example I'm finding about defining a keyspace's replication strategy using NetworkTopologyStrategy with only one DC, specifically names the DC instead of stating "replicationfactor." Even the doc I linked states:

NetworkTopologyStrategy takes as options the number of replicas you want per data center. Even for single data center (or single node) clusters, you can use this replica placement strategy and just define the number of replicas for one data center.

So assuming that you name your DC DC1, it would look like this:

CREATE KEYSPACE "myKeyspaceName"
WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'DC1' : 3}

If you did that, and had your three racks defined underneath that DC, this will replicate one copy to all three racks.

like image 55
Aaron Avatar answered Dec 11 '22 10:12

Aaron


Replication is completely dependent on the replication strategy of your keyspace and the layout of your cluster. This layout is defined by two things, Datacenters and Racks. Datacenters are group of racks which should be treated as though they are separate from the other machines.

For example if you have 3 datacenters, You can specify (Using Network Topology Strategy) that each of those datacenters should have a strict number of copies of the data. One typical strategy is to specify that each datacenter have an RF of 3. In this situation you would end up with 9 copies total.

Racks only help the cluster figure out where to place replica's within a datacenter. When possible C* tries to put replicas within a datacenter on separate racks.

Whether or not your service is available (reads and writes are possible) is dependent on the consistency level you choose for client operations. Consistency level of One requires only one replica to be online, Quorum requires 1/2 of total replicas + 1. Most folks using NetworkTopologyStrategy use Local_One or Local_Quorum (1/2 of the nodes in the contacted DC + 1) which minimize cross DC traffic.

Calculator to figure out how many nodes go down before you have unavailable exceptions

Replication

Consistency

like image 44
RussS Avatar answered Dec 11 '22 10:12

RussS