{"record":{"id":"4581cd40c3fd5084","repo":"apache/druid","slug":"cannot-add-files-of-the-same-name-already-have-4581cd","errorCode":null,"errorMessage":"Cannot add files of the same name, already have [%s]","messagePattern":"Cannot add files of the same name, already have \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/file/SegmentFileBuilderV10.java","lineNumber":203,"sourceCode":"    }\n  }\n\n  @Override\n  public void add(String name, ByteBuffer bufferToAdd) throws IOException\n  {\n    try (SegmentFileChannel out = addWithChannel(name, bufferToAdd.remaining())) {\n      out.write(bufferToAdd);\n    }\n  }\n\n  @Override\n  public SegmentFileChannel addWithChannel(final String name, final long size) throws IOException\n  {\n    if (name.contains(\",\")) {\n      throw new IAE(\"Cannot have a comma in the name of a file, got[%s].\", name);\n    }\n    if (internalFiles.containsKey(name)) {\n      throw new IAE(\"Cannot add files of the same name, already have [%s]\", name);\n    }\n    ensureNameMatchesActiveBundle(name);\n    if (size > maxContainerSize) {\n      throw DruidException.forPersona(DruidException.Persona.ADMIN)\n                          .ofCategory(DruidException.Category.RUNTIME_FAILURE)\n                          .build(\n                              \"Serialized buffer size[%,d] for column[%s] exceeds the maximum[%,d]. \"\n                              + \"Consider adjusting the tuningConfig - for example, reduce maxRowsPerSegment, \"\n                              + \"or partition your data further.\",\n                              size, name, maxContainerSize\n                          );\n    }\n\n    // If an outer writer is mid-write we can't append to the current container concurrently, route through a temp\n    // file that will be merged back into a container once the outer writer releases.\n    if (writerCurrentlyInUse) {\n      return delegateChannel(name, size);\n    }","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/file/SegmentFileBuilderV10.java#L185-L221","documentation":"Each file inside a SegmentFileV10 container must have a unique name because the container metadata indexes internal files by name. addWithChannel checks internalFiles.containsKey(name) and throws this IllegalArgumentException when a duplicate name is added. It prevents silently overwriting or shadowing an existing internal file.","triggerScenarios":"Calling addWithChannel(name, size) (directly or via add/makeColumn) twice with the same name within one container build, e.g. writing two versions of a column under the same file name in one builder session.","commonSituations":"Custom ingestion/segment-generation code writing multiple index files with the same generated name; a builder reused across bundles without clearing names; a bug in name generation omitting a version/suffix.","solutions":["Make internal file names unique by adding a distinguishing suffix (column name, version, index kind) before calling addWithChannel","Ensure a single SegmentFileBuilderV10 instance is not reused to write the same file twice; create a new builder or a new container for a second write","Check existing names with the builder's metadata before adding and skip/overwrite intentionally"],"exampleFix":"// before\nbuilder.addWithChannel(\"__time.idx\", size);\nbuilder.addWithChannel(\"__time.idx\", size2); // duplicate\n// after\nbuilder.addWithChannel(\"__time.idx.v1\", size);\nbuilder.addWithChannel(\"__time.idx.v2\", size2);","handlingStrategy":"validation","validationCode":"// Java: track names you have already added\nSet<String> used = new HashSet<>();\nif (!used.add(name)) { throw new IllegalStateException(\"duplicate file name: \" + name); }","typeGuard":null,"tryCatchPattern":"try {\n  builder.addWithChannel(name, size);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Cannot add files of the same name\")) {\n    builder.addWithChannel(appendVersionSuffix(name), size);\n  } else { throw e; }\n}","preventionTips":["Include a unique suffix (column name + index kind + version) in every internal file name","Never reuse a single builder for multiple independent write sessions","Maintain your own Set of names written and assert uniqueness before add"],"tags":["validation","segment-files","duplicate-key"],"backgroundTag":"file-already-exists","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"}