How to Remove a Datacenter from a Cassandra Cluster
In this article
Removing a datacenter from a Cassandra cluster decommissions all nodes in that datacenter and updates the cluster metadata so the remaining datacenters continue to operate correctly. This is needed when consolidating infrastructure, decommissioning a region, or migrating to a new topology. Before starting, ensure you have SSH access to all nodes, the Cassandra binaries available, and a recent backup of the schema and data if the datacenter holds the only copy of any keyspace.
What You'll Need
- SSH access to every node in the datacenter being removed
- Cassandra binaries (nodetool) on each node or a control node with remote access
- Credentials for a superuser account (if authentication is enabled)
- Network access between nodes on the gossip and storage ports (usually 7000, 7001, 9042, 9142)
- A clear understanding of your keyspace replication factors (RF) across datacenters
Step-by-Step
- Verify cluster health. Run
nodetool statuson any node in a remaining datacenter. Confirm all nodes in the datacenter you are removing are in theUN(Up Normal) state. If any node is down, fix it first; removing a datacenter with down nodes can cause data loss. - Check replication settings. For each keyspace, run
DESCRIBE KEYSPACE <keyspace_name>in cqlsh. Note the replication strategy and the replication factor for the datacenter you are removing. If the RF for that datacenter is greater than 0, you must change it to 0 before decommissioning. - Update keyspace replication. For each keyspace, alter the replication to remove the datacenter. For example, if you have a NetworkTopologyStrategy with
'dc1': 3, 'dc2': 2and you are removingdc2, run:ALTER KEYSPACE <keyspace_name> WITH REPLICATION = {'class': 'NetworkTopologyStrategy', 'dc1': 3};Repeat for all keyspaces, including system keyspaces likesystem_auth,system_distributed, andsystem_tracesif they are replicated to that datacenter. - Run repair on remaining datacenters. After changing RF, run
nodetool repairon each node in the remaining datacenters. This ensures that all data that was previously replicated to the removed datacenter is now fully replicated among the remaining replicas. Usenodetool repair -pr(primary range) on each node to avoid overlapping repairs. - Decommission each node in the datacenter. On each node in the datacenter being removed, run
nodetool decommission. This streams the node's data to other replicas (if any) and then removes the node from the ring. Wait for the command to complete fully before moving to the next node. Do not shut down the node until the decommission finishes. - Verify node removal. After each decommission, run
nodetool statusfrom a remaining node. The decommissioned node should disappear from the list. If it still shows as leaving, wait or investigate. - Remove the datacenter from the cluster metadata. Once all nodes are decommissioned, the datacenter may still appear in the gossip information. On any remaining node, run
nodetool gossipinfoto check. If the datacenter still appears, you can force a gossip resync by restarting one node in each remaining datacenter. In some versions, you may need to usenodetool assassinatefor a node that is permanently down, but only after decommissioning has failed. - Update client configuration. Ensure your application connection strings and any driver policies no longer reference the removed datacenter. Update load-balancing policies if they specify datacenter awareness.
- Monitor the cluster. For the next few hours, watch
nodetool statusandnodetool netstatsto ensure no unexpected streaming or repair activity. Check logs for errors.
Common Mistakes
- Not changing replication factor first. If you decommission nodes while the keyspace still has RF > 0 for that datacenter, the decommission will try to stream data to other nodes in the same datacenter, which may not exist, causing failure or data loss.
- Decommissioning nodes in parallel. Running decommission on multiple nodes simultaneously can overload the cluster and cause streaming failures. Always do one node at a time.
- Skipping repair. Without a repair, some data might not be fully replicated to the remaining datacenters, leading to inconsistency after the removal.
- Forgetting system keyspaces. System keyspaces like
system_authare often replicated to all datacenters. If you don't update them, authentication may break. - Shutting down a node during decommission. Interrupting the process can leave the node in a leaving state and cause the cluster to think it is still there.
Tips
- Always back up your schema (
cqlsh -e 'DESCRIBE SCHEMA') before making changes. - Perform the operation during a maintenance window to minimize impact on applications.
- If you have a multi-datacenter setup, consider running repair with
-dcoption to target only the remaining datacenters. - Use
nodetool decommission -fto force if the node is unresponsive, but only as a last resort. - After removal, update any monitoring or alerting that expects the old datacenter.
Troubleshooting
- Decommission hangs. Check
nodetool netstatson the node to see if streaming is in progress. If it's stuck, wait; if it's not moving, check the logs. You may need to restart the node and try again. - Node still shows as leaving after decommission. Run
nodetool statusand look for the node state. If it's stuck, you can restart the node and runnodetool decommissionagain. If it's permanently down, usenodetool assassinatewith the node's IP, but only after confirming it is safe. - Data loss after removal. If you suspect data loss, restore from backup. To prevent this, always ensure RF is set to 0 for the removed datacenter and repair is done before decommissioning.
- Authentication fails after removal. This usually means
system_authwas not updated. Alter the keyspace to replicate to the remaining datacenters and run repair on thesystem_authkeyspace. - Gossip still shows the old datacenter. Restart one node in each remaining datacenter to clear gossip state. If it persists, check for any leftover nodes in the ring with
nodetool status.
Frequently Asked Questions
Can I remove a datacenter without stopping the cluster?
Yes, the process is designed to be online. You decommission nodes one by one while the cluster continues serving requests.
What happens to the data that was stored in the removed datacenter?
If the keyspace replication factor for that datacenter was set to 0 before decommissioning, the data is already replicated elsewhere. If it was the only copy, the data is lost—that's why you must change RF and repair first.
Do I need to remove the datacenter from the gossip configuration?
Cassandra doesn't have a separate config file for datacenters; it learns them via gossip. Once all nodes are decommissioned, the datacenter disappears from the cluster after a gossip resync, usually within minutes.
Can I add the datacenter back later?
Yes, you can add new nodes with the same datacenter name, and they will join the cluster. You'll need to update keyspace replication to include that datacenter again.
How long does the process take?
It depends on the amount of data to stream and cluster load. A small datacenter might take minutes; a large one with many nodes and data can take hours.
Is it safe to use nodetool assassinate?
Only if the node is permanently down and cannot be decommissioned. It forcefully removes the node from the ring, but can cause inconsistencies if the node is actually alive. Use as a last resort.