nodetool enableautocompaction
Re-enables automatic compaction for specified keyspaces and tables.
Synopsis
Section titled “Synopsis”nodetool [connection_options] enableautocompaction [--] [<keyspace> <tables>...]See connection options for connection options.
Description
Section titled “Description”nodetool enableautocompaction restores automatic compaction behavior for one or more tables after it was temporarily disabled with disableautocompaction. When auto-compaction is enabled, Cassandra's compaction strategy continuously evaluates SSTables and triggers compaction operations based on configured thresholds and policies.
Automatic compaction is essential for:
- Maintaining read performance - Merging SSTables reduces the number of files to scan
- Reclaiming disk space - Removing tombstones and expired data
- Data consistency - Ensuring deleted data is eventually purged
- Preventing SSTable proliferation - Keeping file counts manageable
Default State
Auto-compaction is enabled by default on all tables. This command is only needed after explicitly disabling it with disableautocompaction.
Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
keyspace | Target keyspace name. If omitted, applies to all keyspaces |
tables | Space-separated list of table names. If omitted, applies to all tables in the keyspace |
Examples
Section titled “Examples”Enable for All Keyspaces and Tables
Section titled “Enable for All Keyspaces and Tables”# Re-enable compaction cluster-wide on this nodenodetool enableautocompactionEnable for Specific Keyspace
Section titled “Enable for Specific Keyspace”# Re-enable for all tables in a keyspacenodetool enableautocompaction my_keyspaceEnable for Specific Tables
Section titled “Enable for Specific Tables”# Re-enable for specific tables onlynodetool enableautocompaction my_keyspace users orders productsWith Verification
Section titled “With Verification”# Enable and verifynodetool enableautocompaction my_keyspace my_tablenodetool statusautocompaction my_keyspace my_table# Expected: running=trueWhen to Use
Section titled “When to Use”After Bulk Data Loading
Section titled “After Bulk Data Loading”Re-enable compaction after loading large amounts of data:
# 1. Disable compaction before bulk loadnodetool disableautocompaction my_keyspace my_table
# 2. Load data (sstableloader, COPY, etc.)sstableloader -d node1,node2 /path/to/sstables/
# 3. Re-enable compactionnodetool enableautocompaction my_keyspace my_table
# 4. Optionally force immediate compactionnodetool compact my_keyspace my_tableAfter Maintenance Operations
Section titled “After Maintenance Operations”Restore normal operation after maintenance:
# After repair or other maintenancenodetool enableautocompaction my_keyspace
# Monitor compaction activitywatch nodetool compactionstatsAfter Troubleshooting
Section titled “After Troubleshooting”When compaction was disabled to investigate issues:
# Issue identified and resolvednodetool enableautocompaction
# Verify compaction resumesnodetool compactionstatsAfter Node Recovery
Section titled “After Node Recovery”When bringing a node back to normal operation:
# Node recovered, restore full functionalitynodetool enableautocompaction
# Check for compaction backlognodetool compactionstatsBehavior
Section titled “Behavior”What Happens When Enabled
Section titled “What Happens When Enabled”- The table is marked as eligible for automatic compaction
- The compaction strategy begins evaluating SSTables
- Compaction tasks are scheduled based on strategy rules
- Pending compaction backlog begins processing
Compaction Strategy Interaction
Section titled “Compaction Strategy Interaction”The enabled auto-compaction respects the table's configured compaction strategy:
| Strategy | Behavior After Enable |
|---|---|
| SizeTieredCompactionStrategy (STCS) | Compacts SSTables of similar sizes |
| LeveledCompactionStrategy (LCS) | Promotes SSTables through levels |
| TimeWindowCompactionStrategy (TWCS) | Compacts within time windows |
| UnifiedCompactionStrategy (UCS) | Adaptive compaction (Cassandra 5.0+) |
Impact Assessment
Section titled “Impact Assessment”Immediate Effects
Section titled “Immediate Effects”| Aspect | Impact |
|---|---|
| Compaction scheduling | Resumes immediately |
| Disk I/O | May increase as backlog processes |
| CPU usage | Compaction threads become active |
| Pending tasks | Begin processing |
Short-term Effects
Section titled “Short-term Effects”| Aspect | Impact |
|---|---|
| SSTable count | Begins decreasing |
| Read latency | Improves as SSTables merge |
| Disk usage | May spike during compaction |
| Write amplification | Normal levels resume |
Compaction Backlog
If auto-compaction was disabled for an extended period, there may be a significant backlog. Monitor disk space and I/O during catch-up.
Workflow: Complete Bulk Load Procedure
Section titled “Workflow: Complete Bulk Load Procedure”#!/bin/bashKEYSPACE="my_keyspace"TABLE="my_table"DATA_PATH="/path/to/sstables"
echo "=== Bulk Load with Compaction Control ==="
# 1. Check current stateecho "1. Current compaction status:"nodetool statusautocompaction $KEYSPACE $TABLE
# 2. Disable auto-compactionecho "2. Disabling auto-compaction..."nodetool disableautocompaction $KEYSPACE $TABLE
# 3. Verify disabledecho "3. Verifying disabled:"nodetool statusautocompaction $KEYSPACE $TABLE
# 4. Load dataecho "4. Loading data..."sstableloader -d localhost $DATA_PATH
# 5. Re-enable auto-compactionecho "5. Re-enabling auto-compaction..."nodetool enableautocompaction $KEYSPACE $TABLE
# 6. Verify enabledecho "6. Verifying enabled:"nodetool statusautocompaction $KEYSPACE $TABLE
# 7. Check compaction activityecho "7. Current compaction activity:"nodetool compactionstats
echo "=== Complete ==="Monitoring After Enable
Section titled “Monitoring After Enable”Check Compaction Activity
Section titled “Check Compaction Activity”# View active and pending compactionsnodetool compactionstatsExample output showing compaction resuming:
pending tasks: 15- my_keyspace.my_table: 15
Active compaction remaining time : 0h00m45s compaction type keyspace table completed total unit progress Compaction my_keyspace my_table 524288000 1048576000 bytes 50.00%Monitor Over Time
Section titled “Monitor Over Time”# Watch compaction progresswatch -n 5 'nodetool compactionstats'Check SSTable Counts
Section titled “Check SSTable Counts”# Before re-enabling (many SSTables)nodetool tablestats my_keyspace.my_table | grep "SSTable count"# SSTable count: 47
# After compaction catches up (fewer SSTables)nodetool tablestats my_keyspace.my_table | grep "SSTable count"# SSTable count: 8Troubleshooting
Section titled “Troubleshooting”Compaction Not Starting After Enable
Section titled “Compaction Not Starting After Enable”If compaction doesn't start after enabling:
# Verify status is enablednodetool statusautocompaction my_keyspace my_table
# Check for pending tasksnodetool compactionstats
# If no pending tasks, may need to wait for strategy evaluation# Or force compactionnodetool compact my_keyspace my_tableHigh I/O After Enable
Section titled “High I/O After Enable”If I/O is too high after enabling:
# Reduce compaction throughput temporarilynodetool setcompactionthroughput 32
# Let backlog process graduallywatch nodetool compactionstats
# Restore normal throughput laternodetool setcompactionthroughput 64Disk Space Issues
Section titled “Disk Space Issues”If disk space is critical:
# Check current usagedf -h /var/lib/cassandra
# May need to process compaction slowlynodetool setcompactionthroughput 16
# Clear snapshots if needednodetool clearsnapshot --allCluster-Wide Operations
Section titled “Cluster-Wide Operations”Enable on All Nodes
Section titled “Enable on All Nodes”#!/bin/bashKEYSPACE="my_keyspace"TABLE="my_table"
# Get list of node IPs from local nodetool statusnodes=$(nodetool status | grep "^UN" | awk '{print $2}')
for node in $nodes; do echo "Enabling auto-compaction on $node..." ssh "$node" "nodetool enableautocompaction $KEYSPACE $TABLE"done
echo "Verification:"for node in $nodes; do echo -n "$node: " ssh "$node" "nodetool statusautocompaction $KEYSPACE $TABLE"doneBest Practices
Section titled “Best Practices”Auto-Compaction Guidelines
- Re-enable promptly - Don't leave auto-compaction disabled for extended periods
- Verify after enabling - Always check with
statusautocompaction - Monitor the backlog - Watch
compactionstatsfor catch-up progress - Control throughput - Adjust compaction throughput if I/O impact is too high
- Check disk space - Ensure sufficient space for compaction to proceed
- Document changes - Log when and why auto-compaction was disabled/enabled
- Apply consistently - Enable on all nodes if disabled cluster-wide
Long-term Disable Risks
Keeping auto-compaction disabled for extended periods causes:
- SSTable proliferation (many small files)
- Degraded read performance
- Increased memory usage for bloom filters
- Tombstone accumulation
- Potential disk space issues
Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| disableautocompaction | Disable auto-compaction |
| statusautocompaction | Check auto-compaction status |
| compact | Force manual compaction |
| compactionstats | View active compactions |
| setcompactionthroughput | Control compaction rate |
| tablestats | View SSTable counts |