Skip to content

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

nodetool scrub

Rebuilds SSTables by rewriting them, validating data and optionally discarding corrupted partitions.


Terminal window
nodetool [connection_options] scrub [options] [--] [keyspace [table ...]]

See connection options for connection options.

nodetool scrub reads SSTables and rewrites them, performing validation and cleanup. It can:

  • Fix SSTable corruption
  • Rewrite SSTables in current format
  • Remove corrupt data (with -s flag)
  • Validate partition ordering

Scrub operates locally and does not involve other nodes.


SSTable corruption is relatively rare but can occur due to several factors:

CauseDescription
Hardware failuresFailing disks, bad sectors, faulty RAID controllers, or memory errors (bit flips) can corrupt data during writes or reads
Unexpected process terminationIf Cassandra is killed (SIGKILL) or crashes during SSTable writes or compaction, partially written files may be corrupted
Power lossSudden power failure without proper shutdown can leave SSTables in an inconsistent state, particularly if disk write caches were not flushed
Filesystem issuesBugs in the filesystem, filesystem corruption, or running out of disk space during writes
Network storage problemsWhen using network-attached storage (NAS/SAN), network interruptions during writes can cause corruption
Kernel or driver bugsBugs in storage drivers, kernel I/O subsystems, or virtualization layers
Manual file manipulationAccidental deletion, modification, or truncation of SSTable files
Software bugsRarely, bugs in Cassandra itself during compaction or SSTable generation

Prevention

  • Use ECC memory to prevent bit flips
  • Configure disk write caching appropriately (battery-backed or disabled)
  • Ensure proper shutdown procedures
  • Monitor disk health with S.M.A.R.T.
  • Use checksums (enabled by default in Cassandra)
  • Maintain adequate free disk space

ArgumentDescription
keyspaceKeyspace to scrub. If omitted, scrubs all keyspaces
tableSpecific table(s) to scrub

OptionDescriptionDefault
-j, --jobsNumber of concurrent scrub jobs. 0 means use all available compaction threads2
-n, --no-validateSkip validation (faster but less thorough)
-ns, --no-snapshotDo not take a snapshot before scrubbing
-r, --reinsert-overflowed-ttlReinsert rows with overflowed TTL
-s, --skip-corruptedSkip corrupted partitions instead of failing

Default Snapshot Behavior

By default, scrub creates a snapshot of tables before scrubbing. Use -ns to skip this if space is limited.


When logs show SSTable corruption:

ERROR [CompactionExecutor:1] CorruptSSTableException: Corrupted: /var/lib/cassandra/data/...
Terminal window
nodetool scrub my_keyspace my_table

If Cassandra crashed or was killed:

Terminal window
# Check for corruption first
nodetool verify my_keyspace
# If issues found
nodetool scrub my_keyspace

Following disk I/O errors that may have corrupted data:

Terminal window
nodetool scrub my_keyspace

After modifying compression or other SSTable settings:

Terminal window
nodetool scrub my_keyspace my_table

Not for Regular Use

Scrub is a repair operation for corruption, not routine maintenance:

  • Rewrites all SSTables (resource intensive)
  • Should only be used when corruption is suspected
  • Normal compaction handles most SSTable maintenance
Terminal window
# First verify if scrub is actually needed
nodetool verify my_keyspace my_table

If verify passes without errors, scrub is unnecessary.

Performance Impact

Scrub is I/O intensive:

  • Reads all SSTables
  • Writes new SSTables
  • Can impact production workloads

Run during maintenance windows.


Terminal window
nodetool scrub my_keyspace my_table

If corruption is found, scrub fails and stops:

ERROR: Scrub failed because of corrupted data at position X
Terminal window
nodetool scrub -s my_keyspace my_table

Data Loss Warning

The -s flag discards corrupted partitions:

  • Corrupted data is permanently lost
  • No way to recover skipped partitions
  • Use only when data loss is acceptable

After using -s, run repair to recover data from replicas:

Terminal window
nodetool repair my_keyspace my_table

  1. Read SSTable sequentially
  2. Validate partition ordering
  3. Check partition data integrity
  4. If corruption found:
    • With -s: Log and skip corrupted partition
    • Without -s: Fail scrub immediately
  5. Write valid partition to new SSTable
  6. Repeat for all partitions
  7. Replace old SSTable with new one

Terminal window
nodetool scrub my_keyspace my_table
Terminal window
nodetool scrub my_keyspace
Terminal window
nodetool scrub -s my_keyspace my_table
Terminal window
nodetool scrub -n my_keyspace my_table
Terminal window
nodetool scrub -j 4 my_keyspace

Terminal window
nodetool compactionstats

Scrub appears as a compaction operation.

Terminal window
tail -f /var/log/cassandra/system.log | grep -i scrub

Logs show:

  • Progress
  • Any corruption found
  • Partitions skipped (if -s used)
  • Completion status

Space Needed

Scrub rewrites SSTables, requiring temporary space:

Space needed ≈ Size of largest SSTable being scrubbed

Ensure sufficient free space before running scrub.

Check space:

Terminal window
df -h /var/lib/cassandra/data
nodetool tablestats my_keyspace.my_table | grep "Space used"

Terminal window
# Step 1: Identify corrupted table from logs
# Look for CorruptSSTableException in system.log
# Step 2: Verify corruption
nodetool verify my_keyspace my_table
# Step 3: Attempt scrub without skip (preserves data if possible)
nodetool scrub my_keyspace my_table
# Step 4: If scrub fails, use skip-corrupted
nodetool scrub -s my_keyspace my_table
# Step 5: Repair to recover lost data from replicas
nodetool repair -pr my_keyspace my_table

ERROR: Not enough space to scrub

Solutions:

  • Free disk space
  • Scrub one table at a time
  • Move data files to larger volume

Large tables take significant time:

Table SizeApproximate Duration
10 GB10-30 minutes
100 GB1-3 hours
1 TB10+ hours

If corruption keeps appearing:

  1. Check disk health
  2. Check for memory errors
  3. Review system logs
  4. May indicate hardware failure

CommandPurpose
scrubFix corrupted SSTables
verifyCheck for corruption (read-only)
compactMerge SSTables (not for corruption)
repairSync data between replicas
upgradesstablesConvert SSTables to new format
Terminal window
# Check first
nodetool verify my_keyspace my_table
# Scrub only if verify fails
nodetool scrub my_keyspace my_table

Scrub Guidelines

  1. Verify first - Confirm corruption before scrubbing
  2. Check disk space - Ensure room for rewritten SSTables
  3. Off-peak hours - High I/O impact
  4. One table at a time - For large keyspaces
  5. Repair after skip - Recover data from replicas
  6. Investigate root cause - Corruption indicates underlying issues

CommandRelationship
compactMerge SSTables
repairSync replicas (run after scrub with -s)
tablestatsCheck table health