{"record":{"id":"1b5b85752c943676","repo":"apache/hadoop","slug":"rename-file-failed","errorCode":null,"errorMessage":"rename file failed","messagePattern":"rename file failed","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/FileStore.java","lineNumber":447,"sourceCode":"          throw new RuntimeException(\n              String.format(\"part num mismatched: %d != %d\", part.num(), partNums.get(i)));\n        }\n\n        File partFile = new File(uploadDir, String.valueOf(part.num()));\n        checkPartFile(part, partFile);\n\n        try (FileInputStream inputStream = new FileInputStream(partFile);\n            FileChannel inputChannel = inputStream.getChannel()) {\n          outputChannel.transferFrom(inputChannel, offset, partFile.length());\n          offset += partFile.length();\n        }\n      }\n    } catch (IOException e) {\n      throw new RuntimeException(e);\n    }\n\n    if (!tmpFile.renameTo(keyPath.toFile())) {\n      throw new RuntimeException(\"rename file failed\");\n    } else {\n      try {\n        FileUtils.deleteDirectory(uploadDir);\n      } catch (IOException e) {\n        LOG.warn(\"failed to clean upload directory.\");\n      }\n    }\n\n    return getFileChecksum(keyPath);\n  }\n\n  private byte[] getFileChecksum(Path keyPath) {\n    return getFileMD5(keyPath);\n  }\n\n  private static byte[] getFileMD5(Path keyPath) {\n    try {\n      return DigestUtils.md5(Files.readAllBytes(keyPath));","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/FileStore.java#L429-L465","documentation":"FileStore.completeUpload() concatenates all staged part files into a .tmp file next to the final object and then promotes it with tmpFile.renameTo(keyPath); if the rename returns false it throws 'rename file failed' — the assembled object could not replace/become the destination file even though every part was read and written successfully.","triggerScenarios":"completeUpload reaching the final rename when the destination file is locked by a concurrent reader (typical on Windows), the object's directory is not writable, the destination exists with restrictive permissions, or the filesystem rejects the atomic replace (unusual mounts under the store root).","commonSituations":"Concurrent read of the same object key while a multipart write completes (Windows file locking); store root on NFS/FUSE mounts with unreliable rename semantics; leftover read-only destination file from a run under a different user; antivirus interfering on developer machines.","solutions":["Ensure no reader holds the destination key open while the upload completes (coordinate writers/readers, or write to a new key then rename/copy at the object level)","Verify write permission on the destination directory and delete any stale read-only destination file before completing","Move the filestore root to a plain local filesystem (ext4/xfs/tmpfs), not NFS or network mounts","If the destination already exists and the platform refuses replace, delete it first (storage.delete(key)) then complete the upload again from a fresh uploadId"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"java.nio.file.Path dir = java.nio.file.Paths.get(root);\nif (!java.nio.file.Files.isWritable(dir)) {\n  throw new IOException(\"destination dir not writable: \" + dir);\n}\nif (storage.objectStatus(key) != null) {\n  storage.delete(key); // clear a possibly locked destination before completing\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Coordinate so no reader has the destination key open when a multipart upload completes","Delete stale destination objects (storage.delete(key)) before completing an upload that overwrites them","Keep the filestore root on a local filesystem with reliable atomic rename (ext4/xfs/tmpfs)","Watch for antivirus/scanners holding files open on developer machines running tests on Windows"],"tags":["hadoop","tos","filestore","rename","multipart-upload"],"backgroundTag":"file-rename-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}