Skip to content

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

sstablelevelreset

Resets all SSTables to level 0 for tables using Leveled Compaction Strategy (LCS).


Terminal window
sstablelevelreset --really-reset <keyspace> <table>

sstablelevelreset resets the compaction level of all SSTables for a table back to level 0 (L0). This is specifically for tables using Leveled Compaction Strategy (LCS) where level corruption or distribution issues have occurred.

This tool is used when:

  • Level metadata is corrupted - SSTables have incorrect level assignments
  • Compaction is stuck - Levels are imbalanced and compaction cannot progress
  • After switching to LCS - Existing SSTables need level assignment
  • Recovery from issues - Compaction problems require a fresh start

Cassandra Must Be Stopped

Cassandra must be completely stopped before running sstablelevelreset. Running this tool while Cassandra is active will cause data corruption.


Leveled Compaction Strategy StructureLeveled Compaction Strategy StructureLevel 0 (L0)Level 1 (L1)Level 2 (L2)SSTableSSTableSSTableMax 4 SSTablesOverlapping ranges allowedSSTableSSTableSSTableSSTable10 × L0 sizeNon-overlappingSSTableSSTableSSTableSSTableSSTable10 × L1 sizeNon-overlappingsstablelevelreset movesALL SSTables back to L0CompactionCompaction
LevelMax SizeNon-overlappingSSTables
L0Up to 4 × sstable_size_in_mbNo1-4
L1fanout_size × L0 sizeYes~10
L2fanout_size × L1 sizeYes~100
L3+fanout_size × previousYes~1000+

Configuration-Dependent Values

Level sizes depend on LCS compaction strategy settings:

  • sstable_size_in_mb: Target SSTable size (default: 160 MiB)
  • fanout_size: Size multiplier between levels (default: 10)

With defaults, L0 holds up to ~640 MiB (4 × 160 MiB) before triggering compaction to L1.


ArgumentDescription
keyspaceName of the keyspace containing the table
tableName of the table to reset levels

OptionDescription
--really-resetRequired safety flag to confirm reset

The --really-reset flag is mandatory to prevent accidental execution.


Terminal window
# Stop Cassandra first
sudo systemctl stop cassandra
# Reset all SSTables to level 0
sstablelevelreset --really-reset my_keyspace my_table
# Start Cassandra - LCS will reorganize levels
sudo systemctl start cassandra
Terminal window
# Before reset - check level distribution
sstablemetadata /var/lib/cassandra/data/my_keyspace/my_table-*/*-Data.db | grep "SSTable Level"
#!/bin/bash
# reset_lcs_tables.sh - Reset levels for all LCS tables
KEYSPACE="$1"
# Find tables using LCS
lcs_tables=$(cqlsh -e "SELECT table_name FROM system_schema.tables
WHERE keyspace_name = '$KEYSPACE'" | \
while read table; do
compaction=$(cqlsh -e "SELECT compaction FROM system_schema.tables
WHERE keyspace_name = '$KEYSPACE' AND table_name = '$table'" 2>/dev/null | \
grep -i "leveledcompaction")
if [ -n "$compaction" ]; then
echo "$table"
fi
done)
for table in $lcs_tables; do
echo "Resetting levels for ${KEYSPACE}.${table}..."
sstablelevelreset --really-reset "$KEYSPACE" "$table"
done

Terminal window
# Symptoms:
# - Cassandra logs show "Level X has Y SSTables but should have Z"
# - Unexpected compaction behavior
# - Compaction stats show wrong level distribution
# Check current state
nodetool cfstats my_keyspace.my_table | grep -i level
# Reset levels
sudo systemctl stop cassandra
sstablelevelreset --really-reset my_keyspace my_table
sudo systemctl start cassandra
Terminal window
# When migrating from STCS to LCS
# 1. Change compaction strategy
cqlsh -e "ALTER TABLE my_keyspace.my_table WITH compaction = {
'class': 'LeveledCompactionStrategy'
};"
# 2. Stop Cassandra
sudo systemctl stop cassandra
# 3. Reset levels (existing SSTables may have level 0 already, but reset ensures clean state)
sstablelevelreset --really-reset my_keyspace my_table
# 4. Start Cassandra - LCS will organize SSTables into levels
sudo systemctl start cassandra
# 5. Monitor compaction progress
nodetool compactionstats
Terminal window
# Symptoms:
# - Compaction not progressing
# - High number of SSTables
# - Levels are imbalanced
# Check level distribution
for f in /var/lib/cassandra/data/my_keyspace/my_table-*/*-Data.db; do
level=$(sstablemetadata "$f" | grep "SSTable Level:" | awk '{print $3}')
echo "L${level}: $(basename $f)"
done | sort | uniq -c
# If distribution is problematic, reset
sudo systemctl stop cassandra
sstablelevelreset --really-reset my_keyspace my_table
sudo systemctl start cassandra

