Cassandra Handle Full Disk
A full disk is a critical emergency that can cause data loss, node failures, and cluster instability. Immediate action is required.
Symptoms
Section titled “Symptoms”- Write failures with “No space left on device”
- Cassandra process crashes or refuses to start
- Compaction failures
- Commit log segment allocation failures
- Node becomes unavailable
Immediate Response
Section titled “Immediate Response”Step 1: Assess Situation
Section titled “Step 1: Assess Situation”# Check disk usagedf -h /var/lib/cassandra
# Check what's consuming spacedu -sh /var/lib/cassandra/*Step 2: Stop Writes (If Possible)
Section titled “Step 2: Stop Writes (If Possible)”# Disable binary protocol to stop client writesnodetool disablebinary
# Disable gossip to prevent coordinator trafficnodetool disablegossipStep 3: Quick Space Recovery
Section titled “Step 3: Quick Space Recovery”Option A: Clear snapshots (fastest, usually safe)
# List snapshotsnodetool listsnapshots
# Clear all snapshotsnodetool clearsnapshot --all
# Check recovered spacedf -h /var/lib/cassandraOption B: Clear old hints (if hints are large)
# Check hints sizedu -sh /var/lib/cassandra/hints
# Truncate hints (some data loss risk during node down scenarios)nodetool truncatehintsOption C: Clear saved caches
rm -rf /var/lib/cassandra/saved_caches/*Step 4: Verify Recovery
Section titled “Step 4: Verify Recovery”df -h /var/lib/cassandra# Should show < 90% usage for safe operationStep 5: Re-enable Operations
Section titled “Step 5: Re-enable Operations”nodetool enablegossipnodetool enablebinaryDiagnosis
Section titled “Diagnosis”What’s Using Space?
Section titled “What’s Using Space?”# Detailed breakdowndu -h /var/lib/cassandra/data/* | sort -h | tail -20
# Snapshotsdu -sh /var/lib/cassandra/data/*/*/snapshots/* 2>/dev/null | sort -h | tail -10
# Commitlogdu -sh /var/lib/cassandra/commitlog
# Hintsdu -sh /var/lib/cassandra/hintsIdentify Large Tables
Section titled “Identify Large Tables”# Size per tablenodetool tablestats 2>/dev/null | grep -E "Table:|Space used" | paste - - | sort -t: -k3 -h | tail -20Check for Snapshot Accumulation
Section titled “Check for Snapshot Accumulation”nodetool listsnapshotsOld snapshots from backups, repairs, or schema changes accumulate over time.
Resolution by Cause
Section titled “Resolution by Cause”Cause 1: Snapshot Accumulation
Section titled “Cause 1: Snapshot Accumulation”Clear specific snapshots:
# Clear snapshot by namenodetool clearsnapshot -t snapshot_name
# Clear all snapshotsnodetool clearsnapshot --allClear snapshots for specific keyspace:
nodetool clearsnapshot -t snapshot_name -- my_keyspaceCause 2: Failed Compaction
Section titled “Cause 2: Failed Compaction”Compaction needs temporary space. If disk filled mid-compaction:
# Clear snapshots firstnodetool clearsnapshot --all
# Reduce compaction parallelismnodetool setconcurrentcompactors 1
# Reduce compaction throughputnodetool setcompactionthroughput 32Cause 3: Large Table Growth
Section titled “Cause 3: Large Table Growth”# Identify growing tablesnodetool tablestats my_keyspace | grep -E "Table:|Space used"
# Consider:# 1. Add nodes to distribute data# 2. Implement TTLs# 3. Archive old dataCause 4: Commitlog Growth
Section titled “Cause 4: Commitlog Growth”# Check commitlogdu -sh /var/lib/cassandra/commitlog/*
# Force flush to reduce commitlognodetool flush
# If commitlog is blocking startup, may need to clear# WARNING: DATA LOSS - unflushed data will be lost# sudo rm /var/lib/cassandra/commitlog/*Cause 5: Hints Accumulation
Section titled “Cause 5: Hints Accumulation”Hints accumulate when nodes are down:
# Check hintsdu -sh /var/lib/cassandra/hints
# Truncate hints (loses hints data)nodetool truncatehints
# Fix underlying node issuesnodetool status # All should be UNEmergency Procedures
Section titled “Emergency Procedures”Cannot Start Cassandra Due to Full Disk
Section titled “Cannot Start Cassandra Due to Full Disk”# 1. Clear snapshots manuallyrm -rf /var/lib/cassandra/data/*/*/snapshots/*
# 2. Clear saved cachesrm -rf /var/lib/cassandra/saved_caches/*
# 3. If still full, reduce commitlog# WARNING: Potential data lossrm /var/lib/cassandra/commitlog/*
# 4. Try startingsudo systemctl start cassandraMultiple Nodes Full
Section titled “Multiple Nodes Full”Indicates cluster capacity issue:
- Add temporary disk capacity if possible
- Clear snapshots on all nodes
- Plan capacity expansion urgently
- Consider emergency node additions
Prevention
Section titled “Prevention”Monitoring
Section titled “Monitoring”Set up alerts:
| Metric | Warning | Critical |
|---|---|---|
| Disk usage | > 70% | > 85% |
| Disk growth rate | Unusual spike | - |
Automated Cleanup
Section titled “Automated Cleanup”#!/bin/bash# cleanup_snapshots.sh - Run periodically
# Clear snapshots older than 7 daysfind /var/lib/cassandra/data -path '*/snapshots/*' -mtime +7 -delete
# Report disk usagedf -h /var/lib/cassandra | mail -s "Cassandra disk report" admin@example.comConfiguration
Section titled “Configuration”# Auto-snapshot before DROP/TRUNCATEauto_snapshot: true
# Limit hints storagemax_hints_file_size_in_mb: 128hints_flush_period_in_ms: 10000max_hints_delivery_threads: 2Capacity Planning
Section titled “Capacity Planning”| Data Growth | Action |
|---|---|
| < 5% per month | Monitor |
| 5-10% per month | Plan expansion |
| > 10% per month | Expand immediately |
Rule of thumb: Keep disk usage below 50% to allow for:
- Compaction temporary space
- Growth headroom
- Emergency buffer
Recovery Verification
Section titled “Recovery Verification”# Verify disk spacedf -h /var/lib/cassandra
# Verify node healthnodetool statusnodetool info
# Verify compaction can runnodetool compactionstats
# Verify writes workcqlsh -e "INSERT INTO system_auth.roles (role) VALUES ('test_write');"cqlsh -e "DELETE FROM system_auth.roles WHERE role = 'test_write';"Space Requirements
Section titled “Space Requirements”Minimum Free Space
Section titled “Minimum Free Space”| Component | Requirement |
|---|---|
| Compaction | 50% of largest SSTable |
| Repair | Variable, can be significant |
| Normal operations | 20% free recommended |
| Safe operating range | < 70% used |
Estimation
Section titled “Estimation”# Current usagedf -h /var/lib/cassandra
# Data sizenodetool tablestats 2>/dev/null | grep "Space used (total)" | awk '{sum+=$5} END {print sum/1024/1024/1024 " GB"}'
# Snapshot sizedu -sh /var/lib/cassandra/data/*/*/snapshots/* 2>/dev/null | awk '{sum+=$1} END {print sum " total in snapshots"}'Related Issues
Section titled “Related Issues”| Problem | Playbook |
|---|---|
| Compaction failing | Compaction Issues |
| Node down | Replace Dead Node |
| OOM related to disk | Recover from OOM |
Related Commands
Section titled “Related Commands”| Command | Purpose |
|---|---|
nodetool clearsnapshot | Remove snapshots |
nodetool listsnapshots | List snapshots |
nodetool truncatehints | Clear hints |
nodetool flush | Flush memtables |
nodetool disablebinary | Stop client connections |