{"record":{"id":"54c59ffec1a64df2","repo":"apache/cassandra","slug":"could-not-compact-segments-tocompact","errorCode":null,"errorMessage":"Could not compact segments: \" + toCompact","messagePattern":"Could not compact segments: \" \\+ toCompact","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/journal/Compactor.java","lineNumber":105,"sourceCode":"            toCompact.subList(limit, toCompact.size()).clear();\n        }\n\n        try\n        {\n            Collection<StaticSegment<K, V>> newSegments = segmentCompactor.compact(toCompact);\n\n            for (StaticSegment<K, V> segment : newSegments)\n                toCompact.remove(segment);\n\n            journal.replaceCompactedSegments(toCompact, newSegments);\n            for (StaticSegment<K, V> segment : toCompact)\n                segment.discard(journal);\n\n            compacted.signalAll();\n        }\n        catch (IOException e)\n        {\n            throw new RuntimeException(\"Could not compact segments: \" + toCompact);\n        }\n    }\n\n    @Override\n    public boolean isTerminated()\n    {\n        return executor.isTerminated();\n    }\n\n    @Override\n    public void shutdown()\n    {\n        logger.debug(\"Shutting down \" + executor);\n        if (scheduled != null)\n            scheduled.cancel(false);\n        executor.shutdown();\n    }\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/journal/Compactor.java#L87-L123","documentation":"The journal Compactor runs on its own thread; if compaction of a set of segments fails with an IOException, it wraps it in a RuntimeException after signalling completion. This is a fail-fast wrapper turning a checked I/O failure into an unchecked one for the scheduler thread.","triggerScenarios":"IOException while reading segments, rewriting filtered entries, or writing compacted output during Compactor.run(); disk full, permission errors, or segment files disappearing mid-compaction.","commonSituations":"Disk exhaustion on the commitlog/journal volume; concurrent recovery/cleanup deleting segments; filesystem errors (I/O errors, read-only mounts).","solutions":["Check disk space and filesystem health on the journal directory","Inspect the suppressed/cause stack (IOException) for the root cause; ensure logging captures it","Avoid deleting or manipulating segment files while compaction is active","Restart the journal/compactor thread after fixing the underlying I/O condition"],"exampleFix":"// before\nthrow new RuntimeException(\"Could not compact segments: \" + toCompact);\n// after\nthrow new RuntimeException(\"Could not compact segments: \" + toCompact, e); // preserve cause (recommended upstream fix)","handlingStrategy":"try-catch","validationCode":"// pre-check: disk space and writability of journal dir\nFiles.getFileStore(journalDir).getUsableSpace(); journalDir.canWrite();","typeGuard":null,"tryCatchPattern":"try { compact(...); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) handleIoFailure(e.getCause()); else throw e; }","preventionTips":["Monitor disk free space on journal volumes","Never delete segment files while compaction runs","Alert on journal compactor thread death","Log the IOException cause when wrapping"],"tags":["compaction","io-exception","journal"],"backgroundTag":"file-write-failed","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"}