Scenario 4: Recovery from sstableofflinerelevel Issues

Section titled “Scenario 4: Recovery from sstableofflinerelevel Issues”
Terminal window
# If sstableofflinerelevel caused problems
# Reset to clean state and let LCS reorganize
sudo systemctl stop cassandra
sstablelevelreset --really-reset my_keyspace my_table
sudo systemctl start cassandra

Level Distribution:
L0: 2 SSTables (320 MB)
L1: 10 SSTables (1.6 GB)
L2: 87 SSTables (14 GB)
L3: 432 SSTables (69 GB)
Level Distribution:
L0: 531 SSTables (85 GB) <- All SSTables moved here
L1: 0 SSTables
L2: 0 SSTables
L3: 0 SSTables
Level Distribution:
L0: 4 SSTables (640 MB) <- Back to normal
L1: 10 SSTables (1.6 GB)
L2: 100 SSTables (16 GB)
L3: 450 SSTables (72 GB)

Terminal window
sudo systemctl start cassandra
Terminal window
# Watch compaction progress
watch -n 5 'nodetool compactionstats'
# Check level distribution
nodetool cfstats my_keyspace.my_table | grep -A10 "SSTables in each level"
Terminal window
# Ensure reads work correctly
cqlsh -e "SELECT * FROM my_keyspace.my_table LIMIT 10;"
# Check for compaction errors
grep -i "error\|exception" /var/log/cassandra/system.log

sstablelevelreset vs sstableofflinerelevel

Section titled “sstablelevelreset vs sstableofflinerelevel”
Aspectsstablelevelresetsstableofflinerelevel
ActionReset all to L0Recalculate optimal levels
ResultClean slateReorganized levels
Compaction afterHeavy (reorganize all)Minimal (already organized)
Use caseCorrupted metadataImbalanced levels
SafetyConservativeMore aggressive
Choosing Between Level ToolsChoosing Between Level ToolsLCS level issue detectedMetadata corrupted?yesnoSafe, conservative choiceUse sstablelevelresetLevels just imbalanced?yesnoReorganizes without resetUse sstableofflinerelevelInvestigate further

Terminal window
# Run as cassandra user
sudo -u cassandra sstablelevelreset --really-reset my_keyspace my_table
# Or fix permissions
sudo chown -R cassandra:cassandra /var/lib/cassandra/data/
Terminal window
# Error: Cannot run while Cassandra is active
# Stop Cassandra properly
nodetool drain
sudo systemctl stop cassandra
# Verify stopped
pgrep -f CassandraDaemon # Should return nothing
# Now run the tool
sstablelevelreset --really-reset my_keyspace my_table
Terminal window
# Error: Must provide --really-reset flag
# The flag is required as a safety measure
sstablelevelreset --really-reset my_keyspace my_table
Terminal window
# After reset, LCS will compact aggressively to reorganize
# Option 1: Let it complete (recommended)
# Monitor with:
nodetool compactionstats
# Option 2: Throttle compaction if overwhelming
nodetool setcompactionthroughput 16 # 16 MB/s

sstablelevelreset Guidelines

  1. Last resort - Try sstableofflinerelevel first for imbalanced levels
  2. Backup first - Snapshot before running
  3. Plan for compaction - Heavy compaction will follow
  4. Off-peak timing - Run during maintenance windows
  5. Monitor after - Watch compaction progress
  6. One table at a time - Don't reset multiple tables simultaneously
  7. Verify result - Check level distribution after compaction settles

Cautions

  • All SSTables move to L0 (causes heavy compaction)
  • Only use for LCS tables
  • Requires --really-reset flag
  • Cannot be undone (must let compaction reorganize)

CommandRelationship
sstableofflinerelevelRecalculate levels (alternative)
sstablemetadataCheck current SSTable levels
nodetool compactionstatsMonitor compaction progress
nodetool tablestatsView level distribution
nodetool setcompactionthroughputControl compaction speed