{"record":{"id":"2453580c12f8326a","repo":"apache/druid","slug":"failed-to-write-to-file-s-current-size-of-file","errorCode":null,"errorMessage":"Failed to write to file: %s. Current size of file: %d","messagePattern":"Failed to write to file: (.+?)\\. Current size of file: (.+?)","errorType":"exception","errorClass":"org.apache.druid.java.util.common.IOE","httpStatus":null,"severity":"critical","filePath":"processing/src/main/java/org/apache/druid/segment/writeout/FileWriteOutBytes.java","lineNumber":75,"sourceCode":"    );\n  }\n\n  private void flushIfNeeded(int bytesNeeded) throws IOException\n  {\n    if (buffer.remaining() < bytesNeeded) {\n      flush();\n    }\n  }\n\n  @Override\n  public void flush() throws IOException\n  {\n    buffer.flip();\n    try {\n      Channels.writeFully(ch, buffer);\n    }\n    catch (IOException e) {\n      throw new IOE(e, \"Failed to write to file: %s. Current size of file: %d\", file.getAbsolutePath(), writeOutBytes);\n    }\n    buffer.clear();\n  }\n\n  @Override\n  public void write(int b) throws IOException\n  {\n    flushIfNeeded(1);\n    buffer.put((byte) b);\n    writeOutBytes++;\n  }\n\n  @Override\n  public void writeInt(int v) throws IOException\n  {\n    flushIfNeeded(Integer.BYTES);\n    buffer.putInt(v);\n    writeOutBytes += Integer.BYTES;","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/writeout/FileWriteOutBytes.java#L57-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nwriteOutBytes.write(bytes); // fails when disk is full\n// after\nlong usable = new File(baseDir).getUsableSpace();\nif (usable < bytes.length) {\n  throw new IOException(\"insufficient disk space in \" + baseDir + \": \" + usable);\n}\nwriteOutBytes.write(bytes);","handlingStrategy":"try-catch","validationCode":"if (new File(baseDir).getUsableSpace() < requiredBytes) { throw new IOException(\"low disk: \" + baseDir); }","typeGuard":null,"tryCatchPattern":"try { outBytes.write(data); outBytes.flushIfNeeded(); } catch (IOException e) { log.error(e, \"file write failed: %s\", e.getMessage()); throw e; }","preventionTips":["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."],"tags":["io","file-write","disk"],"backgroundTag":"file-write-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}