Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

nodetool cleanup

Removes data that no longer belongs to this node after a topology change, such as adding new nodes to the cluster.


Terminal window
nodetool [connection_options] cleanup [options] [--] [keyspace [table ...]]

See connection options for connection options.

nodetool cleanup scans SSTables and removes any data where the token is no longer owned by the local node. This is necessary after adding nodes to the cluster, as token ranges are redistributed and some data becomes redundant on existing nodes.

When cluster topology changes occur (such as adding new nodes or decommissioning nodes), Cassandra streams data to ensure the replication factor is maintained on the appropriate nodes. However, Cassandra does not automatically remove data that is no longer relevant to a node after a topology change.

Consider this scenario when adding a new node:

  1. Before: Node A owns token range 1-100
  2. After adding Node B: Node A now owns 1-50, Node B owns 51-100
  3. Cassandra streams data for range 51-100 to Node B
  4. Node A still retains the data for range 51-100 even though it no longer owns those tokens

This stale data:

  • Consumes disk space unnecessarily
  • Is not served to clients (queries route to the correct token owner)
  • Will eventually be removed during normal compaction, but this can take a long time
  • May cause confusion when analyzing disk usage

The cleanup command explicitly scans all SSTables and removes partitions whose tokens are no longer owned by the local node, reclaiming disk space immediately rather than waiting for compaction to eventually remove the data.

Automatic vs Manual Cleanup

While compaction will eventually remove data outside the node's token ranges, this process is not predictable and depends on compaction strategy and workload patterns. Running cleanup ensures immediate removal and predictable disk space recovery.


ArgumentDescription
keyspaceKeyspace to clean up. If omitted, cleans all keyspaces
tableSpecific table(s) to clean. If omitted, cleans all tables

OptionDescription
-j, --jobsNumber of concurrent cleanup jobs (default: 2)

Recommended After Scaling Up

After adding nodes and bootstrap completes:

Terminal window
# Run on each EXISTING node (not the new node)
nodetool cleanup

This reclaims disk space by removing data now owned by new nodes.

StepNodeActionNotes
1New NodeBootstrap completesNode has streamed data for its token ranges
2Existing Node 1nodetool cleanupRemoves data now owned by new node
3Existing Node 2nodetool cleanupRemoves data now owned by new node

Sequential Execution

Run cleanup sequentially on each existing node (not in parallel).

When migrating data between clusters, run cleanup on the source after the target has received data.


Not Needed After Node Removal

When nodes are removed (decommission or removenode), remaining nodes receive additional data—they don't have excess data to clean up.

Never run cleanup while a new node is still bootstrapping. Wait for nodetool status to show the new node as UN (Up/Normal).

The newly added node has only the data it should own—no cleanup needed.


ResourceImpact
Disk I/OHigh - reads all SSTables
CPUModerate - token range calculations
Disk spaceTemporary increase, then decrease
DurationProportional to data size
  1. Scans each SSTable
  2. Checks each partition's token against current ring
  3. Creates new SSTable with only locally-owned data
  4. Removes old SSTable after completion

Temporary Space Needed

During cleanup, both old and new SSTables exist temporarily:

Before: 100 GB (original SSTables)
During: Up to 200 GB (old + new being written)
After: ~75 GB (assuming 25% of data moved to new node)

Ensure sufficient free space before running cleanup.


Terminal window
nodetool cleanup

Cleans all non-system keyspaces.

Terminal window
nodetool cleanup my_keyspace
Terminal window
nodetool cleanup my_keyspace my_table
Terminal window
nodetool cleanup -j 4 my_keyspace

Parallelism Trade-offs

Higher parallelism speeds up cleanup but increases I/O load. On production systems, use default or lower values.


Terminal window
nodetool compactionstats

Cleanup appears as a compaction operation in the output.

Terminal window
# Check data size before cleanup
nodetool tablestats my_keyspace | grep "Space used"
# Monitor progress
watch -n 5 'nodetool compactionstats'
Terminal window
# Verify reduced data size
nodetool tablestats my_keyspace | grep "Space used"

Terminal window
# Node 1
ssh node1 'nodetool cleanup'
# Wait for completion, then Node 2
ssh node2 'nodetool cleanup'
# Continue for all existing nodes

Sequential Execution

Running cleanup on all nodes simultaneously creates excessive I/O cluster-wide. Process nodes one at a time.

StepActionNotes
1Add new nodeBootstrap streams data
2Wait for UN statusnodetool status
3Run repair on new nodeEnsure data consistency
4Run cleanup on existing nodesOne at a time

System keyspaces are cleaned automatically. Focus on user keyspaces:

Terminal window
nodetool cleanup my_keyspace1 my_keyspace2

CauseSolution
Large data volumeRun during off-peak hours
Slow disksReduce -j parallelism
Heavy production loadSchedule for maintenance window
ERROR: Not enough disk space for cleanup

Options:

  1. Clean up one table at a time
  2. Free disk space elsewhere
  3. Add storage capacity

If disk usage doesn't decrease after cleanup:

  1. Verify bootstrap actually completed
  2. Check that cleanup ran on the correct nodes
  3. Verify token ranges redistributed with nodetool ring

OperationPurpose
cleanupRemove data not belonging to node
repairSynchronize data across replicas

These serve different purposes:

  • Cleanup removes data from wrong location
  • Repair ensures copies are consistent

After adding nodes, typically repair first (on new node), then cleanup (on existing nodes).


CommandRelationship
statusVerify node states before cleanup
ringCheck token distribution
repairSynchronize data after topology change
compactionstatsMonitor cleanup progress
tablestatsCheck data sizes