{"record":{"id":"a2200849728fd861","repo":"apache/druid","slug":"could-not-write-d-bytes-into-smooshchannel","errorCode":null,"errorMessage":"Could not write [%d] bytes into smooshChannel.","messagePattern":"Could not write \\[(.+?)\\] bytes into smooshChannel\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/data/GenericIndexedWriter.java","lineNumber":228,"sourceCode":"    return StringUtils.format(\"%s_header\", fileNameBase);\n  }\n\n  private static void writeBytesIntoSmooshedChannel(\n      long numBytesToPutInFile,\n      final byte[] buffer,\n      final SegmentFileChannel smooshChannel,\n      final InputStream is\n  )\n      throws IOException\n  {\n    ByteBuffer holderBuffer = ByteBuffer.wrap(buffer);\n    while (numBytesToPutInFile > 0) {\n      int bytesRead = is.read(buffer, 0, Math.min(buffer.length, Ints.saturatedCast(numBytesToPutInFile)));\n      if (bytesRead != -1) {\n        smooshChannel.write((ByteBuffer) holderBuffer.clear().limit(bytesRead));\n        numBytesToPutInFile -= bytesRead;\n      } else {\n        throw new ISE(\"Could not write [%d] bytes into smooshChannel.\", numBytesToPutInFile);\n      }\n    }\n  }\n\n  @Override\n  public void open() throws IOException\n  {\n    headerOut = segmentWriteOutMedium.makeWriteOutBytes();\n    valuesOut = segmentWriteOutMedium.makeWriteOutBytes();\n  }\n\n  public void setObjectsNotSorted()\n  {\n    objectsSorted = false;\n  }\n\n  @Override\n  public boolean isSorted()","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/data/GenericIndexedWriter.java#L210-L246","documentation":"writeBytesIntoSmooshedChannel streams a serialized GenericIndexed from an in-memory holder into a smooshed file channel and tracks remaining bytes. If the input stream reaches EOF before all expected bytes are written, it throws ISE, meaning the serialized data was truncated relative to its recorded size.","triggerScenarios":"writeToMultiFiles / writeBytesIntoSmooshedChannel when is.read() returns -1 while numBytesToPutInFile > 0, i.e. the holder's data ended sooner than the declared byte count.","commonSituations":"Disk-full or partial-write during segment persist, a bug producing inconsistent size metadata, or corrupted intermediate files during merge.","solutions":["Check for disk space/full-disk errors on the segment store and retry the persist/merge.","Verify the serialized holder size matches numBytesWritten/declared sizes; fix size accounting if custom code writes the holder.","Retry the operation; if reproducible on valid inputs, report as a bug with the failing segment."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// confirm holder size matches declared byte count before streaming\nlong expected = numBytesWritten;\nlong available = holderInputStream.available(); // heuristic pre-check","typeGuard":null,"tryCatchPattern":"try { writer.writeToMultiFiles(...); } catch (ISE e) {\n  if (e.getMessage().contains(\"smooshChannel\")) { /* retry persist; check disk space */ }\n  throw e;\n}","preventionTips":["Ensure adequate free disk space during segment persist/merge","Keep Druid's built-in writer path intact; don't write holder data manually","Retry persist jobs on transient IO failures"],"tags":["java","io","segment-persist"],"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-17T15:17:12.973Z"}