{"record":{"id":"aed8d7ea70ec36ab","repo":"apache/cassandra","slug":"unable-to-read-partition-key-from-data-file","errorCode":null,"errorMessage":"Unable to read partition key from data file","messagePattern":"Unable to read partition key from data file","errorType":"exception","errorClass":"IOError","httpStatus":null,"severity":"critical","filePath":"src/java/org/apache/cassandra/io/sstable/format/big/BigTableScrubber.java","lineNumber":154,"sourceCode":"            if (indexAvailable())\n            {\n                if (currentIndexKey != null)\n                {\n                    dataStartFromIndex = currentPartitionPositionFromIndex + 2 + currentIndexKey.remaining();\n                    dataSizeFromIndex = nextPartitionPositionFromIndex - dataStartFromIndex;\n                }\n            }\n\n            long dataStart = dataFile.getFilePointer();\n\n            String keyName = key == null ? \"(unreadable key)\" : keyString(key);\n            outputHandler.debug(\"partition %s is %s\", keyName, FBUtilities.prettyPrintMemory(dataSizeFromIndex));\n            assert currentIndexKey != null || !indexAvailable();\n\n            try\n            {\n                if (key == null)\n                    throw new IOError(new IOException(\"Unable to read partition key from data file\"));\n\n                if (currentIndexKey != null && !key.getKey().equals(currentIndexKey))\n                {\n                    throw new IOError(new IOException(String.format(\"Key from data file (%s) does not match key from index file (%s)\",\n                                                                    //ByteBufferUtil.bytesToHex(key.getKey()), ByteBufferUtil.bytesToHex(currentIndexKey))));\n                                                                    \"_too big_\", ByteBufferUtil.bytesToHex(currentIndexKey))));\n                }\n\n                if (indexFile != null && dataSizeFromIndex > dataFile.length())\n                    throw new IOError(new IOException(\"Impossible partition size (greater than file length): \" + dataSizeFromIndex));\n\n                if (indexFile != null && dataStart != dataStartFromIndex)\n                    outputHandler.warn(\"Data file partition position %d differs from index file row position %d\", dataStart, dataStartFromIndex);\n\n                if (tryAppend(prevKey, key, writer))\n                    prevKey = key;\n            }\n            catch (Throwable th)","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/format/big/BigTableScrubber.java#L136-L172","documentation":"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.","triggerScenarios":"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.","commonSituations":"Disk corruption/bitrot; crash mid-write leaving a truncated Data.db; failed bulk-loaded SSTable; restoring partial backups (Data.db present but incomplete).","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."],"exampleFix":"// before: scrub keeps failing on corrupt file\nnodetool scrub keyspace1 standard1  // IOError\n// after: remove bad sstable generation and re-repair\nrm /var/lib/cassandra/data/keyspace1/standard1-<gen>-big-Data.db (move aside)\nnodetool repair -pr keyspace1","handlingStrategy":"try-catch","validationCode":"// Java: check data file size sanity before scrubbing offline\nif (dataFile.length() < indexLastPosition())\n    logger.error(\"Data.db truncated relative to index; restore from replicas instead of scrubbing\");","typeGuard":null,"tryCatchPattern":"try {\n    scrubber.scrub();\n} catch (IOError e) {\n    if (e.getMessage().contains(\"Unable to read partition key\")) {\n        removeSstable(desc);\n        runRepair();\n    } else throw e;\n}","preventionTips":["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"],"tags":["sstable","scrub","corruption","data-file"],"backgroundTag":"file-read-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}