{"record":{"id":"6868f1defca7e2ed","repo":"apache/cassandra","slug":"key-from-data-file-s-does-not-match-key-from-in-6868f1","errorCode":null,"errorMessage":"Key from data file (%s) does not match key from index file (%s)","messagePattern":"Key from data file \\((.+?)\\) does not match key from index file \\((.+?)\\)","errorType":"exception","errorClass":"IOError","httpStatus":null,"severity":"critical","filePath":"src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableScrubber.java","lineNumber":177,"sourceCode":"                        indexIterator = null;\n                        currentIndexKey = null;\n                        dataStartFromIndex = -1;\n                        dataSizeFromIndex = -1;\n                    }\n                }\n            }\n\n            String keyName = key == null ? \"(unreadable key)\" : keyString(key);\n            outputHandler.debug(\"partition %s is %s\", keyName, FBUtilities.prettyPrintMemory(dataSizeFromIndex));\n\n            try\n            {\n                if (key == null)\n                    throw new IOError(new IOException(\"Unable to read partition key from data file\", keyReadError));\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                }\n\n                if (indexIterator != null && dataSizeFromIndex > dataFile.length())\n                    throw new IOError(new IOException(\"Impossible partition size (greater than file length): \" + dataSizeFromIndex));\n\n                if (indexIterator != 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)\n            {\n                throwIfFatal(th);\n                outputHandler.warn(th, \"Error reading partition %s (stacktrace follows):\", keyName);\n\n                if (currentIndexKey != null","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableScrubber.java#L159-L195","documentation":"Thrown during BTI sstable scrub when the partition key read from the data file does not match the key recorded in the index file for the same partition. This indicates index/data divergence — the data file content is not at the position the index expects, a strong sign of file corruption or interleaved/mismatched components.","triggerScenarios":"Scrubbing a BTI sstable where the data file was modified, truncated, or mixed with a different generation's index file; dataStart points to a different partition than currentIndexKey.","commonSituations":"Manually copied or renamed sstable components mixing generations, restore of partial backups, corruption from hardware failure, upgrades leaving mismatched components.","solutions":["Restore the complete, matching set of sstable components (Data.db, Index.db, etc.) from backup","Drop the corrupt sstable and run repair to stream data from replicas","Check that sstable files were not manually renamed — component generation must match the TOC","Scrub with --no-validate to salvage what is readable, accepting some data loss"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure index and data components belong to the same generation before scrub\nif (!dataFile.getName().equals(indexFile.getName())) throw new IllegalStateException(\"component generation mismatch\");","typeGuard":null,"tryCatchPattern":"try { scrubInternal(...); } catch (IOError e) { logger.error(\"index/data key mismatch: restore matching components\", e); }","preventionTips":["Never rename or hand-edit sstable component files","Restore backups as complete sets","Run repair to reconcile divergent replicas","Snapshot before scrub"],"tags":["io","corruption","sstable","index"],"backgroundTag":"checksum-mismatch","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"}