apache/druid · critical · org.apache.druid.java.util.common.IOE
Failed to write to file: %s. Current size of file: %d
Error message
Failed to write to file: %s. Current size of file: %d
What it means
LegacyFileWriteOutBytes.flush pushes its buffered bytes through Channels.writeFully to the file channel; an IOException is wrapped in IOE naming the file path and current size. It indicates the backing file could not be written to during segment persistence.
Source
Thrown at processing/src/main/java/org/apache/druid/segment/writeout/LegacyFileWriteOutBytes.java:67
this.writeOutBytes = 0L;
}
private void flushIfNeeded(int bytesNeeded) throws IOException
{
if (buffer.remaining() < bytesNeeded) {
flush();
}
}
@Override
public void flush() throws IOException
{
buffer.flip();
try {
Channels.writeFully(ch, buffer);
}
catch (IOException e) {
throw new IOE(e, "Failed to write to file: %s. Current size of file: %d", file.getAbsolutePath(), writeOutBytes);
}
buffer.clear();
}
@Override
public void write(int b) throws IOException
{
flushIfNeeded(1);
buffer.put((byte) b);
writeOutBytes++;
}
@Override
public void writeInt(int v) throws IOException
{
flushIfNeeded(Integer.BYTES);
buffer.putInt(v);
writeOutBytes += Integer.BYTES;View on GitHub (pinned to 9b90983fd2)
Solutions
- Check disk space/quota on the druid intermediate persist directory and clean or expand storage.
- Verify file and directory permissions and that the mount/volume is healthy.
- Review OS logs for underlying I/O errors and fix hardware/filesystem issues.
- Rerun the task after fixing; treat the partially written file as invalid and rebuild it.
Example fix
// before
legacyWriteOutBytes.write(data); // IOE when disk full
// after
if (new File(baseDir).getUsableSpace() < data.length * 2L) {
throw new IOException("not enough space in " + baseDir);
}
legacyWriteOutBytes.write(data); Defensive patterns
Strategy: try-catch
Validate before calling
if (baseDir.getUsableSpace() < estimatedSize) { throw new IOException("insufficient space: " + baseDir); } Try / catch
try { legacy.write(data); } catch (IOException e) { log.error(e, "legacy write failed [%s]", e.getMessage()); throw e; } Prevention
- Pre-check disk capacity before large segment builds.
- Keep legacy persist dirs on healthy local volumes.
- Watch for permission changes on running tasks (config management races).
- Rerun failed tasks and rebuild segments after storage incidents.
When it happens
Trigger: write(), writeTo(), readFully(), flushIfNeeded() or asInputStream() triggering flush while the channel write fails: disk full, I/O error, volume unavailable, permission revoked.
Common situations: Full or failing disk on the intermediate persist dir; NFS/network storage outage; permission changes after task start; inode/device errors on long-running peons.
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
- Failed to write to file: %s. Current size of file: %d
- Failed to write partial info file for segment[%s]
- Exception while writing distribution file for interval [%s],
- Exception during serialization of lookups using file [%s]
- Failed to mount partial metadata for segment[%s]
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/56780512f033ac22.
Report an issue: GitHub.