{"record":{"id":"afb01b8ecffdaa30","repo":"apache/cassandra","slug":"compactionstress-does-not-support-secondary-indexe","errorCode":null,"errorMessage":"CompactionStress does not support secondary indexes","messagePattern":"CompactionStress does not support secondary indexes","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/stress/CompactionStress.java","lineNumber":160,"sourceCode":"                    continue;\n\n                try\n                {\n                    SSTableReader sstable = SSTableReader.openNoValidation(entry.getKey(), components, cfs);\n                    sstables.add(sstable);\n                }\n                catch (Exception e)\n                {\n                    JVMStabilityInspector.inspectThrowable(e);\n                    System.err.println(String.format(\"Error Loading %s: %s\", entry.getKey(), e.getMessage()));\n                }\n            }\n\n            cfs.disableAutoCompaction();\n\n            // We want to add the SSTables without firing their indexing by any eventual unsupported 2i\n            if (cfs.indexManager.hasIndexes())\n                throw new IllegalStateException(\"CompactionStress does not support secondary indexes\");\n\n            //Register with cfs\n            cfs.addSSTables(sstables);\n        }\n\n        return cfs;\n    }\n\n    StressProfile getStressProfile()\n    {\n        try\n        {\n            File yamlFile = new File(profile);\n            return StressProfile.load(yamlFile.exists() ? yamlFile.toURI() : URI.create(profile));\n        }\n        catch ( IOError e)\n        {\n            e.printStackTrace();","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/stress/CompactionStress.java#L142-L178","documentation":"CompactionStress loads existing SSTables into a ColumnFamilyStore so compaction strategies can be exercised offline. It explicitly skips registering the SSTables with any indexes; if the loaded table already has secondary indexes defined (indexManager.hasIndexes()), the tool throws IllegalStateException because compaction-stress cannot reproduce index-driven behavior and would produce misleading results. This is a deliberate unsupported-feature guard, not a corruption indicator.","triggerScenarios":"Running compactionstress against a table (schema loaded from the sstable's schema or a provided schema) that has secondary indexes defined, i.e. cfs.indexManager.hasIndexes() returns true after the SSTables are inspected in initCf.","commonSituations":"Pointing compactionstress at SSTables dumped from a production table that has 2i/SAI indexes defined in its schema; forgetting that indexes are part of the table schema even if the dumped files contain no index data.","solutions":["Remove or drop the secondary indexes from the schema used for the stress run (edit the schema DDL / options provided to compactionstress).","Run compactionstress on a copy of the table whose schema has no indexes defined.","If you need to test index compaction behavior, use a full cluster with real writes instead of compactionstress.","Wrap the invocation to catch IllegalStateException and print guidance that 2i tables are unsupported."],"exampleFix":"// before\nCREATE TABLE ks.t (k int PRIMARY KEY, v text);\nCREATE INDEX t_v_idx ON ks.t (v);\n// after\nCREATE TABLE ks.t (k int PRIMARY KEY, v text); // no index for compactionstress","handlingStrategy":"try-catch","validationCode":"// before running compactionstress, inspect schema for indexes:\n// cqlsh -e \"DESCRIBE TABLE ks.t\" | grep -i \"CREATE INDEX\"\nboolean hasIndexes = schemaDDL.toUpperCase().contains(\"CREATE INDEX\");\nif (hasIndexes) throw new IllegalStateException(\"compactionstress unsupported for indexed tables\");","typeGuard":null,"tryCatchPattern":"try {\n    compactionStress.initCf(...);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"secondary indexes\")) {\n        System.err.println(\"Drop indexes from the schema or use a full cluster for this table.\");\n        return;\n    }\n    throw e;\n}","preventionTips":["Strip CREATE INDEX statements from schemas used with compactionstress.","Document that compactionstress supports only plain (non-indexed) tables.","Snapshot production schemas into a sanitized DDL before offline testing."],"tags":["compaction","secondary-index","unsupported-feature"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}