Skip to content

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

Cassandra Compaction Issues

Compaction merges SSTables to maintain read performance and reclaim space. When compaction falls behind or behaves unexpectedly, read performance degrades and disk usage grows.


  • Growing pending compaction count
  • Increasing SSTable count per table
  • Degrading read latency over time
  • Disk space not being reclaimed after deletes
  • High I/O during compaction spikes
  • "Compaction stuck" or very slow progress

Terminal window
nodetool compactionstats

Problem indicators:

  • High pending count (> 50 per table)
  • Same compaction running for hours
  • No active compactions despite pending
Terminal window
nodetool tablestats my_keyspace | grep -E "Table:|SSTable count"

Target: Generally < 20 SSTables per table (varies by strategy).

Terminal window
nodetool getcompactionthroughput

Default: 64 MB/s. May need increase for high-write workloads.

Terminal window
iostat -x 1 10

Problem indicators:

  • Disk utilization at 100%
  • High await times
Terminal window
cqlsh -e "SELECT table_name, compaction FROM system_schema.tables WHERE keyspace_name = 'my_keyspace';"

Increase compaction throughput:

Terminal window
# Check current
nodetool getcompactionthroughput
# Increase (MB/s)
nodetool setcompactionthroughput 128

Increase concurrent compactors:

Terminal window
# Check current
nodetool getconcurrentcompactors
# Increase
nodetool setconcurrentcompactors 4
Terminal window
# Check if auto-compaction is enabled
nodetool statusautocompaction my_keyspace my_table
# Enable if disabled
nodetool enableautocompaction my_keyspace my_table

For read-heavy workloads (many updates):

ALTER TABLE my_table WITH compaction = {
'class': 'LeveledCompactionStrategy',
'sstable_size_in_mb': 160
};

For time-series data:

ALTER TABLE my_table WITH compaction = {
'class': 'TimeWindowCompactionStrategy',
'compaction_window_unit': 'DAYS',
'compaction_window_size': 1
};

For write-heavy workloads:

ALTER TABLE my_table WITH compaction = {
'class': 'SizeTieredCompactionStrategy',
'min_threshold': 4,
'max_threshold': 32
};

For specific table:

Terminal window
nodetool compact my_keyspace my_table

For major compaction (use sparingly):

Terminal window
# Warning: Resource intensive
nodetool compact --split-output my_keyspace my_table

Major Compaction

Major compaction creates one large SSTable and can cause significant I/O. Use --split-output to create multiple smaller SSTables instead.

Check what's happening:

Terminal window
nodetool compactionstats -H

If stuck on validation:

Terminal window
# May need to restart node if truly stuck
# First try waiting - large SSTables take time
# If necessary, cancel specific compaction
# (Requires identifying compaction ID from logs)

See Handle Full Disk.

Terminal window
# Quick space recovery
nodetool clearsnapshot --all
# Check space
df -h /var/lib/cassandra

StrategyBest ForSSTable Behavior
STCSWrite-heavy, space-efficientMany SSTables, tiered by size
LCSRead-heavy, consistent performanceFixed-size levels
TWCSTime-series, TTL dataTime-based windows
UCSFlexible, Cassandra 5.0+Unified approach
-- Check current strategy
SELECT compaction FROM system_schema.tables
WHERE keyspace_name = 'my_ks' AND table_name = 'my_table';
-- Change strategy (takes effect gradually)
ALTER TABLE my_table WITH compaction = {
'class': 'LeveledCompactionStrategy'
};
-- Force migration
nodetool compact my_keyspace my_table

ALTER TABLE my_table WITH compaction = {
'class': 'SizeTieredCompactionStrategy',
'min_threshold': 4, -- Min SSTables to compact
'max_threshold': 32, -- Max SSTables to compact
'min_sstable_size': 50 -- Min size to consider (MB)
};
ALTER TABLE my_table WITH compaction = {
'class': 'LeveledCompactionStrategy',
'sstable_size_in_mb': 160 -- Target SSTable size
};
ALTER TABLE my_table WITH compaction = {
'class': 'TimeWindowCompactionStrategy',
'compaction_window_unit': 'DAYS',
'compaction_window_size': 1,
'max_threshold': 32
};

Terminal window
# Pending should decrease
watch -n 30 'nodetool compactionstats | head -10'
# SSTable count should stabilize
nodetool tablestats my_keyspace.my_table | grep "SSTable count"
Terminal window
# Latencies should improve
nodetool tablehistograms my_keyspace my_table

MetricWarningCritical
Pending compactions> 20> 100
SSTable count> 20> 50
Compaction throughputNear limitAt 0
Disk usage> 70%> 85%
monitor_compaction.sh
#!/bin/bash
while true; do
clear
echo "=== $(date) ==="
echo ""
echo "--- Compaction Stats ---"
nodetool compactionstats | head -20
echo ""
echo "--- SSTable Counts ---"
nodetool tablestats 2>/dev/null | grep -E "Table:|SSTable count" | head -20
echo ""
echo "--- Disk Usage ---"
df -h /var/lib/cassandra
sleep 60
done

  1. Choose appropriate strategy - Match to workload pattern
  2. Monitor pending compactions - Alert early
  3. Adequate disk space - Keep < 70% utilization
  4. Sufficient I/O capacity - SSD recommended
  5. Tune throughput - Match to hardware capability
  6. Regular table maintenance - Monitor SSTable counts

CommandPurpose
nodetool compactionstatsCurrent compaction status
nodetool compactForce compaction
nodetool setcompactionthroughputAdjust throughput
nodetool getconcurrentcompactorsView compactor count
nodetool enableautocompactionEnable auto-compaction
nodetool disableautocompactionDisable auto-compaction