{"record":{"id":"bb7cec27a597b385","repo":"apache/cassandra","slug":"first-position-reported-by-index-should-be-0-was","errorCode":null,"errorMessage":"First position reported by index should be 0, was %d, continuing without index.","messagePattern":"First position reported by index should be 0, was (.+?), continuing without index\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableScrubber.java","lineNumber":100,"sourceCode":"        catch (Throwable t)\n        {\n            outputHandler.warn(t, \"Index is unreadable, scrubbing will continue without index.\");\n        }\n        return null;\n    }\n\n    @Override\n    protected UnfilteredRowIterator withValidation(UnfilteredRowIterator iter, String filename)\n    {\n        return options.checkData && !isIndex ? UnfilteredRowIterators.withValidation(iter, filename) : iter;\n    }\n\n    @Override\n    public void scrubInternal(SSTableRewriter writer)\n    {\n        if (indexAvailable() && indexIterator.dataPosition() != 0)\n        {\n            outputHandler.warn(\"First position reported by index should be 0, was \" +\n                               indexIterator.dataPosition() +\n                               \", continuing without index.\");\n            indexIterator.close();\n            indexIterator = null;\n        }\n\n        DecoratedKey prevKey = null;\n\n        while (!dataFile.isEOF())\n        {\n            if (scrubInfo.isStopRequested())\n                throw new CompactionInterruptedException(scrubInfo.getCompactionInfo());\n\n            // position in a data file where the partition starts\n            long dataStart = dataFile.getFilePointer();\n            outputHandler.debug(\"Reading row at %d\", dataStart);\n\n            DecoratedKey key = null;","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableScrubber.java#L82-L118","documentation":"During a BTI (trie-indexed) sstable scrub, the first entry of the partition index must point to data file position 0 (the start of the first partition). If the index iterator reports any other position, the index is deemed misaligned/corrupt, so the scrubber closes it and falls back to scrubbing the data file without index assistance. This is a warning, not a fatal error: scrubbing continues in a slower, index-less mode.","triggerScenarios":"Running `nodetool scrub` on a BTI-format sstable whose PartitionIndex trie returns a first dataPosition() != 0, typically after partial index writes, crash mid-flush/compaction, or disk corruption affecting the index file.","commonSituations":"Nodes crashed or killed during memtable flush or compaction leaving a truncated/incorrect index; bit-rot or corrupted SSTable files restored from a bad backup; copying sstable files without freezing them first.","solutions":["Let the scrub finish — it continues without the index; verify the scrubbed output sstable afterward.","Run `nodetool scrub` (or recompact) on all sstables of the table to regenerate a valid index.","Check filesystem/hardware health (dmesg, SMART) for the data directory, since this indicates on-disk corruption.","If reproducible on fresh writes, upgrade or check the Cassandra version for known BTI index bugs before re-enabling the format."],"exampleFix":"// No caller-side code fix; recovery is operational.\n// before: sstable with corrupt BTI index reports first position != 0\n// after: nodetool scrub regenerates the sstable and index without the bad index\n$ nodetool scrub <keyspace> <table>","handlingStrategy":"fallback","validationCode":"// Verify sstable integrity before scrubbing\nSSTableReader sstable = ...;\nif (!sstable.isIndexPresent()) System.out.println(\"Index missing; scrub will run without index\");\n// or via tooling:\n// sstablemetadata <Data.db>  -> confirm consistent index component","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always snapshot sstables before copying or restoring them.","Never kill -9 during flush/compaction; drain first (nodetool drain).","Monitor disk health (SMART/fsck) on data directories.","Run nodetool verify periodically to catch index corruption early."],"tags":["cassandra","scrub","sstable","corrupt-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-17T15:17:12.973Z"}