apache/cassandra · critical · RuntimeException

Not enough space to write %s to %s (%s available)

Error message

Not enough space to write %s to %s (%s available)

What it means

When choosing a directory for compaction output, CompactionAwareWriter.getWriteDirectory checks the disk holding the descriptor for enough free space for the estimated write size. If the chosen data directory has less available space than estimatedWriteSize, a RuntimeException aborts the compaction before it fills the disk.

Source

Thrown at src/java/org/apache/cassandra/db/compaction/writers/CompactionAwareWriter.java:293

    public Directories.DataDirectory getWriteDirectory(Iterable<SSTableReader> sstables, long estimatedWriteSize)
    {
        Descriptor descriptor = null;
        for (SSTableReader sstable : sstables)
        {
            if (descriptor == null)
                descriptor = sstable.descriptor;
            if (!descriptor.directory.equals(sstable.descriptor.directory))
            {
                logger.trace("All sstables not from the same disk - putting results in {}", descriptor.directory);
                break;
            }
        }
        Directories.DataDirectory d = getDirectories().getDataDirectoryForFile(descriptor);
        if (d != null)
        {
            long availableSpace = d.getAvailableSpace();
            if (availableSpace < estimatedWriteSize)
                throw new RuntimeException(String.format("Not enough space to write %s to %s (%s available)",
                                                         FBUtilities.prettyPrintMemory(estimatedWriteSize),
                                                         d.location,
                                                         FBUtilities.prettyPrintMemory(availableSpace)));
            logger.trace("putting compaction results in {}", descriptor.directory);
            return d;
        }
        d = getDirectories().getWriteableLocation(estimatedWriteSize);
        if (d == null)
            throw new RuntimeException(String.format("Not enough disk space to store %s",
                                                     FBUtilities.prettyPrintMemory(estimatedWriteSize)));
        return d;
    }

    public CompactionAwareWriter setRepairedAt(long repairedAt)
    {
        this.sstableWriter.setRepairedAt(repairedAt);
        return this;
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Free disk space on the affected data directory (run nodetool cleanup, clear snapshots, archive/expire data).
  2. Add or rebalance across data directories with more free space (check nodetool diskusage / df).
  3. Reduce compaction output size by lowering concurrent compactors or compacting smaller ranges, or raise the disk threshold configuration (disk_usage_percent_warn/fail).
  4. Expand the volume if infrastructure allows.

Example fix

// before (shell)
# compaction fails: /var/lib/cassandra/data 97% full
// after (shell)
nodetool clearsnapshot --all && nodetool cleanup  # free space, then retry compaction
Defensive patterns

Strategy: try-catch

Validate before calling

// before compacting
long free = new File(dataDir).getFreeSpace();
if (free < estimatedOutputBytes) { /* pause compaction, free space or alert */ }

Try / catch

try {
    writer.finish();
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("Not enough space")) { alertDiskPressure(); /* back off, free space, retry later */ }
    else throw e;
}

Prevention

When it happens

Trigger: A compaction (via defaultLocation -> getWriteDirectory) targets a data directory whose getAvailableSpace() is below the estimated size of the output SSTable.

Common situations: Disks nearly full on one of several data directories, a very large compaction producing a huge single SSTable, or mis-provisioned volumes.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/842a5de4427b4361. Report an issue: GitHub.