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

  1. Check free disk space and quotas on the target directory (df -h, quota) and free space or relocate druid.storage BaseDir.
  2. Verify file permissions and that the file/volume is writable and not removed (ls -l, mount status).
  3. Inspect server logs (dmesg / filesystem errors) for hardware-level I/O failures and repair/replace storage.
  4. 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

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


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/2453580c12f8326a. Report an issue: GitHub.