{"record":{"id":"842a5de4427b4361","repo":"apache/cassandra","slug":"not-enough-space-to-write-s-to-s-s-available","errorCode":null,"errorMessage":"Not enough space to write %s to %s (%s available)","messagePattern":"Not enough space to write (.+?) to (.+?) \\((.+?) available\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/java/org/apache/cassandra/db/compaction/writers/CompactionAwareWriter.java","lineNumber":293,"sourceCode":"    public Directories.DataDirectory getWriteDirectory(Iterable<SSTableReader> sstables, long estimatedWriteSize)\n    {\n        Descriptor descriptor = null;\n        for (SSTableReader sstable : sstables)\n        {\n            if (descriptor == null)\n                descriptor = sstable.descriptor;\n            if (!descriptor.directory.equals(sstable.descriptor.directory))\n            {\n                logger.trace(\"All sstables not from the same disk - putting results in {}\", descriptor.directory);\n                break;\n            }\n        }\n        Directories.DataDirectory d = getDirectories().getDataDirectoryForFile(descriptor);\n        if (d != null)\n        {\n            long availableSpace = d.getAvailableSpace();\n            if (availableSpace < estimatedWriteSize)\n                throw new RuntimeException(String.format(\"Not enough space to write %s to %s (%s available)\",\n                                                         FBUtilities.prettyPrintMemory(estimatedWriteSize),\n                                                         d.location,\n                                                         FBUtilities.prettyPrintMemory(availableSpace)));\n            logger.trace(\"putting compaction results in {}\", descriptor.directory);\n            return d;\n        }\n        d = getDirectories().getWriteableLocation(estimatedWriteSize);\n        if (d == null)\n            throw new RuntimeException(String.format(\"Not enough disk space to store %s\",\n                                                     FBUtilities.prettyPrintMemory(estimatedWriteSize)));\n        return d;\n    }\n\n    public CompactionAwareWriter setRepairedAt(long repairedAt)\n    {\n        this.sstableWriter.setRepairedAt(repairedAt);\n        return this;\n    }","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/compaction/writers/CompactionAwareWriter.java#L275-L311","documentation":"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.","triggerScenarios":"A compaction (via defaultLocation -> getWriteDirectory) targets a data directory whose getAvailableSpace() is below the estimated size of the output SSTable.","commonSituations":"Disks nearly full on one of several data directories, a very large compaction producing a huge single SSTable, or mis-provisioned volumes.","solutions":["Free disk space on the affected data directory (run nodetool cleanup, clear snapshots, archive/expire data).","Add or rebalance across data directories with more free space (check nodetool diskusage / df).","Reduce compaction output size by lowering concurrent compactors or compacting smaller ranges, or raise the disk threshold configuration (disk_usage_percent_warn/fail).","Expand the volume if infrastructure allows."],"exampleFix":"// before (shell)\n# compaction fails: /var/lib/cassandra/data 97% full\n// after (shell)\nnodetool clearsnapshot --all && nodetool cleanup  # free space, then retry compaction","handlingStrategy":"try-catch","validationCode":"// before compacting\nlong free = new File(dataDir).getFreeSpace();\nif (free < estimatedOutputBytes) { /* pause compaction, free space or alert */ }","typeGuard":null,"tryCatchPattern":"try {\n    writer.finish();\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Not enough space\")) { alertDiskPressure(); /* back off, free space, retry later */ }\n    else throw e;\n}","preventionTips":["Monitor data-directory free space with alerts well above compaction output estimates","Regularly clear snapshots (nodetool clearsnapshot)","Size disks for peak compaction fan-in, not steady-state data size"],"tags":["cassandra","disk-space","compaction","storage"],"backgroundTag":"insufficient-disk-space","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"}