{"record":{"id":"a8451949ffc02f9e","repo":"apache/cassandra","slug":"the-tree-position-is-less-than-zero","errorCode":null,"errorMessage":"The tree position is less than zero.","messagePattern":"The tree position is less than zero\\.","errorType":"exception","errorClass":"CorruptIndexException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/index/sai/disk/v1/segment/NumericIndexSegmentSearcher.java","lineNumber":63,"sourceCode":" * Executes {@link Expression}s against the balanced tree for an individual index segment.\n */\npublic class NumericIndexSegmentSearcher extends IndexSegmentSearcher\n{\n    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());\n\n    private final BlockBalancedTreeReader treeReader;\n    private final QueryEventListener.BalancedTreeEventListener perColumnEventListener;\n\n    NumericIndexSegmentSearcher(PrimaryKeyMap.Factory primaryKeyMapFactory,\n                                PerColumnIndexFiles perIndexFiles,\n                                SegmentMetadata segmentMetadata,\n                                StorageAttachedIndex index) throws IOException\n    {\n        super(primaryKeyMapFactory, perIndexFiles, segmentMetadata, index);\n\n        final long treePosition = metadata.getIndexRoot(IndexComponent.BALANCED_TREE);\n        if (treePosition < 0)\n            throw new CorruptIndexException(index.identifier().logMessage(\"The tree position is less than zero.\"), IndexComponent.BALANCED_TREE.name);\n        final long postingsPosition = metadata.getIndexRoot(IndexComponent.POSTING_LISTS);\n        if (postingsPosition < 0)\n            throw new CorruptIndexException(index.identifier().logMessage(\"The postings position is less than zero.\"), IndexComponent.BALANCED_TREE.name);\n\n        treeReader = new BlockBalancedTreeReader(index.identifier(),\n                                                 indexFiles.balancedTree(),\n                                                 treePosition,\n                                                 indexFiles.postingLists(),\n                                                 postingsPosition);\n        perColumnEventListener = (QueryEventListener.BalancedTreeEventListener)index.columnQueryMetrics();\n    }\n\n    @Override\n    public long indexFileCacheSize()\n    {\n        return treeReader.memoryUsage();\n    }\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/index/sai/disk/v1/segment/NumericIndexSegmentSearcher.java#L45-L81","documentation":"The NumericIndexSegmentSearcher constructor reads the segment metadata root positions for the BALANCED_TREE and POSTING_LISTS components. A negative tree position is impossible in a valid segment file, so it throws a Lucene CorruptIndexException immediately — a cheap validity check before opening the block-balanced tree reader. (Note the postings check incorrectly labels itself BALANCED_TREE in the message.)","triggerScenarios":"Opening a numeric SAI segment whose metadata.getIndexRoot(IndexComponent.BALANCED_TREE) is < 0, i.e. metadata written without a tree root or pointing past invalid bounds.","commonSituations":"Partially written/truncated segment files after an unclean shutdown, disk corruption, or descriptor/metadata version mismatch after an upgrade or failed flush.","solutions":["Rebuild the SAI index (nodetool rebuild_index or DROP/CREATE INDEX).","Restore the affected SSTable/index components from a snapshot or backup.","Check Cassandra version and disk health; if reproducible after normal flush, report as an internal write-path bug."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"long pos = segmentMetadata.getIndexRoot(IndexComponent.BALANCED_TREE); if (pos < 0) flagCorruptSegment();","typeGuard":null,"tryCatchPattern":"try { searcher = new NumericIndexSegmentSearcher(...); } catch (CorruptIndexException e) { log.error(\"Corrupt numeric segment metadata\", e); markSegmentUnreadable(); }","preventionTips":["Verify index metadata roots on segment open and quarantine bad segments.","Rebuild the index and restore components from snapshots after corruption is detected."],"tags":["cassandra","sai","index-corruption","metadata"],"backgroundTag":"internal-invariant-violation","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"}