Skip to content

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

sstableupgrade

Rewrites SSTables to the current Cassandra version format for compatibility after major version upgrades.


Terminal window
sstableupgrade [options] <keyspace> <table> [snapshot]

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.


sstableupgrade Processsstableupgrade ProcessOld Version SSTablesstableupgradeNew Version SSTableFormat: ma (3.0)Data.dbIndex.dbStatistics.dbRead old formatDeserialize rowsSerialize to new formatWrite new SSTableFormat: nb (4.0)Data.dbIndex.dbStatistics.dbOlder SSTable formatUpdated to currentinstalled version format
Cassandra VersionSSTable FormatFormat ID
2.0.xLegacyjb
2.1.xLegacyka
2.2.xLegacyla
3.0.xBig formatma
3.11.xBig formatmb
4.0.xBig formatnb
4.1.xBig formatnc
5.0.xBTI formatoa

ArgumentDescription
keyspaceName of the keyspace containing the table
tableName 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.


OptionDescription
-k, --keep-sourceKeep original SSTables after upgrade (do not delete)
-h, --helpDisplay help information
--debugEnable debug output

Terminal window
# Stop Cassandra first
sudo systemctl stop cassandra
# Upgrade SSTables for a specific table
sstableupgrade my_keyspace my_table
# Start Cassandra
sudo systemctl start cassandra
Terminal window
# Upgrade but keep old SSTables (useful for rollback)
sstableupgrade -k my_keyspace my_table
# Verify new SSTables work, then manually remove old ones
upgrade_keyspace.sh
#!/bin/bash
KEYSPACE="$1"
DATA_DIR="/var/lib/cassandra/data"
if [ -z "$KEYSPACE" ]; then
echo "Usage: $0 <keyspace>"
exit 1
fi
# Find all tables in keyspace
for 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
fi
done
echo "All tables in ${KEYSPACE} upgraded successfully"
upgrade_all_sstables.sh
#!/bin/bash
DATA_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"
done
done

After upgrading Cassandra from one major version to another:

Terminal window
# 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 keyspaces
for 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"
done
done
sudo systemctl start cassandra

Upgrade SSTables before the next major version upgrade:

Terminal window
# 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_table

Some features require the latest SSTable format:

Terminal window
# Example: New compression algorithm only available in latest format
sstableupgrade my_keyspace my_table
# Then modify table to use new compression
cqlsh -e "ALTER TABLE my_keyspace.my_table
WITH compression = {'class': 'ZstdCompressor'};"

Complete SSTable Upgrade WorkflowComplete SSTable Upgrade WorkflowComplete Cassandra upgradeVerify cluster is healthyVerify node joins clusterRun nodetool repairNode completeRestore from snapshotInvestigate errorRetry upgradeStop Cassandra on nodeCreate snapshot (backup)Run sstableupgrade for each tableUpgrade successful?yesnoRemove old SSTablesStart CassandraAdminNode OperationsSSTable Upgrade

Terminal window
# Check current SSTable versions
sstablemetadata /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 versions
for 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"
done
Terminal window
# Verify all SSTables are now current version
sstablemetadata /var/lib/cassandra/data/my_keyspace/my_table-*/*-Data.db | grep "SSTable Version"
# Verify Cassandra can read upgraded SSTables
sudo systemctl start cassandra
cqlsh -e "SELECT COUNT(*) FROM my_keyspace.my_table;"

Upgrading requires space for both old and new SSTables temporarily:

Terminal window
# Check current table size
du -sh /var/lib/cassandra/data/my_keyspace/my_table-*/
# Ensure at least 2x the size is available
df -h /var/lib/cassandra/data/
Data SizeApproximate Time
1 GB1-2 minutes
10 GB10-20 minutes
100 GB1-3 hours
1 TB10-30 hours

Times vary based on disk speed and SSTable compression.


Terminal window
# Error: No space left on device
# Check available space
df -h /var/lib/cassandra/data/
# Options:
# 1. Free up space by removing old snapshots
nodetool clearsnapshot
# 2. Upgrade tables one at a time
sstableupgrade my_keyspace small_table_first
# 3. Use --keep-source and manually manage old files
sstableupgrade -k my_keyspace my_table
# Verify new files work, then remove old ones
rm /var/lib/cassandra/data/my_keyspace/my_table-*/ma-*
Terminal window
# Run as cassandra user
sudo -u cassandra sstableupgrade my_keyspace my_table
# Or fix ownership after
sudo chown -R cassandra:cassandra /var/lib/cassandra/data/
Terminal window
# If upgrade fails partway through:
# 1. Check for incomplete files
ls -la /var/lib/cassandra/data/my_keyspace/my_table-*/*.tmp
# 2. Remove incomplete files
rm /var/lib/cassandra/data/my_keyspace/my_table-*/*.tmp
# 3. The old SSTables should still be intact
# 4. Retry the upgrade
sstableupgrade my_keyspace my_table
Terminal window
# Error: Unknown column or schema mismatch
# This can happen if schema changed after SSTables were written
# Option 1: Scrub first
sstablescrub --no-validate my_keyspace my_table
sstableupgrade my_keyspace my_table
# Option 2: Check schema history
cqlsh -e "DESCRIBE TABLE my_keyspace.my_table;"

In Cassandra 4.0+, nodetool upgradesstables performs online upgrades:

Terminal window
# Online upgrade (Cassandra must be running)
nodetool upgradesstables my_keyspace my_table
# Upgrade all tables in keyspace
nodetool upgradesstables my_keyspace
# Upgrade with parallel jobs
nodetool upgradesstables -j 4 my_keyspace

sstableupgrade vs nodetool upgradesstables

Section titled “sstableupgrade vs nodetool upgradesstables”
Aspectsstableupgradenodetool upgradesstables
Cassandra stateMust be stoppedMust be running
Resource usageDedicated resourcesShares with operations
SpeedGenerally fasterThrottled for stability
When to useDuring maintenance windowRolling/live upgrade
Compaction strategyIgnoresFollows configured strategy

sstableupgrade Guidelines

  1. Always backup first - Snapshot before upgrading SSTables
  2. Upgrade during maintenance - Plan for downtime
  3. Check disk space - Need 2x table size temporarily
  4. Upgrade one keyspace at a time - Easier to track progress
  5. Verify after upgrade - Run verification queries
  6. Plan for time - Large tables take hours
  7. Consider online upgrade - Use nodetool upgradesstables for 4.0+

Cautions

  • Cannot downgrade SSTables to older format
  • Original SSTables are deleted by default
  • Use -k flag if rollback might be needed
  • Disk space is critical - monitor during operation

CommandRelationship
nodetool upgradesstablesOnline upgrade alternative
sstableverifyVerify SSTables before/after
sstablemetadataCheck SSTable version
sstablescrubFix corruption before upgrade
nodetool snapshotBackup before upgrade