sstablelevelreset
Resets all SSTables to level 0 for tables using Leveled Compaction Strategy (LCS).
Synopsis
Section titled “Synopsis”sstablelevelreset --really-reset <keyspace> <table>Description
Section titled “Description”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.
How LCS Levels Work
Section titled “How LCS Levels Work”Level Properties
Section titled “Level Properties”| Level | Max Size | Non-overlapping | SSTables |
|---|---|---|---|
| L0 | Up to 4 × sstable_size_in_mb | No | 1-4 |
| L1 | fanout_size × L0 size | Yes | ~10 |
| L2 | fanout_size × L1 size | Yes | ~100 |
| L3+ | fanout_size × previous | Yes | ~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.
Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
keyspace | Name of the keyspace containing the table |
table | Name of the table to reset levels |
Options
Section titled “Options”| Option | Description |
|---|---|
--really-reset | Required safety flag to confirm reset |
The --really-reset flag is mandatory to prevent accidental execution.
Examples
Section titled “Examples”Basic Usage
Section titled “Basic Usage”# Stop Cassandra firstsudo systemctl stop cassandra
# Reset all SSTables to level 0sstablelevelreset --really-reset my_keyspace my_table
# Start Cassandra - LCS will reorganize levelssudo systemctl start cassandraVerify Current Levels
Section titled “Verify Current Levels”# Before reset - check level distributionsstablemetadata /var/lib/cassandra/data/my_keyspace/my_table-*/*-Data.db | grep "SSTable Level"Reset All LCS Tables
Section titled “Reset All LCS Tables”#!/bin/bash# reset_lcs_tables.sh - Reset levels for all LCS tables
KEYSPACE="$1"
# Find tables using LCSlcs_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"doneWhen to Use sstablelevelreset
Section titled “When to Use sstablelevelreset”Scenario 1: Corrupted Level Metadata
Section titled “Scenario 1: Corrupted Level Metadata”# Symptoms:# - Cassandra logs show "Level X has Y SSTables but should have Z"# - Unexpected compaction behavior# - Compaction stats show wrong level distribution
# Check current statenodetool cfstats my_keyspace.my_table | grep -i level
# Reset levelssudo systemctl stop cassandrasstablelevelreset --really-reset my_keyspace my_tablesudo systemctl start cassandraScenario 2: After Switching to LCS
Section titled “Scenario 2: After Switching to LCS”# When migrating from STCS to LCS
# 1. Change compaction strategycqlsh -e "ALTER TABLE my_keyspace.my_table WITH compaction = { 'class': 'LeveledCompactionStrategy'};"
# 2. Stop Cassandrasudo 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 levelssudo systemctl start cassandra
# 5. Monitor compaction progressnodetool compactionstatsScenario 3: Compaction Stuck
Section titled “Scenario 3: Compaction Stuck”# Symptoms:# - Compaction not progressing# - High number of SSTables# - Levels are imbalanced
# Check level distributionfor 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, resetsudo systemctl stop cassandrasstablelevelreset --really-reset my_keyspace my_tablesudo systemctl start cassandraScenario 4: Recovery from sstableofflinerelevel Issues
Section titled “Scenario 4: Recovery from sstableofflinerelevel Issues”# If sstableofflinerelevel caused problems# Reset to clean state and let LCS reorganize
sudo systemctl stop cassandrasstablelevelreset --really-reset my_keyspace my_tablesudo systemctl start cassandraImpact of Level Reset
Section titled “Impact of Level Reset”Before Reset
Section titled “Before Reset”Level Distribution:L0: 2 SSTables (320 MB)L1: 10 SSTables (1.6 GB)L2: 87 SSTables (14 GB)L3: 432 SSTables (69 GB)After Reset
Section titled “After Reset”Level Distribution:L0: 531 SSTables (85 GB) <- All SSTables moved hereL1: 0 SSTablesL2: 0 SSTablesL3: 0 SSTablesAfter Compaction Reorganization
Section titled “After Compaction Reorganization”Level Distribution:L0: 4 SSTables (640 MB) <- Back to normalL1: 10 SSTables (1.6 GB)L2: 100 SSTables (16 GB)L3: 450 SSTables (72 GB)Post-Reset Actions
Section titled “Post-Reset Actions”1. Start Cassandra
Section titled “1. Start Cassandra”sudo systemctl start cassandra2. Monitor Compaction
Section titled “2. Monitor Compaction”# Watch compaction progresswatch -n 5 'nodetool compactionstats'
# Check level distributionnodetool cfstats my_keyspace.my_table | grep -A10 "SSTables in each level"3. Verify Health
Section titled “3. Verify Health”# Ensure reads work correctlycqlsh -e "SELECT * FROM my_keyspace.my_table LIMIT 10;"
# Check for compaction errorsgrep -i "error\|exception" /var/log/cassandra/system.logsstablelevelreset vs sstableofflinerelevel
Section titled “sstablelevelreset vs sstableofflinerelevel”| Aspect | sstablelevelreset | sstableofflinerelevel |
|---|---|---|
| Action | Reset all to L0 | Recalculate optimal levels |
| Result | Clean slate | Reorganized levels |
| Compaction after | Heavy (reorganize all) | Minimal (already organized) |
| Use case | Corrupted metadata | Imbalanced levels |
| Safety | Conservative | More aggressive |
Decision Guide
Section titled “Decision Guide”Troubleshooting
Section titled “Troubleshooting”Permission Denied
Section titled “Permission Denied”# Run as cassandra usersudo -u cassandra sstablelevelreset --really-reset my_keyspace my_table
# Or fix permissionssudo chown -R cassandra:cassandra /var/lib/cassandra/data/Cassandra Still Running
Section titled “Cassandra Still Running”# Error: Cannot run while Cassandra is active
# Stop Cassandra properlynodetool drainsudo systemctl stop cassandra
# Verify stoppedpgrep -f CassandraDaemon # Should return nothing
# Now run the toolsstablelevelreset --really-reset my_keyspace my_tableForgot --really-reset Flag
Section titled “Forgot --really-reset Flag”# Error: Must provide --really-reset flag
# The flag is required as a safety measuresstablelevelreset --really-reset my_keyspace my_tableHeavy Compaction After Reset
Section titled “Heavy Compaction After Reset”# After reset, LCS will compact aggressively to reorganize
# Option 1: Let it complete (recommended)# Monitor with:nodetool compactionstats
# Option 2: Throttle compaction if overwhelmingnodetool setcompactionthroughput 16 # 16 MB/sBest Practices
Section titled “Best Practices”sstablelevelreset Guidelines
- Last resort - Try
sstableofflinerelevelfirst for imbalanced levels - Backup first - Snapshot before running
- Plan for compaction - Heavy compaction will follow
- Off-peak timing - Run during maintenance windows
- Monitor after - Watch compaction progress
- One table at a time - Don't reset multiple tables simultaneously
- Verify result - Check level distribution after compaction settles
Cautions
- All SSTables move to L0 (causes heavy compaction)
- Only use for LCS tables
- Requires
--really-resetflag - Cannot be undone (must let compaction reorganize)
Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| sstableofflinerelevel | Recalculate levels (alternative) |
| sstablemetadata | Check current SSTable levels |
| nodetool compactionstats | Monitor compaction progress |
| nodetool tablestats | View level distribution |
| nodetool setcompactionthroughput | Control compaction speed |