Skip to content

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

Cassandra Cleanup Operations

Cleanup removes data that a node no longer owns after topology changes. This operation must run on existing nodes after adding new nodes to the cluster.


OperationCleanup RequiredNodes to Clean
Add node (bootstrap)YesAll existing nodes
DecommissionNoNone
Remove nodeNoNone
Replace nodeNoNone
RebuildNoNone

When a new node joins:

  1. Existing nodes stream data to the new node
  2. The new node now owns some token ranges
  3. Original nodes retain copies of data they streamed
  4. This data is now redundant—the new node is the owner

Without cleanup:

  • Disk usage remains elevated on original nodes
  • Extra data consumes backup storage
  • Compaction processes unnecessary data

  • Only data outside the node's current token ranges is removed
  • Data owned by the node is never deleted
  • Operation is resumable if interrupted
  • Does not affect cluster availability
AspectBehavior
BlockingYes, runs synchronously
I/O impactHigh—reads and rewrites SSTables
DurationProportional to data volume
RestartabilitySafe to restart if interrupted
ScenarioOutcomeRecovery
Cleanup completesObsolete data removedNone required
Cleanup interruptedPartial cleanupRe-run cleanup
Disk fills during cleanupOperation failsFree space, re-run
Node restarts during cleanupCleanup abortedRe-run cleanup

Before running cleanup:

RequirementVerification
New nodes must show UN statusnodetool status
Bootstrap must be completeNo nodes in UJ state
Sufficient disk space for compaction> 20% free recommended
No repairs runningnodetool netstats

Timing Matters

Run cleanup after all new nodes have completed bootstrap. Running cleanup before bootstrap completes may remove data still being streamed.


Run on each existing node (not the new nodes):

Terminal window
# Full cleanup (all keyspaces)
nodetool cleanup

Clean specific keyspaces:

Terminal window
# Single keyspace
nodetool cleanup my_keyspace
# Multiple keyspaces
nodetool cleanup keyspace1 keyspace2

Clean specific tables:

Terminal window
# Single table
nodetool cleanup my_keyspace my_table

Run cleanup one node at a time to limit cluster-wide I/O impact:

Terminal window
# Node 1
ssh node1 "nodetool cleanup"
# Wait for completion
# Node 2
ssh node2 "nodetool cleanup"
# Wait for completion
# Continue for all original nodes...

In large clusters with sufficient I/O capacity:

Terminal window
# Run on multiple nodes simultaneously
# Limit to one per rack to avoid overwhelming storage
parallel-ssh -h nodes_rack1.txt "nodetool cleanup"
# Wait
parallel-ssh -h nodes_rack2.txt "nodetool cleanup"

Parallel Cleanup Impact

Parallel cleanup increases cluster-wide I/O load. Monitor latency and throughput during execution.


Terminal window
# Active compaction tasks (cleanup appears as compaction)
nodetool compactionstats
# Example output during cleanup:
# pending tasks: 3
# compaction type keyspace table completed total unit progress
# Cleanup users data 52428800 104857600 bytes 50.00%
Terminal window
# No cleanup tasks pending
nodetool compactionstats | grep -i cleanup
# Disk usage should decrease
df -h /var/lib/cassandra
# Compare before/after per node
nodetool status
Terminal window
# Watch cleanup progress in logs
tail -f /var/log/cassandra/system.log | grep -i cleanup

Reduce cleanup impact on client operations:

Terminal window
# Reduce concurrent compactors temporarily
nodetool setcompactionthroughput 32 # MB/s (default varies)
# After cleanup
nodetool setcompactionthroughput 0 # Reset to unlimited

Cleanup is I/O intensive. Schedule during:

  • Off-peak hours
  • Maintenance windows
  • Low-traffic periods

Cleanup may temporarily increase disk usage during SSTable rewriting:

Terminal window
# Verify sufficient space before cleanup
df -h /var/lib/cassandra
# Rule: Need ~20% free space for compaction overhead

Cleanup duration depends on:

  • Data volume on the node
  • I/O throughput
  • Percentage of data that moved to new nodes
Data per NodeCleanup Duration
100 GB30 min - 1 hour
500 GB2-4 hours
1 TB4-8 hours
2 TB8-16 hours
Duration ≈ (Node data volume × Fraction moved) / I/O throughput
Example:
- Node has 500 GB
- Added 1 node to 4-node cluster (25% data moved)
- I/O throughput: 100 MB/s
Duration ≈ (500 GB × 0.25) / 100 MB/s = 125 GB / 100 MB/s ≈ 21 minutes

Actual times are typically 2-4x this estimate due to overhead.


Symptoms: Cleanup takes much longer than expected

Causes:

CauseSolution
Disk I/O saturatedReduce compaction_throughput_mb_per_sec
Many small SSTablesRun major compaction first
Competing operationsWait for repairs/streaming to complete
Terminal window
# Check I/O utilization
iostat -x 5
# Check competing tasks
nodetool compactionstats

Symptoms: Cleanup aborts with "No space left on device"

Solution:

Terminal window
# 1. Free disk space
# - Delete old snapshots
nodetool clearsnapshot
# - Remove old logs
sudo journalctl --vacuum-time=7d
# 2. Retry cleanup on specific keyspace
nodetool cleanup smallest_keyspace
# 3. Continue with larger keyspaces as space frees

Symptoms: Cleanup runs indefinitely

Causes:

  • Continuous new data (cleanup processes existing SSTables)
  • Very large SSTables

Solution:

Terminal window
# Run on specific tables
nodetool cleanup keyspace table
# If still slow, consider off-peak window

Cleanup may be deferred in specific scenarios:

ScenarioConsideration
Emergency scale-upDefer cleanup to next maintenance window
Time-critical operationsComplete urgent work first
Limited maintenance windowPartial cleanup (critical keyspaces first)

Risks of skipping cleanup:

  • Elevated disk usage (10-30% higher than necessary)
  • Backup size inflation
  • Wasted I/O on obsolete data

Mitigation if skipped:

  • Schedule cleanup within 1-2 weeks
  • Monitor disk usage closely
  • Prioritize cleanup before next topology change