apache/cassandra · critical · IOError
Unable to read partition key from data file
Error message
Unable to read partition key from data file
What it means
Thrown during BTI sstable scrub when the partition key cannot be read from the data file at the position indicated by the index. The scrubber wraps the underlying keyReadError (an IOException from reading the key) in an IOError, since scrubbing cannot proceed for a partition whose key is unreadable. It signals corruption in the data file's key section.
Source
Thrown at src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableScrubber.java:173
"Failed to advance to the next index position. Index is corrupted. " +
"Continuing without the index. Last position read is %d.",
indexIterator.dataPosition());
indexIterator.close();
indexIterator = null;
currentIndexKey = null;
dataStartFromIndex = -1;
dataSizeFromIndex = -1;
}
}
}
String keyName = key == null ? "(unreadable key)" : keyString(key);
outputHandler.debug("partition %s is %s", keyName, FBUtilities.prettyPrintMemory(dataSizeFromIndex));
try
{
if (key == null)
throw new IOError(new IOException("Unable to read partition key from data file", keyReadError));
if (currentIndexKey != null && !key.getKey().equals(currentIndexKey))
{
throw new IOError(new IOException(String.format("Key from data file (%s) does not match key from index file (%s)",
ByteBufferUtil.bytesToHex(key.getKey()), ByteBufferUtil.bytesToHex(currentIndexKey))));
}
if (indexIterator != null && dataSizeFromIndex > dataFile.length())
throw new IOError(new IOException("Impossible partition size (greater than file length): " + dataSizeFromIndex));
if (indexIterator != null && dataStart != dataStartFromIndex)
outputHandler.warn("Data file partition position %d differs from index file row position %d", dataStart, dataStartFromIndex);
if (tryAppend(prevKey, key, writer))
prevKey = key;
}
catch (Throwable th)
{View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Run `nodetool scrub` with --no-validate or restore the sstable from a backup/snapshot
- Check dmesg/storage health for underlying disk errors (SMART, RAID checks)
- If replication is available, let repair/anti-entropy restore the data and remove the corrupt sstable
- Set scrub to keep the bad files (default -n) and examine the corrupt file with sstablemetadata
Example fix
// before: repeatedly scrubbing a corrupt file nodetool scrub keyspace table // after: restore from snapshot then repair nodetool restore / restore sstable from snapshot; nodetool repair -pr keyspace
Defensive patterns
Strategy: try-catch
Validate before calling
// verify data file size and readability before scrub
File f = new File(dataFile); if (!f.exists() || f.length() == 0) throw new IllegalStateException("missing/truncated data file " + f); Type guard
if (key == null) { outputHandler.warn("unreadable partition key, skipping"); return false; } Try / catch
try { scrubInternal(...); } catch (IOError e) { logger.error("data file corrupt at partition key; restore or repair", e.getCause()); } Prevention
- Take snapshots before running scrub
- Monitor disk health (SMART) to catch corruption early
- Always repair after suspect disk events
- Copy sstables only as complete component sets
When it happens
Trigger: Running `nodetool scrub` on a BTI-format sstable whose data file has corruption in the bytes where a partition key should be, so key deserialization fails and `key == null`.
Common situations: Disk corruption or bit rot, truncated data files after a crash, faulty storage hardware, or copying sstables between nodes without corresponding files.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Corrupt flags value for clustering prefix (isStatic flag set
- Corrupted sstable. Invalid flags found deserializing Deletio
- Failed to import sstable <filename>
- Seeking to a partition at: ${position} did not land after an
- CorruptSSTableException wrapping IOException for ${path}
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/5352dda7b37bfa87.
Report an issue: GitHub.