{"record":{"id":"929565d05fbe9476","repo":"apache/hadoop","slug":"could-not-rename-tmp-to-file","errorCode":null,"errorMessage":"Could not rename ${tmp} to ${file}","messagePattern":"Could not rename (.+?) to (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/HistoryServerFileSystemStateStoreService.java","lineNumber":249,"sourceCode":"      if (!status.isDirectory()) {\n        throw new FileAlreadyExistsException(\"Unexpected file in store: \"\n            + dir);\n      }\n      if (!status.getPermission().equals(DIR_PERMISSIONS)) {\n        fs.setPermission(dir, DIR_PERMISSIONS);\n      }\n    } catch (FileNotFoundException e) {\n      fs.mkdirs(dir, DIR_PERMISSIONS);\n    }\n  }\n\n  private void createNewFile(Path file, byte[] data)\n      throws IOException {\n    Path tmp = new Path(file.getParent(), TMP_FILE_PREFIX + file.getName());\n    writeFile(tmp, data);\n    try {\n      if (!fs.rename(tmp, file)) {\n        throw new IOException(\"Could not rename \" + tmp + \" to \" + file);\n      }\n    } catch (IOException e) {\n      fs.delete(tmp, false);\n      throw e;\n    }\n  }\n\n  private void writeFile(Path file, byte[] data) throws IOException {\n    final int WRITE_BUFFER_SIZE = 4096;\n    FSDataOutputStream out = fs.create(file, FILE_PERMISSIONS, true,\n        WRITE_BUFFER_SIZE, fs.getDefaultReplication(file),\n        fs.getDefaultBlockSize(file), null);\n    try {\n      try {\n        out.write(data);\n        out.close();\n        out = null;\n      } finally {","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/HistoryServerFileSystemStateStoreService.java#L231-L267","documentation":"createNewFile writes token/key data to a temp file (TMP_FILE_PREFIX) beside the final name and renames it into place so readers never observe partial files. If FileSystem.rename returns false, it throws IOException 'Could not rename' and deletes the temp file in the catch block, so no partial record survives but the store operation failed. Root causes are the same class of filesystem problems as the updateToken rename failure.","triggerScenarios":"Target file created concurrently by a second writer; insufficient permission on the parent directory for rename; HDFS transient failure; parent directory removed between writeFile and rename.","commonSituations":"Two JHS instances pointed at one store; ACL or permission tightening after deployment; store directory on a failing or full disk.","solutions":["Ensure only one JHS process writes to the store.","Check parent directory permissions for the JHS user on the path named in the message.","Verify filesystem health and free space, then restart JHS to retry the store operations.","Remove any partially-written leftovers before restart."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  // store operation that creates token/key files\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"Could not rename\")) {\n    // temp file is auto-deleted; fix filesystem perms/health then retry via restart\n  }\n}","preventionTips":["Guarantee a single writer to the store.","Audit directory permissions for the JHS user after any security change.","Watch disk space on the store volume."],"tags":["mapreduce","job-history-server","state-store","filesystem","rename"],"backgroundTag":"rename-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}