{"record":{"id":"b6cd87d65489acd1","repo":"apache/druid","slug":"failed-to-rename-temp-file-s-and-final-segment","errorCode":null,"errorMessage":"Failed to rename temp file [%s] and final segment path [%s] is not present.","messagePattern":"Failed to rename temp file \\[(.+?)\\] and final segment path \\[(.+?)\\] is not present\\.","errorType":"exception","errorClass":"IOE","httpStatus":null,"severity":"error","filePath":"extensions-core/hdfs-storage/src/main/java/org/apache/druid/storage/hdfs/HdfsDataSegmentPusher.java","lineNumber":240,"sourceCode":"      catch (IOException ex) {\n        log.error(ex, \"Failed to delete temp directory[%s]\", tmpIndexFile.getParent());\n      }\n    }\n\n    return dataSegment;\n  }\n\n  private void copyFilesWithChecks(final FileSystem fs, final Path from, final Path to) throws IOException\n  {\n    if (!HadoopFsWrapper.rename(fs, from, to)) {\n      if (fs.exists(to)) {\n        log.info(\n            \"Unable to rename temp file [%s] to segment path [%s], it may have already been pushed by a replica task.\",\n            from,\n            to\n        );\n      } else {\n        throw new IOE(\"Failed to rename temp file [%s] and final segment path [%s] is not present.\", from, to);\n      }\n    }\n  }\n\n  @Override\n  public Map<String, Object> makeLoadSpec(URI finalIndexZipFilePath)\n  {\n    return ImmutableMap.of(\"type\", \"hdfs\", \"path\", finalIndexZipFilePath.toString());\n  }\n\n  /**\n   * Due to https://issues.apache.org/jira/browse/HDFS-13 \":\" are not allowed in\n   * path names. So we format paths differently for HDFS.\n   */\n\n  @Override\n  public String getStorageDir(DataSegment segment, boolean useUniquePath)\n  {","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/hdfs-storage/src/main/java/org/apache/druid/storage/hdfs/HdfsDataSegmentPusher.java#L222-L258","documentation":"After pushing a segment to HDFS, HdfsDataSegmentPusher copies the built temp file to its final path. If the rename fails AND the final segment path does not already exist, neither failure nor prior success explains the state, so an IOException is thrown. When the final path exists, it is assumed a replica task already pushed the same segment and the error is downgraded to an info log.","triggerScenarios":"copyFilesWithChecks() (invoked from pushToFilePath) fails FileSystem.rename(tempFile, segmentPath) and a subsequent exists() check on the target path returns false.","commonSituations":"HDFS permission problems on the segment directory; NameNode issues or transient HDFS unavailability; running as a user without write access to the configured storage directory; concurrent pushing where replicas race but the target is genuinely absent.","solutions":["Check HDFS permissions on the segment storage directory for the Druid process user","Retry the push — the failure may be a transient HDFS/NameNode issue","Verify the configured druid.storage.storageDirectory exists and is writable; create/fix it with hdfs dfs -mkdir -p and chown","Inspect NameNode logs for rename failures around the push time"],"exampleFix":"// before\n// push fails with IOE 'Failed to rename temp file ...'\nhdfs dfs -mkdir -p /druid/segments && hdfs dfs -chown druid:druid /druid/segments\n// after\n// retry the ingestion task; rename succeeds","handlingStrategy":"retry","validationCode":"// pre-check with hadoop fs shell before ingesting\n// hdfs dfs -test -w /druid/segments || hdfs dfs -mkdir -p /druid/segments\ntestHdfsWritable(storageDir);","typeGuard":"null","tryCatchPattern":"try {\n  pusher.push(segment, file);\n} catch (IOException e) {\n  if (e.getMessage().contains(\"Failed to rename temp file\")) {\n    // check HDFS permissions/NameNode health, then retry\n  }\n  throw e;\n}","preventionTips":["Ensure the segment storage directory exists and is writable by the Druid user","Monitor NameNode health and retry transient failures","Avoid concurrent first-time pushes of the same segment without replica tolerance"],"tags":["hdfs","file-rename","segment-pushing","io"],"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-14T11:17:12.474Z"}