{"record":{"id":"651f31724789aa3b","repo":"apache/cassandra","slug":"failed-to-advance-to-the-next-index-position-inde","errorCode":null,"errorMessage":"Failed to advance to the next index position. Index is corrupted. Continuing without the index. Last position read is %d.","messagePattern":"Failed to advance to the next index position\\. Index is corrupted\\. Continuing without the index\\. Last position read is (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableScrubber.java","lineNumber":154,"sourceCode":"            // size of the partition (including partition key)\n            long dataSizeFromIndex = -1;\n            ByteBuffer currentIndexKey = null;\n            if (indexAvailable())\n            {\n                currentIndexKey = indexIterator.key();\n                dataStartFromIndex = indexIterator.dataPosition();\n                if (!indexIterator.isExhausted())\n                {\n                    try\n                    {\n                        indexIterator.advance();\n                        if (!indexIterator.isExhausted())\n                            dataSizeFromIndex = indexIterator.dataPosition() - dataStartFromIndex;\n                    }\n                    catch (Throwable th)\n                    {\n                        throwIfFatal(th);\n                        outputHandler.warn(th,\n                                           \"Failed to advance to the next index position. Index is corrupted. \" +\n                                           \"Continuing without the index. Last position read is %d.\",\n                                           indexIterator.dataPosition());\n                        indexIterator.close();\n                        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)","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableScrubber.java#L136-L172","documentation":"While scrubbing with the BTI partition index, the scrubber advances the index iterator between partitions. If advancing throws (the index entries point at unreadable or inconsistent positions), the scrubber logs this warning, closes the index, and continues scrubbing the data file sequentially without index guidance. The message includes the last data position successfully read from the index to aid diagnosis.","triggerScenarios":"`nodetool scrub` iterating PartitionIndex entries on a BTI sstable where indexIterator.advance() throws due to truncated or corrupt index blocks, bad pointers in the trie, or data/index length mismatch.","commonSituations":"Incomplete compaction or flush leaves after a crash; corrupt sstables restored from backups; disks with silent corruption; manually truncated sstable files.","solutions":["Continue the scrub — it proceeds without the index and quarantines/repairs bad partitions.","After scrub completes, run `nodetool compact` on the table to rebuild a clean index.","Restore the affected sstables from a verified backup or repair the node with `nodetool repair`.","Investigate storage-layer corruption (fsck, SMART, RAID checks) on the data directory."],"exampleFix":"// Operational fix, not code:\n// before: scrub warns 'Failed to advance to the next index position' and drops the index\n// after: rebuild the sstable/index and verify\n$ nodetool scrub <keyspace> <table>\n$ nodetool compact <keyspace> <table>","handlingStrategy":"fallback","validationCode":"// Check sstable components exist and are non-trivial before scrub\n$ sstablemetadata <path>/xx-Data.db   # errors out on unreadable/corrupt sstable\n$ ls -l <path>/xx-Index.db            # should not be 0 bytes when Data.db is non-empty","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep Data.db and Index.db components from the same generation together when restoring.","Enable periodic scrub on a schedule to detect corruption proactively.","Watch node logs for earlier index warnings during flush/compaction.","Use verified snapshots for backups, not live file copies."],"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"}