Snitches in Cassandra
In this article, we will discuss the Snitch and its types and Understanding how to configure the cassandra-topology.properties and cassandra-rackdc.properties files helps configure data centers and clusters.
In Cassandra Snitch is very useful and snitch is also helps in keep record to avoid storing multiple replicas of data on the same rack. In Cassandra, it is very important aspects to avoid multiple replica. In replication strategy we assign number of replica and also we define the data-center. This information is very helpful for snitch to identify the node and which rack belong to.
In Cassandra, snitch job is to determine which data centers and racks it should use to read data from and write data to. In Cassandra, all snitch are dynamic by default.
Types of Snitches:
In Cassandra, It is default snitch and good for development environments. It is unaware of datacenters or racks and also is not look for Cassandra-topologies.properties file and therefore is unusable for multi-datacenter environments.
In Cassandra, it is very important file snitch also recommends by datastax for production usage. This snitch also look for the Cassandra-topologies.properties file to identify the cluster inforamtion such that which data center and rack belong to then we configure in the cassandra-rackdc.properties file to the rest of the nodes using gossip.
We can configure the GossipingPropertyFileSnitch by editing the Cassandra-topologies.properties file.
Let’s have a look.
dc=DC1 rack=RACK1 prefer_local=true
Here, we are using dc and rack which refers to datacenter and rack and prefer_local=true refers to communicate with local IP adress while it is not communicating in multiple data center in order to limit the network bandwidth usage.
It is important snitch for deployments and it is a simple snitch for Amazon EC2 deployments where all nodes are in a single region. In Ec2Snitch region name refers to data center and availability zone refers to rack in a cluster.
In Cassandra, this snitch we use where the clusters span multiple regions and Ec2MultiRegionSnitch for Amazon EC2-based clusters.
In Cassandra, it is the snitch for a Cassandra deployment on the Google Cloud Platform (GCP) across a single or multiple regions. It is the snitch which supports GCP (Google Cloud Plateform).
In this snitch we find out the loaction by rack and datacenter. In this snitch the 3rd and 4th octets of IP address for example 10.40.08.230 corresponds to rack and datacenter. This is very useful snitch for writing custom snitch classes.
This snitch uses the cassandra-topology.properties file and we must define the nodes information by which we can Determines the closeness of the nodes.
We can identify nodes information based on the datacenter and rack which they belong to. To determine the closeness of the nodes The PropertyFileSnitch used the network definitions from the cassandra-topology.properties file.
It is the snitch which based on cloud and It is snitch for an Apache Cloudstack-based cluster.
Now, let’s understand the cassandra-topology.properties and the cassandra-rackdc.properties Files.
Understanding the cassandra-topology.properties and the cassandra-rackdc.properties Files:
It contains the topology of entire cluster and the information of the cassandra-topology.properties and the cassandra-rackdc.properties Files.
Let’s take an example.
dc = DC1 rack = RAC1 rack= RAC2
In below given example DC1 and DC2 are two physical datacenters and there are two rack for each of them. In Cassandra The PropertyFileSnitch uses the properties file which is cassandra-topologies.properties file to identify the cluster’s node. If we don’t identify cluster’s nodes in the cassandra-topologies.properties file then database assumes that data are in default datacenter and rack.
# datacenter One 10.40.08.230 = DC1:RAC1 10.30.11.231 = DC1:RAC1 10.54.06.232 = DC1:RAC1 18.104.22.168 = DC1:RAC2 22.214.171.124 = DC1:RAC2 126.96.36.199 = DC1:RAC2 # datacenter Two 188.8.131.52 = DC2:RAC1 184.108.40.206 = DC2:RAC1 220.127.116.11 = DC2:RAC1 18.104.22.168 = DC2:RAC2 22.214.171.124 = DC2:RAC2 126.96.36.199 = DC2:RAC2
The Cassandra-topologies.properties file is very important to update while we are going to add or delete nodes from cluster then to make aware that the nodes belong to which datacenter and rack. from performance perspective it is very important to keep record that information to Cassandra.
Here, we are going to describe the cassandra-rackdc.properties file: In above given example we are using following information of node.
Let’s have a look.
There are following snitch types look up the cassandra-rackdc.properties file for identifying the nodes cluster information such that which data center and which rack belong to.
Let’s have a look.
GossipingPropertyFileSnitch Ec2Snitch Ec2MultiRegionSnitch
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.