{"record":{"id":"56780512f033ac22","repo":"apache/druid","slug":"failed-to-write-to-file-s-current-size-of-file-567805","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/LegacyFileWriteOutBytes.java","lineNumber":67,"sourceCode":"    this.writeOutBytes = 0L;\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":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/writeout/LegacyFileWriteOutBytes.java#L49-L85","documentation":"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.","triggerScenarios":"write(), writeTo(), readFully(), flushIfNeeded() or asInputStream() triggering flush while the channel write fails: disk full, I/O error, volume unavailable, permission revoked.","commonSituations":"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.","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."],"exampleFix":"// before\nlegacyWriteOutBytes.write(data); // IOE when disk full\n// after\nif (new File(baseDir).getUsableSpace() < data.length * 2L) {\n  throw new IOException(\"not enough space in \" + baseDir);\n}\nlegacyWriteOutBytes.write(data);","handlingStrategy":"try-catch","validationCode":"if (baseDir.getUsableSpace() < estimatedSize) { throw new IOException(\"insufficient space: \" + baseDir); }","typeGuard":null,"tryCatchPattern":"try { legacy.write(data); } catch (IOException e) { log.error(e, \"legacy write failed [%s]\", e.getMessage()); throw e; }","preventionTips":["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."],"tags":["io","file-write","disk","legacy"],"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"}