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
BigTableScrubber.scrubInternal reads the next partition key from the data file while scrubbing. If the key cannot be deserialized from the data file (key == null), it throws IOError('Unable to read partition key from data file'). This indicates the Data.db is damaged at the partition boundary such that scrub cannot even identify the partition it is reading.
Source
Thrown at src/java/org/apache/cassandra/io/sstable/format/big/BigTableScrubber.java:154
if (indexAvailable())
{
if (currentIndexKey != null)
{
dataStartFromIndex = currentPartitionPositionFromIndex + 2 + currentIndexKey.remaining();
dataSizeFromIndex = nextPartitionPositionFromIndex - dataStartFromIndex;
}
}
long dataStart = dataFile.getFilePointer();
String keyName = key == null ? "(unreadable key)" : keyString(key);
outputHandler.debug("partition %s is %s", keyName, FBUtilities.prettyPrintMemory(dataSizeFromIndex));
assert currentIndexKey != null || !indexAvailable();
try
{
if (key == null)
throw new IOError(new IOException("Unable to read partition key from data file"));
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))));
"_too big_", ByteBufferUtil.bytesToHex(currentIndexKey))));
}
if (indexFile != null && dataSizeFromIndex > dataFile.length())
throw new IOError(new IOException("Impossible partition size (greater than file length): " + dataSizeFromIndex));
if (indexFile != 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
- Delete the unreadable SSTable from the data directory and run `nodetool repair` to restore from replicas.
- Try `nodetool scrub` on a copy if not already done — this error means scrub itself hit an unreadable region; no recovery is possible from that file section.
- If replicas exist, this data loss is benign; ensure repair -pr runs on all ranges.
- Check disk health and replace failing hardware to prevent recurrence.
Example fix
// before: scrub keeps failing on corrupt file nodetool scrub keyspace1 standard1 // IOError // after: remove bad sstable generation and re-repair rm /var/lib/cassandra/data/keyspace1/standard1-<gen>-big-Data.db (move aside) nodetool repair -pr keyspace1
Defensive patterns
Strategy: try-catch
Validate before calling
// Java: check data file size sanity before scrubbing offline
if (dataFile.length() < indexLastPosition())
logger.error("Data.db truncated relative to index; restore from replicas instead of scrubbing"); Try / catch
try {
scrubber.scrub();
} catch (IOError e) {
if (e.getMessage().contains("Unable to read partition key")) {
removeSstable(desc);
runRepair();
} else throw e;
} Prevention
- Monitor scrub/verify output proactively to catch corruption at first unreadable byte
- Keep healthy replicas so removal + repair is a safe recovery path
- Use hardware RAID/ZFS checksums to detect media errors early
- Never bulk-load partially generated SSTables
When it happens
Trigger: During `nodetool scrub`, reading a partition whose key bytes in Data.db are unreadable — truncated file at a partition boundary, corrupted key length prefix, or a data file shorter than the index claims, so the reader returns null for the key.
Common situations: Disk corruption/bitrot; crash mid-write leaving a truncated Data.db; failed bulk-loaded SSTable; restoring partial backups (Data.db present but incomplete).
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
- Impossible partition size (greater than file length):
- Key from data file (%s) does not match key from index file (
- Unable to read partition key from data file
- Error reading partition %s (stacktrace follows):
- Corrupt flags value for clustering prefix (isStatic flag set
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/aed8d7ea70ec36ab.
Report an issue: GitHub.