sstableupgrade
Rewrites SSTables to the current Cassandra version format for compatibility after major version upgrades.
Synopsis
Section titled “Synopsis”sstableupgrade [options] <keyspace> <table> [snapshot]Description
Section titled “Description”sstableupgrade rewrites SSTable files from older Cassandra versions to the format used by the currently installed version. This is necessary after upgrading Cassandra to a new major version, as SSTable formats may change between versions.
While Cassandra can read SSTables from previous versions during normal operation, upgrading SSTables provides:
- Performance improvements - New formats may have better compression or indexing
- Feature compatibility - Some features require the latest SSTable format
- Reduced complexity - Eliminates need for backward-compatibility code paths
- Preparation for next upgrade - Each major version only supports reading from the previous version
Cassandra Must Be Stopped
Cassandra must be completely stopped before running sstableupgrade. Running this tool while Cassandra is active will cause data corruption.
How It Works
Section titled “How It Works”SSTable Version History
Section titled “SSTable Version History”| Cassandra Version | SSTable Format | Format ID |
|---|---|---|
| 2.0.x | Legacy | jb |
| 2.1.x | Legacy | ka |
| 2.2.x | Legacy | la |
| 3.0.x | Big format | ma |
| 3.11.x | Big format | mb |
| 4.0.x | Big format | nb |
| 4.1.x | Big format | nc |
| 5.0.x | BTI format | oa |
Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
keyspace | Name of the keyspace containing the table |
table | Name of the table to upgrade |
snapshot | (Optional) Name of a specific snapshot to upgrade |
Snapshot Upgrade Breaks Hard Links
When upgrading a snapshot, the hard links between snapshot files and active data files are broken. This increases disk usage as the snapshot files become independent copies.
Options
Section titled “Options”| Option | Description |
|---|---|
-k, --keep-source | Keep original SSTables after upgrade (do not delete) |
-h, --help | Display help information |
--debug | Enable debug output |
Examples
Section titled “Examples”Basic Upgrade
Section titled “Basic Upgrade”# Stop Cassandra firstsudo systemctl stop cassandra
# Upgrade SSTables for a specific tablesstableupgrade my_keyspace my_table
# Start Cassandrasudo systemctl start cassandraKeep Original Files
Section titled “Keep Original Files”# Upgrade but keep old SSTables (useful for rollback)sstableupgrade -k my_keyspace my_table
# Verify new SSTables work, then manually remove old onesUpgrade All Tables in Keyspace
Section titled “Upgrade All Tables in Keyspace”#!/bin/bashKEYSPACE="$1"DATA_DIR="/var/lib/cassandra/data"
if [ -z "$KEYSPACE" ]; then echo "Usage: $0 <keyspace>" exit 1fi
# Find all tables in keyspacefor table_dir in ${DATA_DIR}/${KEYSPACE}/*/; do table_name=$(basename "$table_dir" | cut -d'-' -f1) echo "Upgrading ${KEYSPACE}.${table_name}..." sstableupgrade "$KEYSPACE" "$table_name" if [ $? -ne 0 ]; then echo "ERROR: Failed to upgrade ${KEYSPACE}.${table_name}" exit 1 fidone
echo "All tables in ${KEYSPACE} upgraded successfully"Upgrade Entire Cluster
Section titled “Upgrade Entire Cluster”#!/bin/bashDATA_DIR="/var/lib/cassandra/data"
# Skip system keyspaces (they're upgraded automatically)SKIP_KEYSPACES="system system_schema system_auth system_distributed system_traces"
for ks_dir in ${DATA_DIR}/*/; do ks_name=$(basename "$ks_dir")
# Skip system keyspaces if echo "$SKIP_KEYSPACES" | grep -q "$ks_name"; then echo "Skipping system keyspace: $ks_name" continue fi
for table_dir in ${ks_dir}*/; do table_name=$(basename "$table_dir" | cut -d'-' -f1) echo "Upgrading ${ks_name}.${table_name}..." sstableupgrade "$ks_name" "$table_name" donedoneWhen to Use sstableupgrade
Section titled “When to Use sstableupgrade”Scenario 1: Post-Major-Upgrade
Section titled “Scenario 1: Post-Major-Upgrade”After upgrading Cassandra from one major version to another:
# Example: After upgrading from 3.11 to 4.0
# 1. Complete rolling upgrade of all nodes# 2. Stop Cassandra on each node and run sstableupgrade offline# (For online upgrade, use nodetool upgradesstables instead)
sudo systemctl stop cassandra
# 3. Upgrade user keyspacesfor ks in my_keyspace other_keyspace; do for table_dir in /var/lib/cassandra/data/$ks/*/; do table=$(basename "$table_dir" | cut -d'-' -f1) sstableupgrade "$ks" "$table" donedone
sudo systemctl start cassandraScenario 2: Preparing for Next Upgrade
Section titled “Scenario 2: Preparing for Next Upgrade”Upgrade SSTables before the next major version upgrade:
# Cassandra 4.x can read 3.x SSTables# But Cassandra 5.x may not read 3.x SSTables# Upgrade now to ensure compatibility
sstableupgrade my_keyspace my_tableScenario 3: Enabling New Features
Section titled “Scenario 3: Enabling New Features”Some features require the latest SSTable format:
# Example: New compression algorithm only available in latest formatsstableupgrade my_keyspace my_table
# Then modify table to use new compressioncqlsh -e "ALTER TABLE my_keyspace.my_table WITH compression = {'class': 'ZstdCompressor'};"Upgrade Process Flow
Section titled “Upgrade Process Flow”Verification
Section titled “Verification”Before Upgrade
Section titled “Before Upgrade”# Check current SSTable versionssstablemetadata /var/lib/cassandra/data/my_keyspace/my_table-*/nb-*-big-Data.db | grep "SSTable Version"
# Sample output:# SSTable Version: mb
# List all SSTables and their versionsfor f in /var/lib/cassandra/data/my_keyspace/my_table-*/*-Data.db; do version=$(echo "$f" | grep -oP '\w{2}(?=-\d+-big-Data\.db)') echo "$version: $f"doneAfter Upgrade
Section titled “After Upgrade”# Verify all SSTables are now current versionsstablemetadata /var/lib/cassandra/data/my_keyspace/my_table-*/*-Data.db | grep "SSTable Version"
# Verify Cassandra can read upgraded SSTablessudo systemctl start cassandracqlsh -e "SELECT COUNT(*) FROM my_keyspace.my_table;"Resource Requirements
Section titled “Resource Requirements”Disk Space
Section titled “Disk Space”Upgrading requires space for both old and new SSTables temporarily:
# Check current table sizedu -sh /var/lib/cassandra/data/my_keyspace/my_table-*/
# Ensure at least 2x the size is availabledf -h /var/lib/cassandra/data/Time Estimates
Section titled “Time Estimates”| Data Size | Approximate Time |
|---|---|
| 1 GB | 1-2 minutes |
| 10 GB | 10-20 minutes |
| 100 GB | 1-3 hours |
| 1 TB | 10-30 hours |
Times vary based on disk speed and SSTable compression.
Troubleshooting
Section titled “Troubleshooting”Out of Disk Space
Section titled “Out of Disk Space”# Error: No space left on device
# Check available spacedf -h /var/lib/cassandra/data/
# Options:# 1. Free up space by removing old snapshotsnodetool clearsnapshot
# 2. Upgrade tables one at a timesstableupgrade my_keyspace small_table_first
# 3. Use --keep-source and manually manage old filessstableupgrade -k my_keyspace my_table# Verify new files work, then remove old onesrm /var/lib/cassandra/data/my_keyspace/my_table-*/ma-*Permission Denied
Section titled “Permission Denied”# Run as cassandra usersudo -u cassandra sstableupgrade my_keyspace my_table
# Or fix ownership aftersudo chown -R cassandra:cassandra /var/lib/cassandra/data/Upgrade Fails Mid-Process
Section titled “Upgrade Fails Mid-Process”# If upgrade fails partway through:
# 1. Check for incomplete filesls -la /var/lib/cassandra/data/my_keyspace/my_table-*/*.tmp
# 2. Remove incomplete filesrm /var/lib/cassandra/data/my_keyspace/my_table-*/*.tmp
# 3. The old SSTables should still be intact# 4. Retry the upgradesstableupgrade my_keyspace my_tableSchema Mismatch Errors
Section titled “Schema Mismatch Errors”# Error: Unknown column or schema mismatch
# This can happen if schema changed after SSTables were written# Option 1: Scrub firstsstablescrub --no-validate my_keyspace my_tablesstableupgrade my_keyspace my_table
# Option 2: Check schema historycqlsh -e "DESCRIBE TABLE my_keyspace.my_table;"Alternative: Online Upgrade
Section titled “Alternative: Online Upgrade”In Cassandra 4.0+, nodetool upgradesstables performs online upgrades:
# Online upgrade (Cassandra must be running)nodetool upgradesstables my_keyspace my_table
# Upgrade all tables in keyspacenodetool upgradesstables my_keyspace
# Upgrade with parallel jobsnodetool upgradesstables -j 4 my_keyspacesstableupgrade vs nodetool upgradesstables
Section titled “sstableupgrade vs nodetool upgradesstables”| Aspect | sstableupgrade | nodetool upgradesstables |
|---|---|---|
| Cassandra state | Must be stopped | Must be running |
| Resource usage | Dedicated resources | Shares with operations |
| Speed | Generally faster | Throttled for stability |
| When to use | During maintenance window | Rolling/live upgrade |
| Compaction strategy | Ignores | Follows configured strategy |
Best Practices
Section titled “Best Practices”sstableupgrade Guidelines
- Always backup first - Snapshot before upgrading SSTables
- Upgrade during maintenance - Plan for downtime
- Check disk space - Need 2x table size temporarily
- Upgrade one keyspace at a time - Easier to track progress
- Verify after upgrade - Run verification queries
- Plan for time - Large tables take hours
- Consider online upgrade - Use
nodetool upgradesstablesfor 4.0+
Cautions
- Cannot downgrade SSTables to older format
- Original SSTables are deleted by default
- Use
-kflag if rollback might be needed - Disk space is critical - monitor during operation
Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| nodetool upgradesstables | Online upgrade alternative |
| sstableverify | Verify SSTables before/after |
| sstablemetadata | Check SSTable version |
| sstablescrub | Fix corruption before upgrade |
| nodetool snapshot | Backup before upgrade |