TechBuzzPro

How to Remove a Datacenter from a Cassandra Cluster

· 6 min read · Apps & Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Verify cluster health. Run nodetool status on any node in a remaining datacenter. Confirm all nodes in the datacenter you are removing are in the UN (Up Normal) state. If any node is down, fix it first; removing a datacenter with down nodes can cause data loss.
  2. 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.
  3. Update keyspace replication. For each keyspace, alter the replication to remove the datacenter. For example, if you have a NetworkTopologyStrategy with 'dc1': 3, 'dc2': 2 and you are removing dc2, run:
    ALTER KEYSPACE <keyspace_name> WITH REPLICATION = {'class': 'NetworkTopologyStrategy', 'dc1': 3};
    Repeat for all keyspaces, including system keyspaces like system_auth, system_distributed, and system_traces if they are replicated to that datacenter.
  4. Run repair on remaining datacenters. After changing RF, run nodetool repair on 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. Use nodetool repair -pr (primary range) on each node to avoid overlapping repairs.
  5. 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.
  6. Verify node removal. After each decommission, run nodetool status from a remaining node. The decommissioned node should disappear from the list. If it still shows as leaving, wait or investigate.
  7. 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 gossipinfo to 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 use nodetool assassinate for a node that is permanently down, but only after decommissioning has failed.
  8. 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.
  9. Monitor the cluster. For the next few hours, watch nodetool status and nodetool netstats to 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_auth are 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 -dc option to target only the remaining datacenters.
  • Use nodetool decommission -f to 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 netstats on 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 status and look for the node state. If it's stuck, you can restart the node and run nodetool decommission again. If it's permanently down, use nodetool assassinate with 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_auth was not updated. Alter the keyspace to replicate to the remaining datacenters and run repair on the system_auth keyspace.
  • 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.