apache/cassandra · error · RuntimeException
Could not compact segments: " + toCompact
Error message
Could not compact segments: " + toCompact
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/journal/Compactor.java:105
toCompact.subList(limit, toCompact.size()).clear();
}
try
{
Collection<StaticSegment<K, V>> newSegments = segmentCompactor.compact(toCompact);
for (StaticSegment<K, V> segment : newSegments)
toCompact.remove(segment);
journal.replaceCompactedSegments(toCompact, newSegments);
for (StaticSegment<K, V> segment : toCompact)
segment.discard(journal);
compacted.signalAll();
}
catch (IOException e)
{
throw new RuntimeException("Could not compact segments: " + toCompact);
}
}
@Override
public boolean isTerminated()
{
return executor.isTerminated();
}
@Override
public void shutdown()
{
logger.debug("Shutting down " + executor);
if (scheduled != null)
scheduled.cancel(false);
executor.shutdown();
}
View on GitHub (pinned to 88fd0f6a0e)
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
Example fix
// before
throw new RuntimeException("Could not compact segments: " + toCompact);
// after
throw new RuntimeException("Could not compact segments: " + toCompact, e); // preserve cause (recommended upstream fix) Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check: disk space and writability of journal dir Files.getFileStore(journalDir).getUsableSpace(); journalDir.canWrite();
Try / catch
try { compact(...); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) handleIoFailure(e.getCause()); else throw e; } Prevention
- 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
When it happens
Trigger: IOException while reading segments, rewriting filtered entries, or writing compacted output during Compactor.run(); disk full, permission errors, or segment files disappearing mid-compaction.
Common situations: Disk exhaustion on the commitlog/journal volume; concurrent recovery/cleanup deleting segments; filesystem errors (I/O errors, read-only mounts).
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- JournalReadError(descriptor, file, e)
- Unsupported disk access mode for compaction_read_disk_access
- concurrent_compactors should be strictly greater than 0, but
- Invalid value of compaction_throughput:
- compaction_throughput: is too large; it should be less than
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/54c59ffec1a64df2.
Report an issue: GitHub.