This section discusses routine management and maintenance tasks.
The nodetool repair command repairs inconsistencies across all of the replicas for a given range of data. Repair should be run at regular intervals during normal operations, as well as during node recovery scenarios, such as bringing a node back into the cluster after a failure.
Unless Cassandra applications perform no deletes at all, production clusters require periodic, scheduled repairs on all nodes. The hard requirement for repair frequency is the value of gc_grace_seconds. Make sure you run a repair operation at least once on each node within this time period. Following this important guideline ensures that deletes are properly handled in the cluster.
Note
Repair requires heavy disk and CPU consumption. Use caution when running node repair on more than one node at a time. Be sure to schedule regular repair operations for low-usage hours.
In systems that seldom delete or overwrite data, it is possible to raise the value of gc_grace_seconds at a minimal cost in extra disk space used. This allows wider intervals for scheduling repair operations with the nodetool utility.
Cassandra allows you to add capacity to a cluster by introducing new nodes to the cluster in stages and by adding an entire data center. When a new node joins an existing cluster, it needs to know:
You set the Node and Cluster Initialization Properties in cassandra.yaml file. The location of this file depends on the type of installation; see Cassandra Configuration Files Locations or DataStax Enterprise Configuration Files Locations.
When you add a node to a cluster, it needs to know its position in the ring. There are several approaches for calculating tokens for new nodes:
The following steps describe adding a data center to an existing cluster. Before starting this procedure, please read the guidelines in Adding Capacity to an Existing Cluster above.
Ensure that you are using NetworkTopologyStrategy for all of your custom keyspaces.
For each new node, edit the configuration properties in the cassandra.yaml file:
If using the PropertyFileSnitch, update the cassandra-topology.properties file on all servers to include the new nodes. You do not need to restart.
The location of this file depends on the type of installation; see Cassandra Configuration Files Locations or DataStax Enterprise Configuration Files Locations.
Ensure that your client does not autodetect the new nodes so that they aren't contacted by the client until explicitly directed. For example in Hector, set hostConfig.setAutoDiscoverHosts(false);
If using a QUORUM consistency level for reads or writes, check the LOCAL_QUORUM or EACH_QUORUM consistency level to see if the level meets your requirements for multiple data centers.
After all nodes are running in the cluster:
Increasing the replication factor increases the total number of copies of keyspace data stored in a Cassandra cluster.
Update each keyspace in the cluster and change its replication strategy options. For example, to update the number of replicas in Cassandra CLI when using SimpleStrategy replica placement strategy:
[default@unknown] UPDATE KEYSPACE demo
WITH strategy_options = {replication_factor:3};
Or if using NetworkTopologyStrategy:
[default@unknown] UPDATE KEYSPACE demo
WITH strategy_options = {datacenter1:6,datacenter2:6};
On each node in the cluster, run nodetool repair for each keyspace that was updated. Wait until repair completes on a node before moving to the next node.
To replace a node that has died (due to hardware failure, for example), bring up a new node using the token of the dead node as described in the next procedure. This token used must already be part of the ring.
To replace a dead node:
Confirm that the node is dead using the nodetool ring command on any live node in the cluster.
Trying to replace a node using a token from a live node results in an exception. The nodetool ring command shows a Down status for the token value of the dead node:
Install Cassandra on the replacement node.
Remove any pre-existing Cassandra data on the replacement node:
sudo rm -rf /var/lib/cassandra/*
Configure any non-default settings in the node's cassandra.yaml to match your existing cluster.
Set the initial_token in the cassandra.yaml file to the value of the dead node's token -1. Using the value from the graphic in step 1, this is 28356863910078205288614550619314017621-1:
initial_token: 28356863910078205288614550619314017620
After the new node is up, run nodetool repair on each keyspace to ensure the node is fully consistent. For example:
$ nodetool repair -h 10.46.123.12 keyspace_name -pr
Remove the dead node.