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
FileWriteOutBytes.flush writes its internal buffer to the underlying file channel via Channels.writeFully; when the OS-level write fails with IOException it is wrapped in IOE with the file path and current logical size. This signals disk/IO failure while persisting segment data.
Source
Thrown at processing/src/main/java/org/apache/druid/segment/writeout/FileWriteOutBytes.java:75
);
}
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 free disk space and quotas on the target directory (df -h, quota) and free space or relocate druid.storage BaseDir.
- Verify file permissions and that the file/volume is writable and not removed (ls -l, mount status).
- Inspect server logs (dmesg / filesystem errors) for hardware-level I/O failures and repair/replace storage.
- Retry the task/ingestion after resolving storage; regenerate the segment since the file may be partially written.
Example fix
// before
writeOutBytes.write(bytes); // fails when disk is full
// after
long usable = new File(baseDir).getUsableSpace();
if (usable < bytes.length) {
throw new IOException("insufficient disk space in " + baseDir + ": " + usable);
}
writeOutBytes.write(bytes); Defensive patterns
Strategy: try-catch
Validate before calling
if (new File(baseDir).getUsableSpace() < requiredBytes) { throw new IOException("low disk: " + baseDir); } Try / catch
try { outBytes.write(data); outBytes.flushIfNeeded(); } catch (IOException e) { log.error(e, "file write failed: %s", e.getMessage()); throw e; } Prevention
- Monitor disk free space on segment/persist dirs and alert at thresholds.
- Use local (non-NFS) storage for intermediate persists where possible.
- Ensure the Druid process user owns the target directories.
- Handle IOException per-task and rebuild affected segments; never trust partially written files.
When it happens
Trigger: Any write(), writeTo(), readFully(), flushIfNeeded(), or asInputStream() that triggers flush when the underlying channel write fails: disk full, I/O error, device removed, permission loss, closed channel.
Common situations: Disk quota exceeded or filesystem full on druid segment cache dir; NFS/EBS volume detached; directory permissions changed mid-run; too many open files causing channel issues.
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/2453580c12f8326a.
Report an issue: GitHub.